2012-07-28 23:00:27 +02:00
|
|
|
if (module.parent) {
|
|
|
|
// signal we've been loaded as a module
|
|
|
|
console.log('Loaded as a module, exiting with status code 42.');
|
|
|
|
process.exit(42);
|
|
|
|
}
|
|
|
|
|
2015-02-22 03:47:04 +01:00
|
|
|
var common = require('../common'),
|
2011-09-11 03:52:44 +02:00
|
|
|
assert = require('assert'),
|
|
|
|
child = require('child_process'),
|
|
|
|
nodejs = '"' + process.execPath + '"';
|
2011-08-24 08:42:23 +02:00
|
|
|
|
2012-07-28 23:00:27 +02:00
|
|
|
|
2011-09-11 03:52:44 +02:00
|
|
|
// replace \ by / because windows uses backslashes in paths, but they're still
|
|
|
|
// interpreted as the escape character when put between quotes.
|
|
|
|
var filename = __filename.replace(/\\/g, '/');
|
2010-11-16 15:44:06 +01:00
|
|
|
|
2011-07-25 23:54:44 +02:00
|
|
|
// assert that nothing is written to stdout
|
|
|
|
child.exec(nodejs + ' --eval 42',
|
2010-12-05 20:15:30 +01:00
|
|
|
function(err, stdout, stderr) {
|
2011-07-25 23:54:44 +02:00
|
|
|
assert.equal(stdout, '');
|
2012-09-04 14:40:59 +02:00
|
|
|
assert.equal(stderr, '');
|
2011-07-25 23:54:44 +02:00
|
|
|
});
|
|
|
|
|
2011-08-04 16:43:11 +02:00
|
|
|
// assert that "42\n" is written to stderr
|
2011-09-11 03:52:44 +02:00
|
|
|
child.exec(nodejs + ' --eval "console.error(42)"',
|
2011-07-25 23:54:44 +02:00
|
|
|
function(err, stdout, stderr) {
|
2012-09-04 14:40:59 +02:00
|
|
|
assert.equal(stdout, '');
|
2011-10-05 00:08:18 +02:00
|
|
|
assert.equal(stderr, '42\n');
|
2010-12-05 20:15:30 +01:00
|
|
|
});
|
2010-11-16 15:44:06 +01:00
|
|
|
|
2012-05-18 02:02:57 +02:00
|
|
|
// assert that the expected output is written to stdout
|
2012-09-04 14:19:59 +02:00
|
|
|
['--print', '-p -e', '-pe', '-p'].forEach(function(s) {
|
2011-12-01 17:21:00 +01:00
|
|
|
var cmd = nodejs + ' ' + s + ' ';
|
|
|
|
|
|
|
|
child.exec(cmd + '42',
|
|
|
|
function(err, stdout, stderr) {
|
|
|
|
assert.equal(stdout, '42\n');
|
2012-09-04 14:40:59 +02:00
|
|
|
assert.equal(stderr, '');
|
2011-12-01 17:21:00 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
child.exec(cmd + "'[]'",
|
|
|
|
function(err, stdout, stderr) {
|
|
|
|
assert.equal(stdout, '[]\n');
|
2012-09-04 14:40:59 +02:00
|
|
|
assert.equal(stderr, '');
|
2011-12-01 17:21:00 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2010-11-16 15:44:06 +01:00
|
|
|
// assert that module loading works
|
2011-09-11 03:52:44 +02:00
|
|
|
child.exec(nodejs + ' --eval "require(\'' + filename + '\')"',
|
2010-12-05 20:15:30 +01:00
|
|
|
function(status, stdout, stderr) {
|
|
|
|
assert.equal(status.code, 42);
|
|
|
|
});
|
2010-11-16 15:44:06 +01:00
|
|
|
|
|
|
|
// module path resolve bug, regression test
|
2014-12-17 14:30:04 +01:00
|
|
|
child.exec(nodejs + ' --eval "require(\'./test/parallel/test-cli-eval.js\')"',
|
2010-12-05 20:15:30 +01:00
|
|
|
function(status, stdout, stderr) {
|
|
|
|
assert.equal(status.code, 42);
|
|
|
|
});
|
2011-05-28 19:04:36 +02:00
|
|
|
|
|
|
|
// empty program should do nothing
|
|
|
|
child.exec(nodejs + ' -e ""', function(status, stdout, stderr) {
|
2011-07-25 23:54:44 +02:00
|
|
|
assert.equal(stdout, '');
|
2011-05-28 19:04:36 +02:00
|
|
|
assert.equal(stderr, '');
|
|
|
|
});
|
2012-09-04 14:19:59 +02:00
|
|
|
|
|
|
|
// "\\-42" should be interpreted as an escaped expression, not a switch
|
|
|
|
child.exec(nodejs + ' -p "\\-42"',
|
|
|
|
function(err, stdout, stderr) {
|
|
|
|
assert.equal(stdout, '-42\n');
|
2012-09-04 14:40:59 +02:00
|
|
|
assert.equal(stderr, '');
|
2012-09-04 14:19:59 +02:00
|
|
|
});
|
2013-09-02 16:42:01 +02:00
|
|
|
|
|
|
|
child.exec(nodejs + ' --use-strict -p process.execArgv',
|
|
|
|
function(status, stdout, stderr) {
|
|
|
|
assert.equal(stdout, "[ '--use-strict', '-p', 'process.execArgv' ]\n");
|
|
|
|
});
|