• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2
3const common = require('../common');
4const assert = require('assert');
5const { exec } = require('child_process');
6const fixtures = require('../common/fixtures');
7
8const node = process.execPath;
9
10// Test both sets of arguments that check syntax
11const syntaxArgs = [
12  ['-c'],
13  ['--check'],
14];
15
16// Test good syntax with and without shebang
17[
18  'syntax/good_syntax.js',
19  'syntax/good_syntax',
20  'syntax/good_syntax_shebang.js',
21  'syntax/good_syntax_shebang',
22  'syntax/illegal_if_not_wrapped.js',
23].forEach(function(file) {
24  file = fixtures.path(file);
25
26  // Loop each possible option, `-c` or `--check`
27  syntaxArgs.forEach(function(args) {
28    const _args = args.concat(file);
29
30    const cmd = [node, ..._args].join(' ');
31    exec(cmd, common.mustCall((err, stdout, stderr) => {
32      if (err) {
33        console.log('-- stdout --');
34        console.log(stdout);
35        console.log('-- stderr --');
36        console.log(stderr);
37      }
38      assert.ifError(err);
39      assert.strictEqual(stdout, '');
40      assert.strictEqual(stderr, '');
41    }));
42  });
43});
44