11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_cirequire('../common'); 41cb0ef41Sopenharmony_ciconst assert = require('assert'); 51cb0ef41Sopenharmony_ciconst { spawnSync } = require('child_process'); 61cb0ef41Sopenharmony_ci 71cb0ef41Sopenharmony_ciconst node = process.execPath; 81cb0ef41Sopenharmony_ci 91cb0ef41Sopenharmony_ci// Test both sets of arguments that check syntax 101cb0ef41Sopenharmony_ciconst syntaxArgs = [ 111cb0ef41Sopenharmony_ci '-c', 121cb0ef41Sopenharmony_ci '--check', 131cb0ef41Sopenharmony_ci]; 141cb0ef41Sopenharmony_ci 151cb0ef41Sopenharmony_ci// Should not execute code piped from stdin with --check. 161cb0ef41Sopenharmony_ci// Loop each possible option, `-c` or `--check`. 171cb0ef41Sopenharmony_cisyntaxArgs.forEach(function(arg) { 181cb0ef41Sopenharmony_ci const stdin = 'throw new Error("should not get run");'; 191cb0ef41Sopenharmony_ci const c = spawnSync(node, [arg], { encoding: 'utf8', input: stdin }); 201cb0ef41Sopenharmony_ci 211cb0ef41Sopenharmony_ci // No stdout or stderr should be produced 221cb0ef41Sopenharmony_ci assert.strictEqual(c.stdout, ''); 231cb0ef41Sopenharmony_ci assert.strictEqual(c.stderr, ''); 241cb0ef41Sopenharmony_ci 251cb0ef41Sopenharmony_ci assert.strictEqual(c.status, 0); 261cb0ef41Sopenharmony_ci}); 271cb0ef41Sopenharmony_ci 281cb0ef41Sopenharmony_ci// Check --input-type=module 291cb0ef41Sopenharmony_cisyntaxArgs.forEach(function(arg) { 301cb0ef41Sopenharmony_ci const stdin = 'export var p = 5; throw new Error("should not get run");'; 311cb0ef41Sopenharmony_ci const c = spawnSync( 321cb0ef41Sopenharmony_ci node, 331cb0ef41Sopenharmony_ci ['--no-warnings', '--input-type=module', arg], 341cb0ef41Sopenharmony_ci { encoding: 'utf8', input: stdin } 351cb0ef41Sopenharmony_ci ); 361cb0ef41Sopenharmony_ci 371cb0ef41Sopenharmony_ci // No stdout or stderr should be produced 381cb0ef41Sopenharmony_ci assert.strictEqual(c.stdout, ''); 391cb0ef41Sopenharmony_ci assert.strictEqual(c.stderr, ''); 401cb0ef41Sopenharmony_ci 411cb0ef41Sopenharmony_ci assert.strictEqual(c.status, 0); 421cb0ef41Sopenharmony_ci}); 43