2018-12-09 09:44:44 -08:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const common = require('../common');
|
|
|
|
const assert = require('assert');
|
|
|
|
const { exec } = require('child_process');
|
|
|
|
|
2024-09-22 15:03:30 +02:00
|
|
|
// The execPath might contain chars that should be escaped in a shell context.
|
|
|
|
// On non-Windows, we can pass the path via the env; `"` is not a valid char on
|
|
|
|
// Windows, so we can simply pass the path.
|
|
|
|
const execNode = (args, callback) => exec(
|
|
|
|
`"${common.isWindows ? process.execPath : '$NODE'}" ${args}`,
|
|
|
|
common.isWindows ? undefined : { env: { ...process.env, NODE: process.execPath } },
|
|
|
|
callback,
|
|
|
|
);
|
|
|
|
|
2018-12-09 09:44:44 -08:00
|
|
|
|
2019-01-21 01:22:27 +01:00
|
|
|
// Should throw if -c and -e flags are both passed
|
2018-12-09 09:44:44 -08:00
|
|
|
['-c', '--check'].forEach(function(checkFlag) {
|
|
|
|
['-e', '--eval'].forEach(function(evalFlag) {
|
|
|
|
const args = [checkFlag, evalFlag, 'foo'];
|
2024-09-22 15:03:30 +02:00
|
|
|
execNode(args.join(' '), common.mustCall((err, stdout, stderr) => {
|
2018-12-09 09:44:44 -08:00
|
|
|
assert.strictEqual(err instanceof Error, true);
|
|
|
|
assert.strictEqual(err.code, 9);
|
|
|
|
assert(
|
|
|
|
stderr.startsWith(
|
2024-09-22 15:03:30 +02:00
|
|
|
`${process.execPath}: either --check or --eval can be used, not both`
|
2018-12-09 09:44:44 -08:00
|
|
|
)
|
|
|
|
);
|
|
|
|
}));
|
|
|
|
});
|
|
|
|
});
|