Skip to content

Commit a6942b3

Browse files
committed
Fix test-repl
1 parent 09af242 commit a6942b3

2 files changed

Lines changed: 25 additions & 22 deletions

File tree

lib/repl.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ function REPLServer(prompt, stream) {
4343
self.buffered_cmd = '';
4444

4545
self.stream = stream || process.openStdin();
46-
self.prompt = "node> " || prompt;
46+
self.prompt = prompt || "node> ";
4747

4848
var isTTY = (self.stream.fd < 3);
4949
var rli = self.rli = rl.createInterface(self.stream, isTTY);

test/simple/test-repl.js

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
require("../common");
2+
23
var sys = require("sys"),
34
net = require("net"),
45
repl = require("repl"),
@@ -7,8 +8,8 @@ var sys = require("sys"),
78
prompt_unix = "node via Unix socket> ",
89
prompt_tcp = "node via TCP socket> ",
910
server_tcp, server_unix, client_tcp, client_unix, timer;
10-
11-
debug('repl test');
11+
12+
error('repl test');
1213

1314
// function for REPL to run
1415
invoke_me = function (arg) {
@@ -19,6 +20,8 @@ function send_expect(list) {
1920
if (list.length > 0) {
2021
var cur = list.shift();
2122

23+
error("sending " + JSON.stringify(cur.send));
24+
2225
cur.client.expect = cur.expect;
2326
cur.client.list = list;
2427
if (cur.send.length > 0) {
@@ -31,7 +34,7 @@ function tcp_test() {
3134
server_tcp = net.createServer(function (socket) {
3235
assert.strictEqual(server_tcp, socket.server);
3336
assert.strictEqual(server_tcp.type, 'tcp4');
34-
37+
3538
socket.addListener("end", function () {
3639
socket.end();
3740
});
@@ -41,7 +44,7 @@ function tcp_test() {
4144

4245
server_tcp.addListener('listening', function () {
4346
var read_buffer = "";
44-
47+
4548
client_tcp = net.createConnection(PORT);
4649

4750
client_tcp.addListener('connect', function () {
@@ -50,36 +53,36 @@ function tcp_test() {
5053

5154
send_expect([
5255
{ client: client_tcp, send: "", expect: prompt_tcp },
53-
{ client: client_tcp, send: "invoke_me(333)", expect: ('\'' + "invoked 333" + '\'\n' + prompt_tcp) },
54-
{ client: client_tcp, send: "a += 1", expect: ("12346" + '\n' + prompt_tcp) }
56+
{ client: client_tcp, send: "invoke_me(333)\n", expect: ('\'' + "invoked 333" + '\'\n' + prompt_tcp) },
57+
{ client: client_tcp, send: "a += 1\n", expect: ("12346" + '\n' + prompt_tcp) }
5558
]);
5659
});
5760

5861
client_tcp.addListener('data', function (data) {
5962
read_buffer += data.asciiSlice(0, data.length);
60-
sys.puts("TCP data: " + read_buffer + ", expecting " + client_tcp.expect);
63+
error("TCP data: " + JSON.stringify(read_buffer) + ", expecting " + JSON.stringify(client_tcp.expect));
6164
if (read_buffer.indexOf(prompt_tcp) !== -1) {
6265
assert.strictEqual(client_tcp.expect, read_buffer);
6366
read_buffer = "";
6467
if (client_tcp.list && client_tcp.list.length > 0) {
6568
send_expect(client_tcp.list);
6669
}
6770
else {
68-
sys.puts("End of TCP test.");
71+
error("End of TCP test.");
6972
client_tcp.end();
7073
client_unix.end();
7174
clearTimeout(timer);
7275
}
7376
}
7477
else {
75-
sys.puts("didn't see prompt yet, buffering");
78+
error("didn't see prompt yet, buffering");
7679
}
7780
});
78-
81+
7982
client_tcp.addListener("error", function (e) {
8083
throw e;
8184
});
82-
85+
8386
client_tcp.addListener("close", function () {
8487
server_tcp.close();
8588
});
@@ -102,7 +105,7 @@ function unix_test() {
102105

103106
server_unix.addListener('listening', function () {
104107
var read_buffer = "";
105-
108+
106109
client_unix = net.createConnection(unix_socket_path);
107110

108111
client_unix.addListener('connect', function () {
@@ -111,31 +114,31 @@ function unix_test() {
111114

112115
send_expect([
113116
{ client: client_unix, send: "", expect: prompt_unix },
114-
{ client: client_unix, send: "message", expect: ('\'' + message + '\'\n' + prompt_unix) },
115-
{ client: client_unix, send: "invoke_me(987)", expect: ('\'' + "invoked 987" + '\'\n' + prompt_unix) },
116-
{ client: client_unix, send: "a = 12345", expect: ("12345" + '\n' + prompt_unix) }
117+
{ client: client_unix, send: "message\n", expect: ('\'' + message + '\'\n' + prompt_unix) },
118+
{ client: client_unix, send: "invoke_me(987)\n", expect: ('\'' + "invoked 987" + '\'\n' + prompt_unix) },
119+
{ client: client_unix, send: "a = 12345\n", expect: ("12345" + '\n' + prompt_unix) }
117120
]);
118121
});
119122

120123
client_unix.addListener('data', function (data) {
121124
read_buffer += data.asciiSlice(0, data.length);
122-
sys.puts("Unix data: " + read_buffer + ", expecting " + client_unix.expect);
125+
error("Unix data: " + JSON.stringify(read_buffer) + ", expecting " + JSON.stringify(client_unix.expect));
123126
if (read_buffer.indexOf(prompt_unix) !== -1) {
124127
assert.strictEqual(client_unix.expect, read_buffer);
128+
error("match");
125129
read_buffer = "";
126130
if (client_unix.list && client_unix.list.length > 0) {
127131
send_expect(client_unix.list);
128-
}
129-
else {
130-
sys.puts("End of Unix test, running TCP test.");
132+
} else {
133+
error("End of Unix test, running TCP test.");
131134
tcp_test();
132135
}
133136
}
134137
else {
135-
sys.puts("didn't see prompt yet, bufering.");
138+
error("didn't see prompt yet, bufering.");
136139
}
137140
});
138-
141+
139142
client_unix.addListener("error", function (e) {
140143
throw e;
141144
});

0 commit comments

Comments
 (0)