diff options
author | Evan Lucas <evanlucas@me.com> | 2014-02-25 21:40:16 +0400 |
---|---|---|
committer | Domenic Denicola <domenic@domenicdenicola.com> | 2014-04-18 07:51:46 +0400 |
commit | 057d9b781501d678b1582b63516bef06b9fa4d11 (patch) | |
tree | 904d73ca749875657e4fb44e43ca246a92a9f2f4 /test | |
parent | 6ef9f9dd71620b03f039823bb082cfbeb7200416 (diff) |
Don't return 0 exit code on invalid command
Fixes #4780
Diffstat (limited to 'test')
-rw-r--r-- | test/common-tap.js | 12 | ||||
-rw-r--r-- | test/tap/invalid-cmd-exit-code.js | 27 |
2 files changed, 33 insertions, 6 deletions
diff --git a/test/common-tap.js b/test/common-tap.js index c4f3f613f..f5311c5d4 100644 --- a/test/common-tap.js +++ b/test/common-tap.js @@ -12,22 +12,22 @@ function run (cmd, t, opts, cb) { if (!t || !t.end) throw new Error("node-tap instance is missing") - var c = "" - , e = "" + var stdout = "" + , stderr = "" , node = process.execPath , child = spawn(node, cmd, opts) child.stderr.on("data", function (chunk) { - e += chunk + stderr += chunk }) child.stdout.on("data", function (chunk) { - c += chunk + stdout += chunk }) - child.stdout.on("end", function () { + child.on("close", function (code) { if (cb) - cb(t, c, e, { cmd: cmd, opts: opts }) + cb(t, stdout, stderr, code) else t.end() }) diff --git a/test/tap/invalid-cmd-exit-code.js b/test/tap/invalid-cmd-exit-code.js new file mode 100644 index 000000000..c3dabb85a --- /dev/null +++ b/test/tap/invalid-cmd-exit-code.js @@ -0,0 +1,27 @@ +var test = require('tap').test +var npm = require.resolve('../../bin/npm-cli.js') +var node = process.execPath +var common = require('../common-tap.js') + +var opts = { cwd: process.cwd() } + +test('npm asdf should return exit code 1', function(t) { + common.run([npm, 'asdf'], t, opts, function (t, _, __, c) { + t.equal(c, 1, 'exit code should be 1') + t.end() + }) +}) + +test('npm help should return exit code 0', function(t) { + common.run([npm, 'help'], t, opts, function (t, _, __, c) { + t.equal(c, 0, 'exit code should be 0') + t.end() + }) +}) + +test('npm help fadf should return exit code 0', function(t) { + common.run([npm, 'help', 'fadf'], t, opts, function (t, _, __, c) { + t.equal(c, 0, 'exit code should be 0') + t.end() + }) +}) |