summaryrefslogtreecommitdiff
path: root/test/parallel/test-child-process-spawn-typeerror.js
diff options
context:
space:
mode:
authorJames M Snell <jasnell@gmail.com>2015-09-02 14:16:24 -0700
committerRod Vagg <rod@vagg.org>2015-09-06 21:38:00 +1000
commit32037b78a20ba9df2e80cae7d2c0f4ce9efbeac9 (patch)
tree2a4022c700987d0bbca4e38c837c9f2564bce856 /test/parallel/test-child-process-spawn-typeerror.js
parent10a32aee84cf93f1b1b45395fd9d583231272209 (diff)
downloadandroid-node-v8-32037b78a20ba9df2e80cae7d2c0f4ce9efbeac9.tar.gz
android-node-v8-32037b78a20ba9df2e80cae7d2c0f4ce9efbeac9.tar.bz2
android-node-v8-32037b78a20ba9df2e80cae7d2c0f4ce9efbeac9.zip
child_process: check execFile and fork args
Port of joyent/node commits: * https://github.com/nodejs/node-v0.x-archive/commit/e17c5a72b23f920f291d61f2780068c18768cb92 * https://github.com/nodejs/node-v0.x-archive/commit/70dafa7b624abd43432e03304d65cc527fbecc11 Pull over test-child-process-spawn-typeerror.js from v0.12, replacing the existing test in master. The new test includes a broader set of tests on the various arg choices and throws. Reviewed-By: trevnorris - Trevor Norris <trevnorris@nodejs.org> Reviewed-By: cjihrig - Colin Ihrig <cjihrig@gmail.com> Reviewed-By: thefourtheye - Sakthipriyan Vairamani PR-URL: https://github.com/nodejs/node/pull/2667 Fixes: https://github.com/nodejs/node/issues/2515
Diffstat (limited to 'test/parallel/test-child-process-spawn-typeerror.js')
-rw-r--r--test/parallel/test-child-process-spawn-typeerror.js103
1 files changed, 94 insertions, 9 deletions
diff --git a/test/parallel/test-child-process-spawn-typeerror.js b/test/parallel/test-child-process-spawn-typeerror.js
index 348ab2491d..44d67e8608 100644
--- a/test/parallel/test-child-process-spawn-typeerror.js
+++ b/test/parallel/test-child-process-spawn-typeerror.js
@@ -1,14 +1,19 @@
'use strict';
-var assert = require('assert');
-var child_process = require('child_process');
-var spawn = child_process.spawn;
-var cmd = require('../common').isWindows ? 'rundll32' : 'ls';
-var invalidArgsMsg = /Incorrect value of args option/;
-var invalidOptionsMsg = /options argument must be an object/;
-
-// verify that args argument must be an array
+const assert = require('assert');
+const child_process = require('child_process');
+const spawn = child_process.spawn;
+const fork = child_process.fork;
+const execFile = child_process.execFile;
+const common = require('../common');
+const cmd = common.isWindows ? 'rundll32' : 'ls';
+const invalidcmd = 'hopefully_you_dont_have_this_on_your_machine';
+const invalidArgsMsg = /Incorrect value of args option/;
+const invalidOptionsMsg = /options argument must be an object/;
+const empty = common.fixturesDir + '/empty.js';
+
assert.throws(function() {
- spawn(cmd, 'this is not an array');
+ var child = spawn(invalidcmd, 'this is not an array');
+ child.on('error', assert.fail);
}, TypeError);
// verify that valid argument combinations do not throw
@@ -49,3 +54,83 @@ assert.throws(function() {
spawn(cmd, [], 1);
}, invalidOptionsMsg);
+// Argument types for combinatorics
+const a = [];
+const o = {};
+const c = function callback() {};
+const s = 'string';
+const u = undefined;
+const n = null;
+
+// 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); });
+
+// Variants of undefined as explicit 'no argument' at a position
+assert.doesNotThrow(function() { spawn(cmd, u, o); });
+assert.doesNotThrow(function() { spawn(cmd, a, u); });
+
+assert.throws(function() { spawn(cmd, n, o); }, TypeError);
+assert.throws(function() { spawn(cmd, a, n); }, TypeError);
+
+assert.throws(function() { spawn(cmd, s); }, TypeError);
+assert.throws(function() { spawn(cmd, a, s); }, TypeError);
+
+
+// verify that execFile has same argument parsing behaviour as spawn
+//
+// 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); });
+
+
+// verify that fork has same argument parsing behaviour as spawn
+//
+// 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); });
+
+assert.throws(function() { fork(empty, s); }, TypeError);
+assert.doesNotThrow(function() { fork(empty, a, s); }, TypeError);