@@ -12,6 +12,11 @@ const child = require('child_process');
1212const path = require ( 'path' ) ;
1313const nodejs = `"${ process . execPath } "` ;
1414
15+ if ( process . argv . length > 2 ) {
16+ console . log ( process . argv . slice ( 2 ) . join ( ' ' ) ) ;
17+ process . exit ( 0 ) ;
18+ }
19+
1520// Assert that nothing is written to stdout.
1621child . exec ( `${ nodejs } --eval 42` , common . mustCall ( ( err , stdout , stderr ) => {
1722 assert . ifError ( err ) ;
@@ -133,3 +138,38 @@ child.exec(`${nodejs} --use-strict -p process.execArgv`,
133138 assert . strictEqual ( proc . stderr , '' ) ;
134139 assert . strictEqual ( proc . stdout , 'start\nbeforeExit\nexit\n' ) ;
135140}
141+
142+ [ '-arg1' ,
143+ '-arg1 arg2 --arg3' ,
144+ '--' ,
145+ 'arg1 -- arg2' ,
146+ ] . forEach ( function ( args ) {
147+
148+ // Ensure that arguments are successfully passed to eval.
149+ const opt = ' --eval "console.log(process.argv.slice(1).join(\' \'))"' ;
150+ const cmd = `${ nodejs } ${ opt } -- ${ args } ` ;
151+ child . exec ( cmd , common . mustCall ( function ( err , stdout , stderr ) {
152+ assert . strictEqual ( stdout , args + '\n' ) ;
153+ assert . strictEqual ( stderr , '' ) ;
154+ assert . strictEqual ( err , null ) ;
155+ } ) ) ;
156+
157+ // Ensure that arguments are successfully passed to print.
158+ const popt = ' --print "process.argv.slice(1).join(\' \')"' ;
159+ const pcmd = `${ nodejs } ${ popt } -- ${ args } ` ;
160+ child . exec ( pcmd , common . mustCall ( function ( err , stdout , stderr ) {
161+ assert . strictEqual ( stdout , args + '\n' ) ;
162+ assert . strictEqual ( stderr , '' ) ;
163+ assert . strictEqual ( err , null ) ;
164+ } ) ) ;
165+
166+ // Ensure that arguments are successfully passed to a script.
167+ // The first argument after '--' should be interpreted as a script
168+ // filename.
169+ const filecmd = `${ nodejs } -- ${ __filename } ${ args } ` ;
170+ child . exec ( filecmd , common . mustCall ( function ( err , stdout , stderr ) {
171+ assert . strictEqual ( stdout , args + '\n' ) ;
172+ assert . strictEqual ( stderr , '' ) ;
173+ assert . strictEqual ( err , null ) ;
174+ } ) ) ;
175+ } ) ;
0 commit comments