Skip to content

Instantly share code, notes, and snippets.

@isaacs
Last active August 29, 2015 14:24
Show Gist options
  • Save isaacs/f29fe3c07b8ccee66c3a to your computer and use it in GitHub Desktop.
Save isaacs/f29fe3c07b8ccee66c3a to your computer and use it in GitHub Desktop.
#!/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
@isaacs
Copy link
Author

isaacs commented Jul 5, 2015

TAP version 13
    # Subtest: bar.min.js
    ok 1 - *.!(js|css) true
    ok 2 - !*.+(js|css) false
    ok 3 - *.+(js|css) true
    1..3
ok 1 - bar.min.js

    # Subtest: a-integration-test.js
    ok 1 - *-!(integration)-test.js false
    not ok 2 - *.!(j) true
      ---
      wanted: true
      glob: false
      mini: false
      ...
    ok 3 - !(*-integration-test.js) false
    ok 4 - *-!(integration-)test.js true
    ok 5 - *-!(integration)-test.js false
    ok 6 - *!(-integration)-test.js true
    ok 7 - *!(-integration-)test.js true
    ok 8 - *!(integration)-test.js true
    ok 9 - *!(integration-test).js true
    ok 10 - *-!(integration-test).js true
    ok 11 - *-!(integration-test.js) true
    ok 12 - *-!(integra)tion-test.js false
    ok 13 - *-integr!(ation)-test.js false
    ok 14 - *-integr!(ation-t)est.js false
    ok 15 - *-i!(ntegration-)test.js false
    ok 16 - *i!(ntegration-)test.js true
    ok 17 - *te!(gration-te)st.js true
    ok 18 - *-!(integration)?test.js false
    ok 19 - *?!(integration)?test.js true
    1..19
not ok 2 - a-integration-test.js

    # Subtest: foo-integration-test.js
    ok 1 - *-integration-test.js true
    ok 2 - !(*-integration-test.js) false
    1..2
ok 3 - foo-integration-test.js

    # Subtest: foo.jszzz.js
    not ok 1 - *.!(js).js true
      ---
      wanted: true
      glob: false
      mini: false
      ...
    1..1
not ok 4 - foo.jszzz.js

    # Subtest: asd.jss
    not ok 1 - *.!(js) true
      ---
      wanted: true
      glob: false
      mini: false
      ...
    1..1
not ok 5 - asd.jss

1..5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment