2018-12-10 01:44:44 +08:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const common = require('../common');
|
|
|
|
const assert = require('assert');
|
|
|
|
const { exec } = require('child_process');
|
|
|
|
const fixtures = require('../common/fixtures');
|
|
|
|
|
2019-01-21 08:22:27 +08:00
|
|
|
// Test both sets of arguments that check syntax
|
2018-12-10 01:44:44 +08:00
|
|
|
const syntaxArgs = [
|
2024-09-22 21:03:30 +08:00
|
|
|
'-c',
|
|
|
|
'--check',
|
2018-12-10 01:44:44 +08:00
|
|
|
];
|
|
|
|
|
2019-01-21 08:22:27 +08:00
|
|
|
// Test good syntax with and without shebang
|
2018-12-10 01: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-10 01:44:44 +08:00
|
|
|
'syntax/good_syntax_shebang.js',
|
|
|
|
'syntax/good_syntax_shebang',
|
2021-03-26 23:51:08 +08:00
|
|
|
'syntax/illegal_if_not_wrapped.js',
|
2018-12-10 01:44:44 +08:00
|
|
|
].forEach(function(file) {
|
|
|
|
file = fixtures.path(file);
|
|
|
|
|
2019-01-21 08:22:27 +08:00
|
|
|
// Loop each possible option, `-c` or `--check`
|
2024-09-22 21:03:30 +08:00
|
|
|
syntaxArgs.forEach(function(flag) {
|
2024-09-30 04:44:52 +08:00
|
|
|
exec(...common.escapePOSIXShell`"${process.execPath}" ${flag} "${file}"`, common.mustCall((err, stdout, stderr) => {
|
2018-12-10 01: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, '');
|
|
|
|
}));
|
|
|
|
});
|
|
|
|
});
|