summaryrefslogtreecommitdiff
path: root/test/parallel/test-cli-eval.js
diff options
context:
space:
mode:
authorJohn Barboza <jbarboza@ca.ibm.com>2016-12-30 00:28:38 -0500
committerRoman Reiss <me@silverwind.io>2017-01-25 00:24:40 +0100
commit0a9f360c98e4864327888a5030d55f7b2cdcc6d9 (patch)
tree2d2e288746c9e58a3e91def6fffa85afcda9d3a2 /test/parallel/test-cli-eval.js
parent5ea98fb17d45195079865a3b3c78a48fe79258c7 (diff)
downloadandroid-node-v8-0a9f360c98e4864327888a5030d55f7b2cdcc6d9.tar.gz
android-node-v8-0a9f360c98e4864327888a5030d55f7b2cdcc6d9.tar.bz2
android-node-v8-0a9f360c98e4864327888a5030d55f7b2cdcc6d9.zip
src: support "--" after "-e" as end-of-options
When the double dash "--" appears after "-e <script>" on the command line, it indicates the end of options and the beginning of positional parameters for the script. PR-URL: https://github.com/nodejs/node/pull/10651 Reviewed-By: Sam Roberts <vieuxtech@gmail.com> Reviewed-By: Roman Reiss <me@silverwind.io> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Diffstat (limited to 'test/parallel/test-cli-eval.js')
-rw-r--r--test/parallel/test-cli-eval.js40
1 files changed, 40 insertions, 0 deletions
diff --git a/test/parallel/test-cli-eval.js b/test/parallel/test-cli-eval.js
index 3eb8219585..260acdb0d6 100644
--- a/test/parallel/test-cli-eval.js
+++ b/test/parallel/test-cli-eval.js
@@ -12,6 +12,11 @@ const child = require('child_process');
const path = require('path');
const nodejs = `"${process.execPath}"`;
+if (process.argv.length > 2) {
+ console.log(process.argv.slice(2).join(' '));
+ process.exit(0);
+}
+
// Assert that nothing is written to stdout.
child.exec(`${nodejs} --eval 42`, common.mustCall((err, stdout, stderr) => {
assert.ifError(err);
@@ -133,3 +138,38 @@ child.exec(`${nodejs} --use-strict -p process.execArgv`,
assert.strictEqual(proc.stderr, '');
assert.strictEqual(proc.stdout, 'start\nbeforeExit\nexit\n');
}
+
+[ '-arg1',
+ '-arg1 arg2 --arg3',
+ '--',
+ 'arg1 -- arg2',
+].forEach(function(args) {
+
+ // Ensure that arguments are successfully passed to eval.
+ const opt = ' --eval "console.log(process.argv.slice(1).join(\' \'))"';
+ const cmd = `${nodejs}${opt} -- ${args}`;
+ child.exec(cmd, common.mustCall(function(err, stdout, stderr) {
+ assert.strictEqual(stdout, args + '\n');
+ assert.strictEqual(stderr, '');
+ assert.strictEqual(err, null);
+ }));
+
+ // Ensure that arguments are successfully passed to print.
+ const popt = ' --print "process.argv.slice(1).join(\' \')"';
+ const pcmd = `${nodejs}${popt} -- ${args}`;
+ child.exec(pcmd, common.mustCall(function(err, stdout, stderr) {
+ assert.strictEqual(stdout, args + '\n');
+ assert.strictEqual(stderr, '');
+ assert.strictEqual(err, null);
+ }));
+
+ // Ensure that arguments are successfully passed to a script.
+ // The first argument after '--' should be interpreted as a script
+ // filename.
+ const filecmd = `${nodejs} -- ${__filename} ${args}`;
+ child.exec(filecmd, common.mustCall(function(err, stdout, stderr) {
+ assert.strictEqual(stdout, args + '\n');
+ assert.strictEqual(stderr, '');
+ assert.strictEqual(err, null);
+ }));
+});