Skip to content

Commit 37537d5

Browse files
committed
test: stdin error messages
1 parent f5c07b6 commit 37537d5

File tree

2 files changed

+116
-0
lines changed

2 files changed

+116
-0
lines changed

test/message/stdin_messages.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
2+
// Copyright Joyent, Inc. and other Node contributors.
3+
//
4+
// Permission is hereby granted, free of charge, to any person obtaining a
5+
// copy of this software and associated documentation files (the
6+
// "Software"), to deal in the Software without restriction, including
7+
// without limitation the rights to use, copy, modify, merge, publish,
8+
// distribute, sublicense, and/or sell copies of the Software, and to permit
9+
// persons to whom the Software is furnished to do so, subject to the
10+
// following conditions:
11+
//
12+
// The above copyright notice and this permission notice shall be included
13+
// in all copies or substantial portions of the Software.
14+
//
15+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16+
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17+
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
18+
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
19+
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20+
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21+
// USE OR OTHER DEALINGS IN THE SOFTWARE.
22+
23+
var common = require('../common');
24+
var assert = require('assert');
25+
26+
var spawn = require('child_process').spawn;
27+
28+
function run(cmd, strict, cb) {
29+
var args = [];
30+
if (strict) args.push('--use_strict');
31+
args.push('-p');
32+
var child = spawn(process.execPath, args);
33+
child.stdout.pipe(process.stdout);
34+
child.stderr.pipe(process.stdout);
35+
child.stdin.end(cmd);
36+
child.on('close', cb);
37+
}
38+
39+
var queue =
40+
[ 'with(this){__filename}',
41+
'42',
42+
'throw new Error("hello")',
43+
'var x = 100; y = x;',
44+
'var ______________________________________________; throw 10' ];
45+
46+
function go() {
47+
var c = queue.shift();
48+
if (!c) return console.log('done');
49+
run(c, false, function() {
50+
run(c, true, go);
51+
});
52+
}
53+
54+
go();

test/message/stdin_messages.out

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
[stdin]
2+
3+
[stdin]:1
4+
with(this){__filename}
5+
^^^^
6+
SyntaxError: Strict mode code may not include a with statement
7+
at Object.<anonymous> ([stdin]-wrapper:6:22)
8+
at Module._compile (module.js:449:26)
9+
at evalScript (node.js:282:25)
10+
at Socket.<anonymous> (node.js:152:11)
11+
at Socket.EventEmitter.emit (events.js:85:17)
12+
at Pipe.onread (net.js:424:51)
13+
42
14+
42
15+
16+
[stdin]:1
17+
throw new Error("hello")
18+
^
19+
Error: hello
20+
at [stdin]:1:7
21+
at Object.<anonymous> ([stdin]-wrapper:6:22)
22+
at Module._compile (module.js:449:26)
23+
at evalScript (node.js:282:25)
24+
at Socket.<anonymous> (node.js:152:11)
25+
at Socket.EventEmitter.emit (events.js:85:17)
26+
at Pipe.onread (net.js:424:51)
27+
28+
[stdin]:1
29+
throw new Error("hello")
30+
^
31+
Error: hello
32+
at [stdin]:1:7
33+
at Object.<anonymous> ([stdin]-wrapper:6:22)
34+
at Module._compile (module.js:449:26)
35+
at evalScript (node.js:282:25)
36+
at Socket.<anonymous> (node.js:152:11)
37+
at Socket.EventEmitter.emit (events.js:85:17)
38+
at Pipe.onread (net.js:424:51)
39+
100
40+
41+
[stdin]:1
42+
var x = 100; y = x;
43+
^
44+
ReferenceError: y is not defined
45+
at [stdin]:1:16
46+
at Object.<anonymous> ([stdin]-wrapper:6:22)
47+
at Module._compile (module.js:449:26)
48+
at evalScript (node.js:282:25)
49+
at Socket.<anonymous> (node.js:152:11)
50+
at Socket.EventEmitter.emit (events.js:85:17)
51+
at Pipe.onread (net.js:424:51)
52+
53+
[stdin]:1
54+
var ______________________________________________; throw 10
55+
^
56+
10
57+
58+
[stdin]:1
59+
var ______________________________________________; throw 10
60+
^
61+
10
62+
done

0 commit comments

Comments
 (0)