diff options
author | Marco Rogers <marco.rogers@gmail.com> | 2010-11-21 02:44:58 +0300 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2010-11-21 07:36:14 +0300 |
commit | 118b88e44fc8119a32ba1d7e6507e0f9eece70e6 (patch) | |
tree | f63f059866388398d78cd6091b7f3fa38fe44c73 /test | |
parent | 56074d1056a4e4b7a9954f18805605d79b0a5c3a (diff) |
update repl to distinguish JSON.parse SyntaxErrors from the rest
Diffstat (limited to 'test')
-rw-r--r-- | test/simple/test-repl.js | 72 |
1 files changed, 65 insertions, 7 deletions
diff --git a/test/simple/test-repl.js b/test/simple/test-repl.js index 6db7c01c35f..d2465087219 100644 --- a/test/simple/test-repl.js +++ b/test/simple/test-repl.js @@ -7,6 +7,7 @@ var net = require("net"), unix_socket_path = "/tmp/node-repl-sock", prompt_unix = "node via Unix socket> ", prompt_tcp = "node via TCP socket> ", + prompt_multiline = "... ", server_tcp, server_unix, client_tcp, client_unix, timer; // absolute path to test/fixtures/a.js @@ -33,6 +34,63 @@ function send_expect(list) { } } +function clean_up() { + client_tcp.end(); + client_unix.end(); + clearTimeout(timer); +} + +function error_test() { + // The other stuff is done so reuse unix socket + var read_buffer = ""; + client_unix.removeAllListeners('data'); + + client_unix.addListener('data', function (data) { + read_buffer += data.toString('ascii', 0, data.length); + common.error("Unix data: " + JSON.stringify(read_buffer) + ", expecting " + + (client_unix.expect.exec ? client_unix.expect : JSON.stringify(client_unix.expect))); + if (read_buffer.indexOf(prompt_unix) !== -1) { + assert.ok(read_buffer.match(client_unix.expect)); + common.error("match"); + read_buffer = ""; + if (client_unix.list && client_unix.list.length > 0) { + send_expect(client_unix.list); + } else { + common.error("End of Error test, running TCP test."); + tcp_test(); + } + } + else if(read_buffer === prompt_multiline) { + // Check that you meant to send a multiline test + assert.strictEqual(prompt_multiline, client_unix.expect); + read_buffer = ""; + if (client_unix.list && client_unix.list.length > 0) { + send_expect(client_unix.list); + } else { + common.error("End of Error test, running TCP test.\n"); + tcp_test(); + } + } + else { + common.error("didn't see prompt yet, buffering."); + } + }); + + send_expect([ + // Uncaught error throws and prints out + { client: client_unix, send: "throw new Error('test error');", expect: /^Error: test error/ }, + // Common syntax error is treated as multiline command + { client: client_unix, send: "function test_func() {", expect: prompt_multiline }, + // You can recover with the .break command + { client: client_unix, send: ".break", expect: prompt_unix }, + // Can parse valid JSON + { client: client_unix, send: "JSON.parse('{\"valid\": \"json\"}');", expect: "{ valid: 'json' }"}, + // invalid input to JSON.parse error is special case of syntax error, should throw + { client: client_unix, send: "JSON.parse('{invalid: \\'json\\'}');", + expect: /^SyntaxError: Unexpected token ILLEGAL/ } + ]); +} + function tcp_test() { server_tcp = net.createServer(function (socket) { assert.strictEqual(server_tcp, socket.server); @@ -69,15 +127,14 @@ function tcp_test() { common.error("TCP data: " + JSON.stringify(read_buffer) + ", expecting " + JSON.stringify(client_tcp.expect)); if (read_buffer.indexOf(prompt_tcp) !== -1) { assert.strictEqual(client_tcp.expect, read_buffer); + common.error("match"); read_buffer = ""; if (client_tcp.list && client_tcp.list.length > 0) { send_expect(client_tcp.list); } else { - common.error("End of TCP test."); - client_tcp.end(); - client_unix.end(); - clearTimeout(timer); + common.error("End of TCP test.\n"); + clean_up(); } } else { @@ -135,12 +192,12 @@ function unix_test() { if (client_unix.list && client_unix.list.length > 0) { send_expect(client_unix.list); } else { - common.error("End of Unix test, running TCP test."); - tcp_test(); + common.error("End of Unix test, running Error test.\n"); + process.nextTick(error_test); } } else { - common.error("didn't see prompt yet, bufering."); + common.error("didn't see prompt yet, buffering."); } }); @@ -157,6 +214,7 @@ function unix_test() { } unix_test(); + timer = setTimeout(function () { assert.fail("Timeout"); }, 1000); |