summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorisaacs <i@izs.me>2012-07-28 14:00:27 -0700
committerisaacs <i@izs.me>2012-07-30 08:21:39 -0700
commitb3cf3f35fcf192c717e7a393fb984bf6f879d0cc (patch)
tree2272eb5e82f700ffd83afe2b167aab50d085f75a /test
parent72bc4dcda4cfa99ed064419e40d104bd1b2e0e25 (diff)
downloadnodejs-b3cf3f35fcf192c717e7a393fb984bf6f879d0cc.tar.gz
nodejs-b3cf3f35fcf192c717e7a393fb984bf6f879d0cc.tar.bz2
nodejs-b3cf3f35fcf192c717e7a393fb984bf6f879d0cc.zip
Report errors properly from --eval and stdin
Diffstat (limited to 'test')
-rw-r--r--test/message/eval_messages.js53
-rw-r--r--test/message/eval_messages.out58
-rw-r--r--test/simple/test-cli-eval.js13
3 files changed, 118 insertions, 6 deletions
diff --git a/test/message/eval_messages.js b/test/message/eval_messages.js
new file mode 100644
index 000000000..d03c0eb1b
--- /dev/null
+++ b/test/message/eval_messages.js
@@ -0,0 +1,53 @@
+
+// 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('-pe', cmd);
+ var child = spawn(process.execPath, args);
+ child.stdout.pipe(process.stdout);
+ child.stderr.pipe(process.stdout);
+ 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/eval_messages.out b/test/message/eval_messages.out
new file mode 100644
index 000000000..f56bbdbdd
--- /dev/null
+++ b/test/message/eval_messages.out
@@ -0,0 +1,58 @@
+[eval]
+
+[eval]:1
+with(this){__filename}
+^^^^
+SyntaxError: Strict mode code may not include a with statement
+ at Object.<anonymous> ([eval]-wrapper:6:22)
+ at Module._compile (module.js:449:26)
+ at evalScript (node.js:282:25)
+ at startup (node.js:76:7)
+ at node.js:623:3
+42
+42
+
+[eval]:1
+throw new Error("hello")
+ ^
+Error: hello
+ at [eval]:1:7
+ at Object.<anonymous> ([eval]-wrapper:6:22)
+ at Module._compile (module.js:449:26)
+ at evalScript (node.js:282:25)
+ at startup (node.js:76:7)
+ at node.js:623:3
+
+[eval]:1
+throw new Error("hello")
+ ^
+Error: hello
+ at [eval]:1:7
+ at Object.<anonymous> ([eval]-wrapper:6:22)
+ at Module._compile (module.js:449:26)
+ at evalScript (node.js:282:25)
+ at startup (node.js:76:7)
+ at node.js:623:3
+100
+
+[eval]:1
+var x = 100; y = x;
+ ^
+ReferenceError: y is not defined
+ at [eval]:1:16
+ at Object.<anonymous> ([eval]-wrapper:6:22)
+ at Module._compile (module.js:449:26)
+ at evalScript (node.js:282:25)
+ at startup (node.js:76:7)
+ at node.js:623:3
+
+[eval]:1
+var ______________________________________________; throw 10
+ ^
+10
+
+[eval]:1
+var ______________________________________________; throw 10
+ ^
+10
+done
diff --git a/test/simple/test-cli-eval.js b/test/simple/test-cli-eval.js
index b47cc141f..7e3e0cd6e 100644
--- a/test/simple/test-cli-eval.js
+++ b/test/simple/test-cli-eval.js
@@ -19,21 +19,22 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
+if (module.parent) {
+ // signal we've been loaded as a module
+ console.log('Loaded as a module, exiting with status code 42.');
+ process.exit(42);
+}
+
var common = require('../common.js'),
assert = require('assert'),
child = require('child_process'),
nodejs = '"' + process.execPath + '"';
+
// replace \ by / because windows uses backslashes in paths, but they're still
// interpreted as the escape character when put between quotes.
var filename = __filename.replace(/\\/g, '/');
-if (module.parent) {
- // signal we've been loaded as a module
- console.log('Loaded as a module, exiting with status code 42.');
- process.exit(42);
-}
-
// assert that nothing is written to stdout
child.exec(nodejs + ' --eval 42',
function(err, stdout, stderr) {