Last active
August 29, 2015 14:24
-
-
Save isaacs/f29fe3c07b8ccee66c3a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# tests from https://github.com/isaacs/minimatch/issues/65 | |
echo "TAP version 13" | |
count=0 | |
if ! [[ $BASH_VERSION == 4.3.* ]]; then | |
echo "Bail out! Bash v4.3 required" | |
exit 1 | |
fi | |
exitcode=0 | |
runtest () { | |
touch $FILE | |
local bashres | |
local globres | |
local minires | |
local total="ok" | |
local c=0 | |
let '++count' | |
cat <<-OUTPUT | |
# Subtest: $FILE | |
OUTPUT | |
for t in "${TESTS[@]}"; do | |
let '++c' | |
if [[ $FILE == $t ]]; then | |
bashres="true" | |
else | |
bashres="false" | |
fi | |
globres=$(node -p 'require("glob").sync(process.argv[1]).indexOf(process.argv[2]) !== -1' "$t" "$FILE") | |
minires=$(node -p 'require("minimatch")(process.argv[2], process.argv[1],{nonegate:true})' "$t" "$FILE") | |
if [ "$globres" != "$bashres" ] || [ "$minires" != "$bashres" ]; then | |
cat <<-RESULT | |
not ok $c - $t $bashres | |
--- | |
wanted: $bashres | |
glob: $globres | |
mini: $minires | |
... | |
RESULT | |
total="not ok" | |
exitcode=1 | |
else | |
cat <<-RESULT | |
ok $c - $t $bashres | |
RESULT | |
fi | |
done | |
rm $FILE | |
cat <<-OUTPUT | |
1..$c | |
$total $count - $FILE | |
OUTPUT | |
} | |
FILE=bar.min.js | |
TESTS=( | |
"*.!(js|css)" | |
"!*.+(js|css)" | |
"*.+(js|css)" | |
) | |
runtest | |
FILE=a-integration-test.js | |
TESTS=( | |
"*-!(integration)-test.js" | |
"*.!(j)" | |
"!(*-integration-test.js)" | |
"*-!(integration-)test.js" | |
"*-!(integration)-test.js" | |
"*!(-integration)-test.js" | |
"*!(-integration-)test.js" | |
"*!(integration)-test.js" | |
"*!(integration-test).js" | |
"*-!(integration-test).js" | |
"*-!(integration-test.js)" | |
"*-!(integra)tion-test.js" | |
"*-integr!(ation)-test.js" | |
"*-integr!(ation-t)est.js" | |
"*-i!(ntegration-)test.js" | |
"*i!(ntegration-)test.js" | |
"*te!(gration-te)st.js" | |
"*-!(integration)?test.js" | |
"*?!(integration)?test.js" | |
) | |
runtest | |
FILE=foo-integration-test.js | |
TESTS=( | |
'*-integration-test.js' | |
'!(*-integration-test.js)' | |
) | |
runtest | |
FILE=foo.jszzz.js | |
TESTS=("*.!(js).js") | |
runtest | |
FILE=asd.jss | |
TESTS=("*.!(js)") | |
runtest | |
echo "1..$count" | |
exit $exitcode |
Author
isaacs
commented
Jul 5, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment