Skip to content

Commit

Permalink
Report non-matching patterns to STDERR and exit with non-zero status …
Browse files Browse the repository at this point in the history
…if no files are matched at all. Fixes #2194
  • Loading branch information
Munter committed Sep 17, 2016
1 parent 5e1cd44 commit 349f746
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
18 changes: 17 additions & 1 deletion bin/_mocha
Expand Up @@ -358,9 +358,25 @@ if (!args.length) {
}

args.forEach(function(arg) {
files = files.concat(utils.lookupFiles(arg, extensions, program.recursive));
var newFiles;
try {
newFiles = utils.lookupFiles(arg, extensions, program.recursive);
} catch (err) {
if (err.message.indexOf('cannot resolve path') === 0) {
console.error('Warning: Could not find any test files matching pattern: ' + arg);
return;
} else {
throw err;
}
}

files = files.concat(newFiles);
});

if (files.length === 0) {
process.exit(1);
}

// resolve

files = files.map(function(path) {
Expand Down
15 changes: 13 additions & 2 deletions test/acceptance/glob/glob.sh
Expand Up @@ -22,11 +22,22 @@ cat /tmp/mocha-glob.txt | grep -q -F '["end",{"suites":1,"tests":1,"passes":1,"p
exit 1
}

cat /tmp/mocha-glob.txt | grep -q -F 'cannot resolve path' || {
cat /tmp/mocha-glob.txt | grep -q -F 'Could not find any test files matching pattern' || {
echo Globbing './*-none.js' in `pwd` should match no files and run no tests.
exit 1
}

../../../bin/mocha -R json-stream ./*.js ./*-none.js >& /tmp/mocha-glob.txt || {
echo Globbing ./*.js ./*-none.js in `pwd` failed.
exit 1
}

cat /tmp/mocha-glob.txt | grep -q -F '["end",{"suites":1,"tests":1,"passes":1,"pending":0,"failures":0,' &&
cat /tmp/mocha-glob.txt | grep -q -F 'Could not find any test files matching pattern' || {
echo Globbing ./*.js ./*-none.js in `pwd` should match glob.js with one test inside and display one warning for the non-existing file.
exit 1
}

# Globbing in windows command-shell differs completely from unix-style globbing.
# In bash, the shell expands globs and passes the result to executables.
# In windows, the shell passes globs unexpanded, executables do expansion if they support it.
Expand All @@ -47,7 +58,7 @@ cat /tmp/mocha-glob.txt | grep -q -F '["end",{"suites":1,"tests":1,"passes":1,"p
exit 1
}

cat /tmp/mocha-glob.txt | grep -q -F 'cannot resolve path' || {
cat /tmp/mocha-glob.txt | grep -q -F 'Could not find any test files matching pattern' || {
echo Globbing './*-none.js' in `pwd` should match no files and run no tests.
exit 1
}
Expand Down

0 comments on commit 349f746

Please sign in to comment.