11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_ciconst common = require('../common');
41cb0ef41Sopenharmony_ciconst assert = require('assert');
51cb0ef41Sopenharmony_ciconst { exec } = require('child_process');
61cb0ef41Sopenharmony_ciconst fixtures = require('../common/fixtures');
71cb0ef41Sopenharmony_ci
81cb0ef41Sopenharmony_ciconst node = process.execPath;
91cb0ef41Sopenharmony_ci
101cb0ef41Sopenharmony_ci// Test both sets of arguments that check syntax
111cb0ef41Sopenharmony_ciconst syntaxArgs = [
121cb0ef41Sopenharmony_ci  ['-c'],
131cb0ef41Sopenharmony_ci  ['--check'],
141cb0ef41Sopenharmony_ci];
151cb0ef41Sopenharmony_ci
161cb0ef41Sopenharmony_ci// Test good syntax with and without shebang
171cb0ef41Sopenharmony_ci[
181cb0ef41Sopenharmony_ci  'syntax/good_syntax.js',
191cb0ef41Sopenharmony_ci  'syntax/good_syntax',
201cb0ef41Sopenharmony_ci  'syntax/good_syntax.mjs',
211cb0ef41Sopenharmony_ci  'syntax/good_syntax_shebang.js',
221cb0ef41Sopenharmony_ci  'syntax/good_syntax_shebang',
231cb0ef41Sopenharmony_ci  'syntax/illegal_if_not_wrapped.js',
241cb0ef41Sopenharmony_ci].forEach(function(file) {
251cb0ef41Sopenharmony_ci  file = fixtures.path(file);
261cb0ef41Sopenharmony_ci
271cb0ef41Sopenharmony_ci  // Loop each possible option, `-c` or `--check`
281cb0ef41Sopenharmony_ci  syntaxArgs.forEach(function(args) {
291cb0ef41Sopenharmony_ci    const _args = args.concat(file);
301cb0ef41Sopenharmony_ci
311cb0ef41Sopenharmony_ci    const cmd = [node, ..._args].join(' ');
321cb0ef41Sopenharmony_ci    exec(cmd, common.mustCall((err, stdout, stderr) => {
331cb0ef41Sopenharmony_ci      if (err) {
341cb0ef41Sopenharmony_ci        console.log('-- stdout --');
351cb0ef41Sopenharmony_ci        console.log(stdout);
361cb0ef41Sopenharmony_ci        console.log('-- stderr --');
371cb0ef41Sopenharmony_ci        console.log(stderr);
381cb0ef41Sopenharmony_ci      }
391cb0ef41Sopenharmony_ci      assert.ifError(err);
401cb0ef41Sopenharmony_ci      assert.strictEqual(stdout, '');
411cb0ef41Sopenharmony_ci      assert.strictEqual(stderr, '');
421cb0ef41Sopenharmony_ci    }));
431cb0ef41Sopenharmony_ci  });
441cb0ef41Sopenharmony_ci});
45