2018-12-09 09:44:44 -08:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const common = require('../common');
|
|
|
|
const assert = require('assert');
|
|
|
|
const { exec } = require('child_process');
|
|
|
|
const fixtures = require('../common/fixtures');
|
|
|
|
|
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 = (flag, file, callback) => exec(
|
|
|
|
`"${common.isWindows ? process.execPath : '$NODE'}" ${flag} "${common.isWindows ? file : '$FILE'}"`,
|
|
|
|
common.isWindows ? undefined : { env: { ...process.env, NODE: process.execPath, FILE: file } },
|
|
|
|
callback,
|
|
|
|
);
|
2018-12-09 09:44:44 -08:00
|
|
|
|
2019-01-21 01:22:27 +01:00
|
|
|
// Test both sets of arguments that check syntax
|
2018-12-09 09:44:44 -08:00
|
|
|
const syntaxArgs = [
|
2024-09-22 15:03:30 +02:00
|
|
|
'-c',
|
|
|
|
'--check',
|
2018-12-09 09:44:44 -08:00
|
|
|
];
|
|
|
|
|
2019-01-21 01:22:27 +01:00
|
|
|
// Test good syntax with and without shebang
|
2018-12-09 09:44:44 -08:00
|
|
|
[
|
|
|
|
'syntax/good_syntax.js',
|
|
|
|
'syntax/good_syntax',
|
2021-12-20 07:33:34 +08:00
|
|
|
'syntax/good_syntax.mjs',
|
2018-12-09 09:44:44 -08:00
|
|
|
'syntax/good_syntax_shebang.js',
|
|
|
|
'syntax/good_syntax_shebang',
|
2021-03-26 08:51:08 -07:00
|
|
|
'syntax/illegal_if_not_wrapped.js',
|
2018-12-09 09:44:44 -08:00
|
|
|
].forEach(function(file) {
|
|
|
|
file = fixtures.path(file);
|
|
|
|
|
2019-01-21 01:22:27 +01:00
|
|
|
// Loop each possible option, `-c` or `--check`
|
2024-09-22 15:03:30 +02:00
|
|
|
syntaxArgs.forEach(function(flag) {
|
|
|
|
execNode(flag, file, common.mustCall((err, stdout, stderr) => {
|
2018-12-09 09:44:44 -08:00
|
|
|
if (err) {
|
|
|
|
console.log('-- stdout --');
|
|
|
|
console.log(stdout);
|
|
|
|
console.log('-- stderr --');
|
|
|
|
console.log(stderr);
|
|
|
|
}
|
|
|
|
assert.ifError(err);
|
|
|
|
assert.strictEqual(stdout, '');
|
|
|
|
assert.strictEqual(stderr, '');
|
|
|
|
}));
|
|
|
|
});
|
|
|
|
});
|