Browse Source

Fix test-repl

v0.7.4-release
Ryan Dahl 15 years ago
parent
commit
a6942b345d
  1. 2
      lib/repl.js
  2. 31
      test/simple/test-repl.js

2
lib/repl.js

@ -43,7 +43,7 @@ function REPLServer(prompt, stream) {
self.buffered_cmd = ''; self.buffered_cmd = '';
self.stream = stream || process.openStdin(); self.stream = stream || process.openStdin();
self.prompt = "node> " || prompt; self.prompt = prompt || "node> ";
var isTTY = (self.stream.fd < 3); var isTTY = (self.stream.fd < 3);
var rli = self.rli = rl.createInterface(self.stream, isTTY); var rli = self.rli = rl.createInterface(self.stream, isTTY);

31
test/simple/test-repl.js

@ -1,4 +1,5 @@
require("../common"); require("../common");
var sys = require("sys"), var sys = require("sys"),
net = require("net"), net = require("net"),
repl = require("repl"), repl = require("repl"),
@ -8,7 +9,7 @@ var sys = require("sys"),
prompt_tcp = "node via TCP socket> ", prompt_tcp = "node via TCP socket> ",
server_tcp, server_unix, client_tcp, client_unix, timer; server_tcp, server_unix, client_tcp, client_unix, timer;
debug('repl test'); error('repl test');
// function for REPL to run // function for REPL to run
invoke_me = function (arg) { invoke_me = function (arg) {
@ -19,6 +20,8 @@ function send_expect(list) {
if (list.length > 0) { if (list.length > 0) {
var cur = list.shift(); var cur = list.shift();
error("sending " + JSON.stringify(cur.send));
cur.client.expect = cur.expect; cur.client.expect = cur.expect;
cur.client.list = list; cur.client.list = list;
if (cur.send.length > 0) { if (cur.send.length > 0) {
@ -50,14 +53,14 @@ function tcp_test() {
send_expect([ send_expect([
{ client: client_tcp, send: "", expect: prompt_tcp }, { client: client_tcp, send: "", expect: prompt_tcp },
{ client: client_tcp, send: "invoke_me(333)", expect: ('\'' + "invoked 333" + '\'\n' + prompt_tcp) }, { client: client_tcp, send: "invoke_me(333)\n", expect: ('\'' + "invoked 333" + '\'\n' + prompt_tcp) },
{ client: client_tcp, send: "a += 1", expect: ("12346" + '\n' + prompt_tcp) } { client: client_tcp, send: "a += 1\n", expect: ("12346" + '\n' + prompt_tcp) }
]); ]);
}); });
client_tcp.addListener('data', function (data) { client_tcp.addListener('data', function (data) {
read_buffer += data.asciiSlice(0, data.length); read_buffer += data.asciiSlice(0, data.length);
sys.puts("TCP data: " + read_buffer + ", expecting " + client_tcp.expect); error("TCP data: " + JSON.stringify(read_buffer) + ", expecting " + JSON.stringify(client_tcp.expect));
if (read_buffer.indexOf(prompt_tcp) !== -1) { if (read_buffer.indexOf(prompt_tcp) !== -1) {
assert.strictEqual(client_tcp.expect, read_buffer); assert.strictEqual(client_tcp.expect, read_buffer);
read_buffer = ""; read_buffer = "";
@ -65,14 +68,14 @@ function tcp_test() {
send_expect(client_tcp.list); send_expect(client_tcp.list);
} }
else { else {
sys.puts("End of TCP test."); error("End of TCP test.");
client_tcp.end(); client_tcp.end();
client_unix.end(); client_unix.end();
clearTimeout(timer); clearTimeout(timer);
} }
} }
else { else {
sys.puts("didn't see prompt yet, buffering"); error("didn't see prompt yet, buffering");
} }
}); });
@ -111,28 +114,28 @@ function unix_test() {
send_expect([ send_expect([
{ client: client_unix, send: "", expect: prompt_unix }, { client: client_unix, send: "", expect: prompt_unix },
{ client: client_unix, send: "message", expect: ('\'' + message + '\'\n' + prompt_unix) }, { client: client_unix, send: "message\n", expect: ('\'' + message + '\'\n' + prompt_unix) },
{ client: client_unix, send: "invoke_me(987)", expect: ('\'' + "invoked 987" + '\'\n' + prompt_unix) }, { client: client_unix, send: "invoke_me(987)\n", expect: ('\'' + "invoked 987" + '\'\n' + prompt_unix) },
{ client: client_unix, send: "a = 12345", expect: ("12345" + '\n' + prompt_unix) } { client: client_unix, send: "a = 12345\n", expect: ("12345" + '\n' + prompt_unix) }
]); ]);
}); });
client_unix.addListener('data', function (data) { client_unix.addListener('data', function (data) {
read_buffer += data.asciiSlice(0, data.length); read_buffer += data.asciiSlice(0, data.length);
sys.puts("Unix data: " + read_buffer + ", expecting " + client_unix.expect); error("Unix data: " + JSON.stringify(read_buffer) + ", expecting " + JSON.stringify(client_unix.expect));
if (read_buffer.indexOf(prompt_unix) !== -1) { if (read_buffer.indexOf(prompt_unix) !== -1) {
assert.strictEqual(client_unix.expect, read_buffer); assert.strictEqual(client_unix.expect, read_buffer);
error("match");
read_buffer = ""; read_buffer = "";
if (client_unix.list && client_unix.list.length > 0) { if (client_unix.list && client_unix.list.length > 0) {
send_expect(client_unix.list); send_expect(client_unix.list);
} } else {
else { error("End of Unix test, running TCP test.");
sys.puts("End of Unix test, running TCP test.");
tcp_test(); tcp_test();
} }
} }
else { else {
sys.puts("didn't see prompt yet, bufering."); error("didn't see prompt yet, bufering.");
} }
}); });

Loading…
Cancel
Save