diff --git a/bin/_mocha b/bin/_mocha index fe3f67861a..b355e28352 100755 --- a/bin/_mocha +++ b/bin/_mocha @@ -358,9 +358,26 @@ 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; + } + + throw err; + } + + files = files.concat(newFiles); }); +if (!files.length) { + console.error('No test files found'); + process.exit(1); +} + // resolve files = files.map(function(path) { diff --git a/test/acceptance/glob/glob.sh b/test/acceptance/glob/glob.sh index a2b8c6fea2..823ba07fb9 100755 --- a/test/acceptance/glob/glob.sh +++ b/test/acceptance/glob/glob.sh @@ -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. @@ -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 }