Repository: mochajs/mocha

Problem statement:
`mocha -h` doesn't always display help
Pretty straightforward testcase:

```
zarel@Phenylalanine ~> mocha -h

  Usage: mocha [debug] [options] [files]

  [...]

zarel@Phenylalanine ~> mkdir test
zarel@Phenylalanine ~> echo "test" > test/mocha.opts
zarel@Phenylalanine ~> mocha -h
No test files found
```

In other words, if `test/mocha.opts` exists, `mocha -h` won't display help.


Hints:

Patch:
diff --git a/bin/options.js b/bin/options.js
--- a/bin/options.js
+++ b/bin/options.js
@@ -17,6 +17,10 @@ module.exports = getOptions;
  */
 
 function getOptions () {
+  if (process.argv.length === 3 && (process.argv[2] === '-h' || process.argv[2] === '--help')) {
+    return;
+  }
+
   var optsPath = process.argv.indexOf('--opts') === -1
     ? 'test/mocha.opts'
     : process.argv[process.argv.indexOf('--opts') + 1];


Test patch:
diff --git a/test/integration/fixtures/options/help/test/mocha.opts b/test/integration/fixtures/options/help/test/mocha.opts
new file mode 100644
--- /dev/null
+++ b/test/integration/fixtures/options/help/test/mocha.opts
@@ -0,0 +1 @@
+foo
diff --git a/test/integration/helpers.js b/test/integration/helpers.js
--- a/test/integration/helpers.js
+++ b/test/integration/helpers.js
@@ -110,15 +110,34 @@ module.exports = {
   /**
    * regular expression used for splitting lines based on new line / dot symbol.
    */
-  splitRegExp: new RegExp('[\\n' + baseReporter.symbols.dot + ']+')
+  splitRegExp: new RegExp('[\\n' + baseReporter.symbols.dot + ']+'),
+
+  /**
+   * Invokes the mocha binary. Accepts an array of additional command line args
+   * to pass. The callback is invoked with the exit code and output. Optional
+   * current working directory as final parameter.
+   *
+   * In most cases runMocha should be used instead.
+   *
+   * Example response:
+   * {
+   *   code:    1,
+   *   output:  '...'
+   * }
+   *
+   * @param {Array<string>} args - Extra args to mocha executable
+   * @param {Function} done - Callback
+   * @param {string} cwd - Current working directory for mocha run, optional
+   */
+  invokeMocha: invokeMocha
 };
 
-function invokeMocha (args, fn) {
+function invokeMocha (args, fn, cwd) {
   var output, mocha, listener;
 
   output = '';
-  args = [path.join('bin', 'mocha')].concat(args);
-  mocha = spawn(process.execPath, args);
+  args = [path.join(__dirname, '..', '..', 'bin', 'mocha')].concat(args);
+  mocha = spawn(process.execPath, args, { cwd: cwd });
 
   listener = function (data) {
     output += data;
diff --git a/test/integration/options.spec.js b/test/integration/options.spec.js
--- a/test/integration/options.spec.js
+++ b/test/integration/options.spec.js
@@ -1,7 +1,9 @@
 'use strict';
 
+var path = require('path');
 var assert = require('assert');
 var run = require('./helpers').runMochaJSON;
+var directInvoke = require('./helpers').invokeMocha;
 var args = [];
 
 describe('options', function () {
@@ -386,4 +388,14 @@ describe('options', function () {
       it('should not force exit after root suite completion', runExit(false, 'disabled'));
     });
   });
+
+  describe('--help', function () {
+    it('works despite the presence of mocha.opts', function (done) {
+      directInvoke(['-h'], function (error, result) {
+        if (error) { return done(error); }
+        expect(result.output).to.contain('Usage:');
+        done();
+      }, path.join(__dirname, 'fixtures', 'options', 'help'));
+    });
+  });
 });