@ -19,6 +19,7 @@ const filename = __filename.replace(/\\/g, '/');
// assert that nothing is written to stdout
// assert that nothing is written to stdout
child . exec ( nodejs + ' --eval 42' ,
child . exec ( nodejs + ' --eval 42' ,
function ( err , stdout , stderr ) {
function ( err , stdout , stderr ) {
assert . ifError ( err ) ;
assert . strictEqual ( stdout , '' ) ;
assert . strictEqual ( stdout , '' ) ;
assert . strictEqual ( stderr , '' ) ;
assert . strictEqual ( stderr , '' ) ;
} ) ;
} ) ;
@ -26,6 +27,7 @@ child.exec(nodejs + ' --eval 42',
// assert that "42\n" is written to stderr
// assert that "42\n" is written to stderr
child . exec ( nodejs + ' --eval "console.error(42)"' ,
child . exec ( nodejs + ' --eval "console.error(42)"' ,
function ( err , stdout , stderr ) {
function ( err , stdout , stderr ) {
assert . ifError ( err ) ;
assert . strictEqual ( stdout , '' ) ;
assert . strictEqual ( stdout , '' ) ;
assert . strictEqual ( stderr , '42\n' ) ;
assert . strictEqual ( stderr , '42\n' ) ;
} ) ;
} ) ;
@ -36,12 +38,14 @@ child.exec(nodejs + ' --eval "console.error(42)"',
child . exec ( cmd + '42' ,
child . exec ( cmd + '42' ,
function ( err , stdout , stderr ) {
function ( err , stdout , stderr ) {
assert . ifError ( err ) ;
assert . strictEqual ( stdout , '42\n' ) ;
assert . strictEqual ( stdout , '42\n' ) ;
assert . strictEqual ( stderr , '' ) ;
assert . strictEqual ( stderr , '' ) ;
} ) ;
} ) ;
child . exec ( cmd + "'[]'" , common . mustCall (
child . exec ( cmd + "'[]'" , common . mustCall (
function ( err , stdout , stderr ) {
function ( err , stdout , stderr ) {
assert . ifError ( err ) ;
assert . strictEqual ( stdout , '[]\n' ) ;
assert . strictEqual ( stdout , '[]\n' ) ;
assert . strictEqual ( stderr , '' ) ;
assert . strictEqual ( stderr , '' ) ;
} ) ) ;
} ) ) ;
@ -49,31 +53,40 @@ child.exec(nodejs + ' --eval "console.error(42)"',
// assert that module loading works
// assert that module loading works
child . exec ( nodejs + ' --eval "require(\'' + filename + '\')"' ,
child . exec ( nodejs + ' --eval "require(\'' + filename + '\')"' ,
function ( status , stdout , stderr ) {
function ( err , stdout , stderr ) {
assert . strictEqual ( status . code , 42 ) ;
assert . strictEqual ( err . code , 42 ) ;
assert . strictEqual (
stdout , 'Loaded as a module, exiting with status code 42.\n' ) ;
assert . strictEqual ( stderr , '' ) ;
} ) ;
} ) ;
// Check that builtin modules are pre-defined.
// Check that builtin modules are pre-defined.
child . exec ( nodejs + ' --print "os.platform()"' ,
child . exec ( nodejs + ' --print "os.platform()"' ,
function ( status , stdout , stderr ) {
function ( err , stdout , stderr ) {
assert . ifError ( err ) ;
assert . strictEqual ( stderr , '' ) ;
assert . strictEqual ( stderr , '' ) ;
assert . strictEqual ( stdout . trim ( ) , require ( 'os' ) . platform ( ) ) ;
assert . strictEqual ( stdout . trim ( ) , require ( 'os' ) . platform ( ) ) ;
} ) ;
} ) ;
// module path resolve bug, regression test
// module path resolve bug, regression test
child . exec ( nodejs + ' --eval "require(\'./test/parallel/test-cli-eval.js\')"' ,
child . exec ( nodejs + ' --eval "require(\'./test/parallel/test-cli-eval.js\')"' ,
function ( status , stdout , stderr ) {
function ( err , stdout , stderr ) {
assert . strictEqual ( status . code , 42 ) ;
assert . strictEqual ( err . code , 42 ) ;
assert . strictEqual (
stdout , 'Loaded as a module, exiting with status code 42.\n' ) ;
assert . strictEqual ( stderr , '' ) ;
} ) ;
} ) ;
// Missing argument should not crash
// Missing argument should not crash
child . exec ( nodejs + ' -e' , common . mustCall ( function ( status , stdout , stderr ) {
child . exec ( nodejs + ' -e' , common . mustCall ( function ( err , stdout , stderr ) {
assert . notStrictEqual ( status , null ) ;
assert . strictEqual ( err . code , 9 ) ;
assert . strictEqual ( status . code , 9 ) ;
assert . strictEqual ( stdout , '' ) ;
assert ( stderr . match ( /node: -e requires an argument\n/ ) ) ;
} ) ) ;
} ) ) ;
// empty program should do nothing
// empty program should do nothing
child . exec ( nodejs + ' -e ""' , function ( status , stdout , stderr ) {
child . exec ( nodejs + ' -e ""' , function ( err , stdout , stderr ) {
assert . ifError ( err ) ;
assert . strictEqual ( stdout , '' ) ;
assert . strictEqual ( stdout , '' ) ;
assert . strictEqual ( stderr , '' ) ;
assert . strictEqual ( stderr , '' ) ;
} ) ;
} ) ;
@ -81,21 +94,25 @@ child.exec(nodejs + ' -e ""', function(status, stdout, stderr) {
// "\\-42" should be interpreted as an escaped expression, not a switch
// "\\-42" should be interpreted as an escaped expression, not a switch
child . exec ( nodejs + ' -p "\\-42"' ,
child . exec ( nodejs + ' -p "\\-42"' ,
function ( err , stdout , stderr ) {
function ( err , stdout , stderr ) {
assert . ifError ( err ) ;
assert . strictEqual ( stdout , '-42\n' ) ;
assert . strictEqual ( stdout , '-42\n' ) ;
assert . strictEqual ( stderr , '' ) ;
assert . strictEqual ( stderr , '' ) ;
} ) ;
} ) ;
child . exec ( nodejs + ' --use-strict -p process.execArgv' ,
child . exec ( nodejs + ' --use-strict -p process.execArgv' ,
function ( status , stdout , stderr ) {
function ( err , stdout , stderr ) {
assert . ifError ( err ) ;
assert . strictEqual (
assert . strictEqual (
stdout , "[ '--use-strict', '-p', 'process.execArgv' ]\n"
stdout , "[ '--use-strict', '-p', 'process.execArgv' ]\n"
) ;
) ;
assert . strictEqual ( stderr , '' ) ;
} ) ;
} ) ;
// Regression test for https://github.com/nodejs/node/issues/3574
// Regression test for https://github.com/nodejs/node/issues/3574
const emptyFile = path . join ( common . fixturesDir , 'empty.js' ) ;
const emptyFile = path . join ( common . fixturesDir , 'empty.js' ) ;
child . exec ( nodejs + ` -e 'require("child_process").fork(" ${ emptyFile } ")' ` ,
child . exec ( nodejs + ` -e 'require("child_process").fork(" ${ emptyFile } ")' ` ,
function ( status , stdout , stderr ) {
function ( err , stdout , stderr ) {
assert . ifError ( err ) ;
assert . strictEqual ( stdout , '' ) ;
assert . strictEqual ( stdout , '' ) ;
assert . strictEqual ( stderr , '' ) ;
assert . strictEqual ( stderr , '' ) ;
} ) ;
} ) ;