@@ -11,6 +11,10 @@ const child = require('child_process');
1111const path = require ( 'path' ) ;
1212const nodejs = '"' + process . execPath + '"' ;
1313
14+ if ( process . argv . length > 2 ) {
15+ console . log ( process . argv . slice ( 2 ) . join ( ' ' ) ) ;
16+ process . exit ( 0 ) ;
17+ }
1418
1519// replace \ by / because windows uses backslashes in paths, but they're still
1620// interpreted as the escape character when put between quotes.
@@ -113,3 +117,38 @@ child.exec(nodejs + ` -e 'require("child_process").fork("${emptyFile}")'`,
113117 assert . strictEqual ( proc . stderr , '' ) ;
114118 assert . strictEqual ( proc . stdout , 'start\nbeforeExit\nexit\n' ) ;
115119}
120+
121+ [ '-arg1' ,
122+ '-arg1 arg2 --arg3' ,
123+ '--' ,
124+ 'arg1 -- arg2' ,
125+ ] . forEach ( function ( args ) {
126+
127+ // Ensure that arguments are successfully passed to eval.
128+ const opt = ' --eval "console.log(process.argv.slice(1).join(\' \'))"' ;
129+ const cmd = `${ nodejs } ${ opt } -- ${ args } ` ;
130+ child . exec ( cmd , common . mustCall ( function ( err , stdout , stderr ) {
131+ assert . strictEqual ( stdout , args + '\n' ) ;
132+ assert . strictEqual ( stderr , '' ) ;
133+ assert . strictEqual ( err , null ) ;
134+ } ) ) ;
135+
136+ // Ensure that arguments are successfully passed to print.
137+ const popt = ' --print "process.argv.slice(1).join(\' \')"' ;
138+ const pcmd = `${ nodejs } ${ popt } -- ${ args } ` ;
139+ child . exec ( pcmd , common . mustCall ( function ( err , stdout , stderr ) {
140+ assert . strictEqual ( stdout , args + '\n' ) ;
141+ assert . strictEqual ( stderr , '' ) ;
142+ assert . strictEqual ( err , null ) ;
143+ } ) ) ;
144+
145+ // Ensure that arguments are successfully passed to a script.
146+ // The first argument after '--' should be interpreted as a script
147+ // filename.
148+ const filecmd = `${ nodejs } -- ${ __filename } ${ args } ` ;
149+ child . exec ( filecmd , common . mustCall ( function ( err , stdout , stderr ) {
150+ assert . strictEqual ( stdout , args + '\n' ) ;
151+ assert . strictEqual ( stderr , '' ) ;
152+ assert . strictEqual ( err , null ) ;
153+ } ) ) ;
154+ } ) ;
0 commit comments