From 37537d5720a563cb63929a0f4014491467767874 Mon Sep 17 00:00:00 2001 From: isaacs Date: Thu, 2 Aug 2012 08:11:09 -0700 Subject: [PATCH] test: stdin error messages --- test/message/stdin_messages.js | 54 +++++++++++++++++++++++++++++++++++ test/message/stdin_messages.out | 62 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 116 insertions(+) create mode 100644 test/message/stdin_messages.js create mode 100644 test/message/stdin_messages.out diff --git a/test/message/stdin_messages.js b/test/message/stdin_messages.js new file mode 100644 index 0000000..b1eaf47 --- /dev/null +++ b/test/message/stdin_messages.js @@ -0,0 +1,54 @@ + +// Copyright Joyent, Inc. and other Node contributors. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to permit +// persons to whom the Software is furnished to do so, subject to the +// following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +// USE OR OTHER DEALINGS IN THE SOFTWARE. + +var common = require('../common'); +var assert = require('assert'); + +var spawn = require('child_process').spawn; + +function run(cmd, strict, cb) { + var args = []; + if (strict) args.push('--use_strict'); + args.push('-p'); + var child = spawn(process.execPath, args); + child.stdout.pipe(process.stdout); + child.stderr.pipe(process.stdout); + child.stdin.end(cmd); + child.on('close', cb); +} + +var queue = + [ 'with(this){__filename}', + '42', + 'throw new Error("hello")', + 'var x = 100; y = x;', + 'var ______________________________________________; throw 10' ]; + +function go() { + var c = queue.shift(); + if (!c) return console.log('done'); + run(c, false, function() { + run(c, true, go); + }); +} + +go(); diff --git a/test/message/stdin_messages.out b/test/message/stdin_messages.out new file mode 100644 index 0000000..acf9a23 --- /dev/null +++ b/test/message/stdin_messages.out @@ -0,0 +1,62 @@ +[stdin] + +[stdin]:1 +with(this){__filename} +^^^^ +SyntaxError: Strict mode code may not include a with statement + at Object. ([stdin]-wrapper:6:22) + at Module._compile (module.js:449:26) + at evalScript (node.js:282:25) + at Socket. (node.js:152:11) + at Socket.EventEmitter.emit (events.js:85:17) + at Pipe.onread (net.js:424:51) +42 +42 + +[stdin]:1 +throw new Error("hello") + ^ +Error: hello + at [stdin]:1:7 + at Object. ([stdin]-wrapper:6:22) + at Module._compile (module.js:449:26) + at evalScript (node.js:282:25) + at Socket. (node.js:152:11) + at Socket.EventEmitter.emit (events.js:85:17) + at Pipe.onread (net.js:424:51) + +[stdin]:1 +throw new Error("hello") + ^ +Error: hello + at [stdin]:1:7 + at Object. ([stdin]-wrapper:6:22) + at Module._compile (module.js:449:26) + at evalScript (node.js:282:25) + at Socket. (node.js:152:11) + at Socket.EventEmitter.emit (events.js:85:17) + at Pipe.onread (net.js:424:51) +100 + +[stdin]:1 +var x = 100; y = x; + ^ +ReferenceError: y is not defined + at [stdin]:1:16 + at Object. ([stdin]-wrapper:6:22) + at Module._compile (module.js:449:26) + at evalScript (node.js:282:25) + at Socket. (node.js:152:11) + at Socket.EventEmitter.emit (events.js:85:17) + at Pipe.onread (net.js:424:51) + +[stdin]:1 +var ______________________________________________; throw 10 + ^ +10 + +[stdin]:1 +var ______________________________________________; throw 10 + ^ +10 +done -- 2.7.4