diff options
author | Sam Roberts <sam@strongloop.com> | 2014-10-08 13:30:38 -0700 |
---|---|---|
committer | Trevor Norris <trev.norris@gmail.com> | 2014-11-18 16:20:31 -0800 |
commit | 8032a210250c86877898331ac4474f39b3a573c6 (patch) | |
tree | d8d3ebe7b9beb932fbee83c0a192ccc95da171fa | |
parent | 70dafa7b624abd43432e03304d65cc527fbecc11 (diff) | |
download | node-8032a210250c86877898331ac4474f39b3a573c6.tar.gz |
test: test all spawn parameter positions
PR-URL: https://github.com/joyent/node/pull/8454
Reviewed-by: Trevor Norris <trev.norris@gmail.com>
-rw-r--r-- | test/simple/test-child-process-spawn-typeerror.js | 93 |
1 files changed, 72 insertions, 21 deletions
diff --git a/test/simple/test-child-process-spawn-typeerror.js b/test/simple/test-child-process-spawn-typeerror.js index e28bd2a51..4a136db86 100644 --- a/test/simple/test-child-process-spawn-typeerror.js +++ b/test/simple/test-child-process-spawn-typeerror.js @@ -24,35 +24,86 @@ var child_process = require('child_process'); var spawn = child_process.spawn; var fork = child_process.fork; var execFile = child_process.execFile; -var cmd = (process.platform === 'win32') ? 'dir' : 'ls'; +var cmd = (process.platform === 'win32') ? 'rundll32' : 'ls'; var empty = require('../common').fixturesDir + '/empty.js'; +// Argument types for combinatorics +var a=[], o={}, c=(function callback(){}), s='string', u=undefined, n=null; -// verify that args argument must be an array -assert.throws(function() { - spawn(cmd, 'this is not an array'); -}, TypeError); +// function spawn(file=f [,args=a] [, options=o]) has valid combinations: +// (f) +// (f, a) +// (f, a, o) +// (f, o) +assert.doesNotThrow(function() { spawn(cmd); }); +assert.doesNotThrow(function() { spawn(cmd, a); }); +assert.doesNotThrow(function() { spawn(cmd, a, o); }); +assert.doesNotThrow(function() { spawn(cmd, o); }); -// verify that args argument is optional -assert.doesNotThrow(function() { - spawn(cmd, {}); -}); +// Variants of undefined as explicit 'no argument' at a position +assert.doesNotThrow(function() { execFile(empty, u, o); }); +assert.doesNotThrow(function() { execFile(empty, a, u); }); +assert.doesNotThrow(function() { execFile(empty, n, o); }); +assert.doesNotThrow(function() { execFile(empty, a, n); }); + +assert.throws(function() { spawn(cmd, s); }, TypeError); +assert.doesNotThrow(function() { spawn(cmd, a, s); }, TypeError); // verify that execFile has same argument parsing behaviour as spawn -assert.throws(function() { - execFile(cmd, 'this is not an array'); -}, TypeError); +// +// function execFile(file=f [,args=a] [, options=o] [, callback=c]) has valid +// combinations: +// (f) +// (f, a) +// (f, a, o) +// (f, a, o, c) +// (f, a, c) +// (f, o) +// (f, o, c) +// (f, c) +assert.doesNotThrow(function() { execFile(cmd); }); +assert.doesNotThrow(function() { execFile(cmd, a); }); +assert.doesNotThrow(function() { execFile(cmd, a, o); }); +assert.doesNotThrow(function() { execFile(cmd, a, o, c); }); +assert.doesNotThrow(function() { execFile(cmd, a, c); }); +assert.doesNotThrow(function() { execFile(cmd, o); }); +assert.doesNotThrow(function() { execFile(cmd, o, c); }); +assert.doesNotThrow(function() { execFile(cmd, c); }); + +// Variants of undefined as explicit 'no argument' at a position +assert.doesNotThrow(function() { execFile(cmd, u, o, c); }); +assert.doesNotThrow(function() { execFile(cmd, a, u, c); }); +assert.doesNotThrow(function() { execFile(cmd, a, o, u); }); +assert.doesNotThrow(function() { execFile(cmd, n, o, c); }); +assert.doesNotThrow(function() { execFile(cmd, a, n, c); }); +assert.doesNotThrow(function() { execFile(cmd, a, o, n); }); + +// string is invalid in arg position (this may seem strange, but is +// consistent across node API, cf. `net.createServer('not options', 'not +// callback')` +assert.throws(function() { execFile(cmd, s, o, c); }, TypeError); +assert.doesNotThrow(function() { execFile(cmd, a, s, c); }); +assert.doesNotThrow(function() { execFile(cmd, a, o, s); }); -assert.doesNotThrow(function() { - execFile(cmd, {}); -}); // verify that fork has same argument parsing behaviour as spawn -assert.throws(function() { - fork(empty, 'this is not an array'); -}, TypeError); +// +// function fork(file=f [,args=a] [, options=o]) has valid combinations: +// (f) +// (f, a) +// (f, a, o) +// (f, o) +assert.doesNotThrow(function() { fork(empty); }); +assert.doesNotThrow(function() { fork(empty, a); }); +assert.doesNotThrow(function() { fork(empty, a, o); }); +assert.doesNotThrow(function() { fork(empty, o); }); + +// Variants of undefined as explicit 'no argument' at a position +assert.doesNotThrow(function() { execFile(empty, u, o); }); +assert.doesNotThrow(function() { execFile(empty, a, u); }); +assert.doesNotThrow(function() { execFile(empty, n, o); }); +assert.doesNotThrow(function() { execFile(empty, a, n); }); -assert.doesNotThrow(function() { - execFile(empty, {}); -}); +assert.throws(function() { fork(empty, s); }, TypeError); +assert.doesNotThrow(function() { fork(empty, a, s); }, TypeError); |