2018-12-09 09:44:44 -08:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
require('../common');
|
|
|
|
const assert = require('assert');
|
|
|
|
const { spawnSync } = require('child_process');
|
|
|
|
|
|
|
|
const node = process.execPath;
|
|
|
|
|
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 = [
|
2018-08-28 17:28:46 +02:00
|
|
|
'-c',
|
2021-03-26 08:51:08 -07:00
|
|
|
'--check',
|
2018-12-09 09:44:44 -08:00
|
|
|
];
|
|
|
|
|
2018-12-10 13:27:32 +01:00
|
|
|
// Should not execute code piped from stdin with --check.
|
|
|
|
// Loop each possible option, `-c` or `--check`.
|
2018-08-28 17:28:46 +02:00
|
|
|
syntaxArgs.forEach(function(arg) {
|
2018-12-09 09:44:44 -08:00
|
|
|
const stdin = 'throw new Error("should not get run");';
|
2018-08-28 17:28:46 +02:00
|
|
|
const c = spawnSync(node, [arg], { encoding: 'utf8', input: stdin });
|
|
|
|
|
|
|
|
// No stdout or stderr should be produced
|
|
|
|
assert.strictEqual(c.stdout, '');
|
|
|
|
assert.strictEqual(c.stderr, '');
|
|
|
|
|
|
|
|
assert.strictEqual(c.status, 0);
|
|
|
|
});
|
|
|
|
|
2019-04-15 10:29:56 -07:00
|
|
|
// Check --input-type=module
|
2018-08-28 17:28:46 +02:00
|
|
|
syntaxArgs.forEach(function(arg) {
|
|
|
|
const stdin = 'export var p = 5; throw new Error("should not get run");';
|
|
|
|
const c = spawnSync(
|
|
|
|
node,
|
2019-10-11 17:57:13 -04:00
|
|
|
['--no-warnings', '--input-type=module', arg],
|
2018-08-28 17:28:46 +02:00
|
|
|
{ encoding: 'utf8', input: stdin }
|
|
|
|
);
|
2018-12-09 09:44:44 -08:00
|
|
|
|
2019-03-07 01:03:53 +01:00
|
|
|
// No stdout or stderr should be produced
|
2018-12-09 09:44:44 -08:00
|
|
|
assert.strictEqual(c.stdout, '');
|
|
|
|
assert.strictEqual(c.stderr, '');
|
|
|
|
|
|
|
|
assert.strictEqual(c.status, 0);
|
|
|
|
});
|