diff options
author | Teddy Katz <teddy.katz@gmail.com> | 2017-03-05 03:05:40 -0500 |
---|---|---|
committer | Teddy Katz <teddy.katz@gmail.com> | 2017-04-03 22:07:32 -0400 |
commit | 3209a8ebf3aa2587c68c4b72e6c3b93176090807 (patch) | |
tree | ccb398eb93eaabccb72083fcc2c41ed2b5af248d /test | |
parent | 53828e8bff277e138447d118c1b0167edd671c52 (diff) | |
download | android-node-v8-3209a8ebf3aa2587c68c4b72e6c3b93176090807.tar.gz android-node-v8-3209a8ebf3aa2587c68c4b72e6c3b93176090807.tar.bz2 android-node-v8-3209a8ebf3aa2587c68c4b72e6c3b93176090807.zip |
lib: ensure --check flag works for piped-in code
Previously, the --check CLI flag had no effect when run on code piped
from stdin. This commit updates the bootstrap logic to handle the
--check flag the same way regardless of whether the code is piped from
stdin.
PR-URL: https://github.com/nodejs/node/pull/11689
Fixes: https://github.com/nodejs/node/issues/11680
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Diffstat (limited to 'test')
-rw-r--r-- | test/parallel/test-cli-syntax.js | 41 |
1 files changed, 38 insertions, 3 deletions
diff --git a/test/parallel/test-cli-syntax.js b/test/parallel/test-cli-syntax.js index d7781eddff..07dd3c4712 100644 --- a/test/parallel/test-cli-syntax.js +++ b/test/parallel/test-cli-syntax.js @@ -31,7 +31,7 @@ const syntaxArgs = [ // no output should be produced assert.strictEqual(c.stdout, '', 'stdout produced'); assert.strictEqual(c.stderr, '', 'stderr produced'); - assert.strictEqual(c.status, 0, 'code == ' + c.status); + assert.strictEqual(c.status, 0, 'code === ' + c.status); }); }); @@ -52,11 +52,14 @@ const syntaxArgs = [ // no stdout should be produced assert.strictEqual(c.stdout, '', 'stdout produced'); + // stderr should include the filename + assert(c.stderr.startsWith(file), "stderr doesn't start with the filename"); + // stderr should have a syntax error message const match = c.stderr.match(/^SyntaxError: Unexpected identifier$/m); assert(match, 'stderr incorrect'); - assert.strictEqual(c.status, 1, 'code == ' + c.status); + assert.strictEqual(c.status, 1, 'code === ' + c.status); }); }); @@ -79,6 +82,38 @@ const syntaxArgs = [ const match = c.stderr.match(/^Error: Cannot find module/m); assert(match, 'stderr incorrect'); - assert.strictEqual(c.status, 1, 'code == ' + c.status); + assert.strictEqual(c.status, 1, 'code === ' + c.status); }); }); + +// should not execute code piped from stdin with --check +// loop each possible option, `-c` or `--check` +syntaxArgs.forEach(function(args) { + const stdin = 'throw new Error("should not get run");'; + const c = spawnSync(node, args, {encoding: 'utf8', input: stdin}); + + // no stdout or stderr should be produced + assert.strictEqual(c.stdout, '', 'stdout produced'); + assert.strictEqual(c.stderr, '', 'stderr produced'); + + assert.strictEqual(c.status, 0, 'code === ' + c.status); +}); + +// should should throw if code piped from stdin with --check has bad syntax +// loop each possible option, `-c` or `--check` +syntaxArgs.forEach(function(args) { + const stdin = 'var foo bar;'; + const c = spawnSync(node, args, {encoding: 'utf8', input: stdin}); + + // stderr should include '[stdin]' as the filename + assert(c.stderr.startsWith('[stdin]'), "stderr doesn't start with [stdin]"); + + // no stdout or stderr should be produced + assert.strictEqual(c.stdout, '', 'stdout produced'); + + // stderr should have a syntax error message + const match = c.stderr.match(/^SyntaxError: Unexpected identifier$/m); + assert(match, 'stderr incorrect'); + + assert.strictEqual(c.status, 1, 'code === ' + c.status); +}); |