2015-05-19 13:00:06 +02:00
|
|
|
/* eslint-disable max-len, strict */
|
2010-12-04 15:20:34 -08:00
|
|
|
var common = require('../common');
|
|
|
|
var assert = require('assert');
|
2010-06-07 17:39:24 -07:00
|
|
|
|
2010-12-04 13:40:39 -08:00
|
|
|
common.globalCheck = false;
|
2015-10-06 21:12:45 -07:00
|
|
|
common.refreshTmpDir();
|
2010-12-04 13:40:39 -08:00
|
|
|
|
2016-01-13 21:42:45 +01:00
|
|
|
const net = require('net');
|
|
|
|
const repl = require('repl');
|
|
|
|
const message = 'Read, Eval, Print Loop';
|
|
|
|
const prompt_unix = 'node via Unix socket> ';
|
|
|
|
const prompt_tcp = 'node via TCP socket> ';
|
|
|
|
const prompt_multiline = '... ';
|
|
|
|
const prompt_npm = 'npm should be run outside of the ' +
|
|
|
|
'node repl, in your normal shell.\n' +
|
|
|
|
'(Press Control-D to exit.)\n';
|
|
|
|
const expect_npm = prompt_npm + prompt_unix;
|
2016-02-25 00:26:41 +05:30
|
|
|
var server_tcp, server_unix, client_tcp, client_unix, timer, replServer;
|
2010-06-07 17:39:24 -07:00
|
|
|
|
2011-08-09 16:06:32 -07:00
|
|
|
|
2010-09-19 11:20:25 -07:00
|
|
|
// absolute path to test/fixtures/a.js
|
2010-12-05 01:45:52 +03:00
|
|
|
var moduleFilename = require('path').join(common.fixturesDir, 'a');
|
2010-09-19 11:20:25 -07:00
|
|
|
|
2013-08-27 18:53:39 -07:00
|
|
|
console.error('repl test');
|
2010-04-11 16:13:32 -07:00
|
|
|
|
|
|
|
// function for REPL to run
|
2010-12-05 01:45:52 +03:00
|
|
|
invoke_me = function(arg) {
|
|
|
|
return 'invoked ' + arg;
|
2010-04-11 16:13:32 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
function send_expect(list) {
|
|
|
|
if (list.length > 0) {
|
|
|
|
var cur = list.shift();
|
|
|
|
|
2013-08-27 18:53:39 -07:00
|
|
|
console.error('sending ' + JSON.stringify(cur.send));
|
2010-06-07 17:39:24 -07:00
|
|
|
|
2010-04-11 16:13:32 -07:00
|
|
|
cur.client.expect = cur.expect;
|
|
|
|
cur.client.list = list;
|
|
|
|
if (cur.send.length > 0) {
|
2012-04-06 12:20:01 -07:00
|
|
|
cur.client.write(cur.send + '\n');
|
2010-04-11 16:13:32 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-20 18:44:58 -05:00
|
|
|
function clean_up() {
|
|
|
|
client_tcp.end();
|
|
|
|
client_unix.end();
|
|
|
|
clearTimeout(timer);
|
|
|
|
}
|
|
|
|
|
2016-02-25 00:26:41 +05:30
|
|
|
function strict_mode_error_test() {
|
|
|
|
send_expect([
|
|
|
|
{ client: client_unix, send: 'ref = 1',
|
|
|
|
expect: /^ReferenceError:\sref\sis\snot\sdefined\n\s+at\srepl:1:5/ },
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2010-11-20 18:44:58 -05:00
|
|
|
function error_test() {
|
2010-12-01 13:43:05 -08:00
|
|
|
// The other stuff is done so reuse unix socket
|
2010-12-05 01:45:52 +03:00
|
|
|
var read_buffer = '';
|
2016-02-25 00:26:41 +05:30
|
|
|
var run_strict_test = true;
|
2010-12-01 13:43:05 -08:00
|
|
|
client_unix.removeAllListeners('data');
|
|
|
|
|
2011-10-15 01:08:36 +02:00
|
|
|
client_unix.on('data', function(data) {
|
2010-12-01 13:43:05 -08:00
|
|
|
read_buffer += data.toString('ascii', 0, data.length);
|
2013-08-27 18:53:39 -07:00
|
|
|
console.error('Unix data: ' + JSON.stringify(read_buffer) + ', expecting ' +
|
2010-12-05 01:45:52 +03:00
|
|
|
(client_unix.expect.exec ?
|
|
|
|
client_unix.expect :
|
|
|
|
JSON.stringify(client_unix.expect)));
|
2010-12-01 13:43:05 -08:00
|
|
|
|
|
|
|
if (read_buffer.indexOf(prompt_unix) !== -1) {
|
2012-06-05 12:02:37 -07:00
|
|
|
// if it's an exact match, then don't do the regexp
|
|
|
|
if (read_buffer !== client_unix.expect) {
|
2014-07-01 21:35:35 +08:00
|
|
|
var expect = client_unix.expect;
|
|
|
|
if (expect === prompt_multiline)
|
|
|
|
expect = /[\.]{3} /;
|
|
|
|
assert.ok(read_buffer.match(expect));
|
2013-08-27 18:53:39 -07:00
|
|
|
console.error('match');
|
2012-06-05 12:02:37 -07:00
|
|
|
}
|
2010-12-05 01:45:52 +03:00
|
|
|
read_buffer = '';
|
2010-12-01 13:43:05 -08:00
|
|
|
if (client_unix.list && client_unix.list.length > 0) {
|
|
|
|
send_expect(client_unix.list);
|
2016-02-25 00:26:41 +05:30
|
|
|
} else if (run_strict_test) {
|
|
|
|
replServer.replMode = repl.REPL_MODE_STRICT;
|
|
|
|
run_strict_test = false;
|
|
|
|
strict_mode_error_test();
|
2010-12-01 13:43:05 -08:00
|
|
|
} else {
|
2013-08-27 18:53:39 -07:00
|
|
|
console.error('End of Error test, running TCP test.');
|
2010-12-01 13:43:05 -08:00
|
|
|
tcp_test();
|
|
|
|
}
|
2010-11-20 18:44:58 -05:00
|
|
|
|
2011-11-11 17:44:39 -08:00
|
|
|
} else if (read_buffer.indexOf(prompt_multiline) !== -1) {
|
2010-12-01 13:43:05 -08:00
|
|
|
// Check that you meant to send a multiline test
|
|
|
|
assert.strictEqual(prompt_multiline, client_unix.expect);
|
2010-12-05 01:45:52 +03:00
|
|
|
read_buffer = '';
|
2010-12-01 13:43:05 -08:00
|
|
|
if (client_unix.list && client_unix.list.length > 0) {
|
|
|
|
send_expect(client_unix.list);
|
2016-02-25 00:26:41 +05:30
|
|
|
} else if (run_strict_test) {
|
|
|
|
replServer.replMode = repl.REPL_MODE_STRICT;
|
|
|
|
run_strict_test = false;
|
|
|
|
strict_mode_error_test();
|
2010-12-01 13:43:05 -08:00
|
|
|
} else {
|
2013-08-27 18:53:39 -07:00
|
|
|
console.error('End of Error test, running TCP test.\n');
|
2010-12-01 13:43:05 -08:00
|
|
|
tcp_test();
|
|
|
|
}
|
2010-11-20 18:44:58 -05:00
|
|
|
|
2010-12-01 13:43:05 -08:00
|
|
|
} else {
|
2013-08-27 18:53:39 -07:00
|
|
|
console.error('didn\'t see prompt yet, buffering.');
|
2010-12-01 13:43:05 -08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
send_expect([
|
|
|
|
// Uncaught error throws and prints out
|
2010-12-05 01:45:52 +03:00
|
|
|
{ client: client_unix, send: 'throw new Error(\'test error\');',
|
|
|
|
expect: /^Error: test error/ },
|
2010-12-01 13:43:05 -08:00
|
|
|
// Common syntax error is treated as multiline command
|
2010-12-05 01:45:52 +03:00
|
|
|
{ client: client_unix, send: 'function test_func() {',
|
|
|
|
expect: prompt_multiline },
|
2010-12-01 13:43:05 -08:00
|
|
|
// You can recover with the .break command
|
2010-12-05 01:45:52 +03:00
|
|
|
{ client: client_unix, send: '.break',
|
|
|
|
expect: prompt_unix },
|
2013-08-27 18:53:39 -07:00
|
|
|
// But passing the same string to eval() should throw
|
|
|
|
{ client: client_unix, send: 'eval("function test_func() {")',
|
|
|
|
expect: /^SyntaxError: Unexpected end of input/ },
|
2015-01-19 13:42:05 +08:00
|
|
|
// Can handle multiline template literals
|
|
|
|
{ client: client_unix, send: '`io.js',
|
|
|
|
expect: prompt_multiline },
|
|
|
|
// Special REPL commands still available
|
|
|
|
{ client: client_unix, send: '.break',
|
|
|
|
expect: prompt_unix },
|
|
|
|
// Template expressions can cross lines
|
|
|
|
{ client: client_unix, send: '`io.js ${"1.0"',
|
|
|
|
expect: prompt_multiline },
|
|
|
|
{ client: client_unix, send: '+ ".2"}`',
|
|
|
|
expect: `'io.js 1.0.2'\n${prompt_unix}` },
|
2015-11-15 14:46:17 +00:00
|
|
|
// Dot prefix in multiline commands aren't treated as commands
|
|
|
|
{ client: client_unix, send: '("a"',
|
|
|
|
expect: prompt_multiline },
|
|
|
|
{ client: client_unix, send: '.charAt(0))',
|
|
|
|
expect: `'a'\n${prompt_unix}` },
|
2012-11-10 18:21:13 +01:00
|
|
|
// Floating point numbers are not interpreted as REPL commands.
|
|
|
|
{ client: client_unix, send: '.1234',
|
|
|
|
expect: '0.1234' },
|
2013-01-03 09:27:55 -05:00
|
|
|
// Floating point expressions are not interpreted as REPL commands
|
2013-07-10 09:48:55 +02:00
|
|
|
{ client: client_unix, send: '.1+.1',
|
2013-01-03 09:27:55 -05:00
|
|
|
expect: '0.2' },
|
2010-12-01 13:43:05 -08:00
|
|
|
// Can parse valid JSON
|
2010-12-05 01:45:52 +03:00
|
|
|
{ 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\\\'}\');',
|
2011-07-05 04:10:14 +09:00
|
|
|
expect: /^SyntaxError: Unexpected token i/ },
|
2012-10-01 11:36:06 -07:00
|
|
|
// end of input to JSON.parse error is special case of syntax error,
|
|
|
|
// should throw
|
2013-05-26 12:26:39 -04:00
|
|
|
{ client: client_unix, send: 'JSON.parse(\'066\');',
|
|
|
|
expect: /^SyntaxError: Unexpected number/ },
|
|
|
|
// should throw
|
2012-10-01 11:36:06 -07:00
|
|
|
{ client: client_unix, send: 'JSON.parse(\'{\');',
|
|
|
|
expect: /^SyntaxError: Unexpected end of input/ },
|
2012-09-21 18:46:16 -07:00
|
|
|
// invalid RegExps are a special case of syntax error,
|
|
|
|
// should throw
|
|
|
|
{ client: client_unix, send: '/(/;',
|
|
|
|
expect: /^SyntaxError: Invalid regular expression\:/ },
|
2012-09-30 22:43:35 -07:00
|
|
|
// invalid RegExp modifiers are a special case of syntax error,
|
|
|
|
// should throw (GH-4012)
|
|
|
|
{ client: client_unix, send: 'new RegExp("foo", "wrong modifier");',
|
|
|
|
expect: /^SyntaxError: Invalid flags supplied to RegExp constructor/ },
|
2013-03-30 13:10:30 -07:00
|
|
|
// strict mode syntax errors should be caught (GH-5178)
|
|
|
|
{ client: client_unix, send: '(function() { "use strict"; return 0755; })()',
|
|
|
|
expect: /^SyntaxError: Octal literals are not allowed in strict mode/ },
|
|
|
|
{ client: client_unix, send: '(function(a, a, b) { "use strict"; return a + b + c; })()',
|
2015-09-04 11:44:17 +02:00
|
|
|
expect: /^SyntaxError: Duplicate parameter name not allowed in this context/ },
|
2013-03-30 13:10:30 -07:00
|
|
|
{ client: client_unix, send: '(function() { "use strict"; with (this) {} })()',
|
|
|
|
expect: /^SyntaxError: Strict mode code may not include a with statement/ },
|
|
|
|
{ client: client_unix, send: '(function() { "use strict"; var x; delete x; })()',
|
|
|
|
expect: /^SyntaxError: Delete of an unqualified identifier in strict mode/ },
|
|
|
|
{ client: client_unix, send: '(function() { "use strict"; eval = 17; })()',
|
2014-03-13 20:38:14 +04:00
|
|
|
expect: /^SyntaxError: Unexpected eval or arguments in strict mode/ },
|
2015-01-07 19:16:21 +01:00
|
|
|
{ client: client_unix, send: '(function() { "use strict"; if (true) function f() { } })()',
|
2013-03-30 13:10:30 -07:00
|
|
|
expect: /^SyntaxError: In strict mode code, functions can only be declared at top level or immediately within another function/ },
|
2011-01-02 18:08:08 -08:00
|
|
|
// Named functions can be used:
|
|
|
|
{ client: client_unix, send: 'function blah() { return 1; }',
|
|
|
|
expect: prompt_unix },
|
|
|
|
{ client: client_unix, send: 'blah()',
|
2011-10-04 18:08:18 -04:00
|
|
|
expect: '1\n' + prompt_unix },
|
2012-02-18 00:18:11 +06:00
|
|
|
// Functions should not evaluate twice (#2773)
|
|
|
|
{ client: client_unix, send: 'var I = [1,2,3,function() {}]; I.pop()',
|
|
|
|
expect: '[Function]' },
|
2011-01-02 18:08:08 -08:00
|
|
|
// Multiline object
|
|
|
|
{ client: client_unix, send: '{ a: ',
|
|
|
|
expect: prompt_multiline },
|
|
|
|
{ client: client_unix, send: '1 }',
|
2011-10-04 18:08:18 -04:00
|
|
|
expect: '{ a: 1 }' },
|
2011-01-02 18:08:08 -08:00
|
|
|
// Multiline anonymous function with comment
|
2015-05-19 13:00:06 +02:00
|
|
|
{ client: client_unix, send: '(function() {',
|
2011-01-02 18:08:08 -08:00
|
|
|
expect: prompt_multiline },
|
|
|
|
{ client: client_unix, send: '// blah',
|
|
|
|
expect: prompt_multiline },
|
|
|
|
{ client: client_unix, send: 'return 1;',
|
|
|
|
expect: prompt_multiline },
|
|
|
|
{ client: client_unix, send: '})()',
|
2012-06-05 12:02:37 -07:00
|
|
|
expect: '1' },
|
2015-11-14 10:59:22 +00:00
|
|
|
// Multiline function call
|
|
|
|
{ client: client_unix, send: 'function f(){}; f(f(1,',
|
|
|
|
expect: prompt_multiline },
|
|
|
|
{ client: client_unix, send: '2)',
|
|
|
|
expect: prompt_multiline },
|
|
|
|
{ client: client_unix, send: ')',
|
|
|
|
expect: 'undefined\n' + prompt_unix },
|
2012-06-05 12:02:37 -07:00
|
|
|
// npm prompt error message
|
|
|
|
{ client: client_unix, send: 'npm install foobar',
|
2012-07-03 04:13:24 +02:00
|
|
|
expect: expect_npm },
|
2015-05-19 13:00:06 +02:00
|
|
|
{ client: client_unix, send: '(function() {\n\nreturn 1;\n})()',
|
2012-07-04 11:51:24 -07:00
|
|
|
expect: '1' },
|
|
|
|
{ client: client_unix, send: '{\n\na: 1\n}',
|
2013-01-12 12:07:06 -08:00
|
|
|
expect: '{ a: 1 }' },
|
|
|
|
{ client: client_unix, send: 'url.format("http://google.com")',
|
|
|
|
expect: 'http://google.com/' },
|
|
|
|
{ client: client_unix, send: 'var path = 42; path',
|
2015-07-12 00:53:39 +00:00
|
|
|
expect: '42' },
|
|
|
|
// this makes sure that we don't print `undefined` when we actually print
|
|
|
|
// the error message
|
|
|
|
{ client: client_unix, send: '.invalid_repl_command',
|
|
|
|
expect: 'Invalid REPL keyword\n' + prompt_unix },
|
2015-07-12 00:58:20 +00:00
|
|
|
// this makes sure that we don't crash when we use an inherited property as
|
|
|
|
// a REPL command
|
|
|
|
{ client: client_unix, send: '.toString',
|
|
|
|
expect: 'Invalid REPL keyword\n' + prompt_unix },
|
2015-07-12 01:22:33 +00:00
|
|
|
// fail when we are not inside a String and a line continuation is used
|
|
|
|
{ client: client_unix, send: '[] \\',
|
|
|
|
expect: /^SyntaxError: Unexpected token ILLEGAL/ },
|
|
|
|
// do not fail when a String is created with line continuation
|
|
|
|
{ client: client_unix, send: '\'the\\\nfourth\\\neye\'',
|
|
|
|
expect: prompt_multiline + prompt_multiline +
|
|
|
|
'\'thefourtheye\'\n' + prompt_unix },
|
|
|
|
// Don't fail when a partial String is created and line continuation is used
|
|
|
|
// with whitespace characters at the end of the string. We are to ignore it.
|
|
|
|
// This test is to make sure that we properly remove the whitespace
|
|
|
|
// characters at the end of line, unlike the buggy `trimWhitespace` function
|
|
|
|
{ client: client_unix, send: ' \t .break \t ',
|
|
|
|
expect: prompt_unix },
|
|
|
|
// multiline strings preserve whitespace characters in them
|
|
|
|
{ client: client_unix, send: '\'the \\\n fourth\t\t\\\n eye \'',
|
|
|
|
expect: prompt_multiline + prompt_multiline +
|
|
|
|
'\'the fourth\\t\\t eye \'\n' + prompt_unix },
|
|
|
|
// more than one multiline strings also should preserve whitespace chars
|
|
|
|
{ client: client_unix, send: '\'the \\\n fourth\' + \'\t\t\\\n eye \'',
|
|
|
|
expect: prompt_multiline + prompt_multiline +
|
|
|
|
'\'the fourth\\t\\t eye \'\n' + prompt_unix },
|
|
|
|
// using REPL commands within a string literal should still work
|
|
|
|
{ client: client_unix, send: '\'\\\n.break',
|
|
|
|
expect: prompt_unix },
|
|
|
|
// using REPL command "help" within a string literal should still work
|
|
|
|
{ client: client_unix, send: '\'thefourth\\\n.help\neye\'',
|
|
|
|
expect: /'thefourtheye'/ },
|
2015-07-12 21:48:50 +00:00
|
|
|
// empty lines in the REPL should be allowed
|
|
|
|
{ client: client_unix, send: '\n\r\n\r\n',
|
|
|
|
expect: prompt_unix + prompt_unix + prompt_unix },
|
|
|
|
// empty lines in the string literals should not affect the string
|
|
|
|
{ client: client_unix, send: '\'the\\\n\\\nfourtheye\'\n',
|
|
|
|
expect: prompt_multiline + prompt_multiline +
|
|
|
|
'\'thefourtheye\'\n' + prompt_unix },
|
2015-08-13 12:14:34 -04:00
|
|
|
// Regression test for https://github.com/nodejs/node/issues/597
|
2015-07-09 03:23:48 +05:30
|
|
|
{ client: client_unix,
|
|
|
|
send: '/(.)(.)(.)(.)(.)(.)(.)(.)(.)/.test(\'123456789\')\n',
|
|
|
|
expect: `true\n${prompt_unix}` },
|
|
|
|
// the following test's result depends on the RegEx's match from the above
|
|
|
|
{ client: client_unix,
|
|
|
|
send: 'RegExp.$1\nRegExp.$2\nRegExp.$3\nRegExp.$4\nRegExp.$5\n' +
|
|
|
|
'RegExp.$6\nRegExp.$7\nRegExp.$8\nRegExp.$9\n',
|
|
|
|
expect: ['\'1\'\n', '\'2\'\n', '\'3\'\n', '\'4\'\n', '\'5\'\n', '\'6\'\n',
|
|
|
|
'\'7\'\n', '\'8\'\n', '\'9\'\n'].join(`${prompt_unix}`) },
|
2015-09-20 16:07:21 +05:30
|
|
|
// regression tests for https://github.com/nodejs/node/issues/2749
|
|
|
|
{ client: client_unix, send: 'function x() {\nreturn \'\\n\';\n }',
|
|
|
|
expect: prompt_multiline + prompt_multiline +
|
|
|
|
'undefined\n' + prompt_unix },
|
|
|
|
{ client: client_unix, send: 'function x() {\nreturn \'\\\\\';\n }',
|
|
|
|
expect: prompt_multiline + prompt_multiline +
|
|
|
|
'undefined\n' + prompt_unix },
|
2015-10-24 13:16:08 +05:30
|
|
|
// regression tests for https://github.com/nodejs/node/issues/3421
|
|
|
|
{ client: client_unix, send: 'function x() {\n//\'\n }',
|
|
|
|
expect: prompt_multiline + prompt_multiline +
|
|
|
|
'undefined\n' + prompt_unix },
|
|
|
|
{ client: client_unix, send: 'function x() {\n//"\n }',
|
|
|
|
expect: prompt_multiline + prompt_multiline +
|
|
|
|
'undefined\n' + prompt_unix },
|
|
|
|
{ client: client_unix, send: 'function x() {//\'\n }',
|
|
|
|
expect: prompt_multiline + 'undefined\n' + prompt_unix },
|
|
|
|
{ client: client_unix, send: 'function x() {//"\n }',
|
|
|
|
expect: prompt_multiline + 'undefined\n' + prompt_unix },
|
|
|
|
{ client: client_unix, send: 'function x() {\nvar i = "\'";\n }',
|
|
|
|
expect: prompt_multiline + prompt_multiline +
|
|
|
|
'undefined\n' + prompt_unix },
|
|
|
|
{ client: client_unix, send: 'function x(/*optional*/) {}',
|
|
|
|
expect: 'undefined\n' + prompt_unix },
|
|
|
|
{ client: client_unix, send: 'function x(/* // 5 */) {}',
|
|
|
|
expect: 'undefined\n' + prompt_unix },
|
|
|
|
{ client: client_unix, send: '// /* 5 */',
|
|
|
|
expect: 'undefined\n' + prompt_unix },
|
|
|
|
{ client: client_unix, send: '"//"',
|
|
|
|
expect: '\'//\'\n' + prompt_unix },
|
|
|
|
{ client: client_unix, send: '"data /*with*/ comment"',
|
|
|
|
expect: '\'data /*with*/ comment\'\n' + prompt_unix },
|
|
|
|
{ client: client_unix, send: 'function x(/*fn\'s optional params*/) {}',
|
|
|
|
expect: 'undefined\n' + prompt_unix },
|
|
|
|
{ client: client_unix, send: '/* \'\n"\n\'"\'\n*/',
|
|
|
|
expect: 'undefined\n' + prompt_unix },
|
2015-11-25 22:27:29 +01:00
|
|
|
// REPL should get a normal require() function, not one that allows
|
|
|
|
// access to internal modules without the --expose_internals flag.
|
|
|
|
{ client: client_unix, send: 'require("internal/repl")',
|
|
|
|
expect: /^Error: Cannot find module 'internal\/repl'/ },
|
2016-02-06 12:14:27 +05:30
|
|
|
// REPL should handle quotes within regexp literal in multiline mode
|
|
|
|
{ client: client_unix, send: "function x(s) {\nreturn s.replace(/'/,'');\n}",
|
|
|
|
expect: prompt_multiline + prompt_multiline +
|
|
|
|
'undefined\n' + prompt_unix },
|
|
|
|
{ client: client_unix, send: "function x(s) {\nreturn s.replace(/\'/,'');\n}",
|
|
|
|
expect: prompt_multiline + prompt_multiline +
|
|
|
|
'undefined\n' + prompt_unix },
|
|
|
|
{ client: client_unix, send: 'function x(s) {\nreturn s.replace(/"/,"");\n}',
|
|
|
|
expect: prompt_multiline + prompt_multiline +
|
|
|
|
'undefined\n' + prompt_unix },
|
|
|
|
{ client: client_unix, send: 'function x(s) {\nreturn s.replace(/.*/,"");\n}',
|
|
|
|
expect: prompt_multiline + prompt_multiline +
|
|
|
|
'undefined\n' + prompt_unix },
|
2016-03-07 10:31:33 +05:30
|
|
|
{ client: client_unix, send: '{ var x = 4; }',
|
|
|
|
expect: 'undefined\n' + prompt_unix },
|
2010-12-01 13:43:05 -08:00
|
|
|
]);
|
2010-11-20 18:44:58 -05:00
|
|
|
}
|
|
|
|
|
2010-04-11 16:13:32 -07:00
|
|
|
function tcp_test() {
|
2010-12-05 01:45:52 +03:00
|
|
|
server_tcp = net.createServer(function(socket) {
|
2010-04-11 16:13:32 -07:00
|
|
|
assert.strictEqual(server_tcp, socket.server);
|
2010-06-07 17:39:24 -07:00
|
|
|
|
2011-10-15 01:08:36 +02:00
|
|
|
socket.on('end', function() {
|
2010-04-11 16:13:32 -07:00
|
|
|
socket.end();
|
|
|
|
});
|
|
|
|
|
|
|
|
repl.start(prompt_tcp, socket);
|
|
|
|
});
|
|
|
|
|
2010-12-05 01:45:52 +03:00
|
|
|
server_tcp.listen(common.PORT, function() {
|
|
|
|
var read_buffer = '';
|
2010-06-07 17:39:24 -07:00
|
|
|
|
2010-07-15 11:47:25 -07:00
|
|
|
client_tcp = net.createConnection(common.PORT);
|
2010-04-11 16:13:32 -07:00
|
|
|
|
2011-10-15 01:08:36 +02:00
|
|
|
client_tcp.on('connect', function() {
|
2010-04-11 16:13:32 -07:00
|
|
|
assert.equal(true, client_tcp.readable);
|
|
|
|
assert.equal(true, client_tcp.writable);
|
|
|
|
|
|
|
|
send_expect([
|
2010-12-05 22:15:30 +03:00
|
|
|
{ client: client_tcp, send: '',
|
|
|
|
expect: prompt_tcp },
|
2012-04-06 12:20:01 -07:00
|
|
|
{ client: client_tcp, send: 'invoke_me(333)',
|
2010-12-05 22:15:30 +03:00
|
|
|
expect: ('\'' + 'invoked 333' + '\'\n' + prompt_tcp) },
|
2012-04-06 12:20:01 -07:00
|
|
|
{ client: client_tcp, send: 'a += 1',
|
2010-12-05 22:15:30 +03:00
|
|
|
expect: ('12346' + '\n' + prompt_tcp) },
|
|
|
|
{ client: client_tcp,
|
2012-04-06 12:20:01 -07:00
|
|
|
send: 'require(' + JSON.stringify(moduleFilename) + ').number',
|
2010-12-05 22:15:30 +03:00
|
|
|
expect: ('42' + '\n' + prompt_tcp) }
|
|
|
|
]);
|
2010-04-11 16:13:32 -07:00
|
|
|
});
|
|
|
|
|
2011-10-15 01:08:36 +02:00
|
|
|
client_tcp.on('data', function(data) {
|
2010-09-06 12:12:36 -07:00
|
|
|
read_buffer += data.toString('ascii', 0, data.length);
|
2013-08-27 18:53:39 -07:00
|
|
|
console.error('TCP data: ' + JSON.stringify(read_buffer) +
|
2010-12-05 01:45:52 +03:00
|
|
|
', expecting ' + JSON.stringify(client_tcp.expect));
|
2010-04-12 14:29:49 -07:00
|
|
|
if (read_buffer.indexOf(prompt_tcp) !== -1) {
|
|
|
|
assert.strictEqual(client_tcp.expect, read_buffer);
|
2013-08-27 18:53:39 -07:00
|
|
|
console.error('match');
|
2010-12-05 01:45:52 +03:00
|
|
|
read_buffer = '';
|
2010-04-12 14:29:49 -07:00
|
|
|
if (client_tcp.list && client_tcp.list.length > 0) {
|
|
|
|
send_expect(client_tcp.list);
|
2010-12-01 13:43:05 -08:00
|
|
|
} else {
|
2013-08-27 18:53:39 -07:00
|
|
|
console.error('End of TCP test.\n');
|
2010-11-20 18:44:58 -05:00
|
|
|
clean_up();
|
2010-04-12 14:29:49 -07:00
|
|
|
}
|
2010-12-01 13:43:05 -08:00
|
|
|
} else {
|
2013-08-27 18:53:39 -07:00
|
|
|
console.error('didn\'t see prompt yet, buffering');
|
2010-04-11 16:13:32 -07:00
|
|
|
}
|
|
|
|
});
|
2010-06-07 17:39:24 -07:00
|
|
|
|
2011-10-15 01:08:36 +02:00
|
|
|
client_tcp.on('error', function(e) {
|
2010-04-11 16:13:32 -07:00
|
|
|
throw e;
|
|
|
|
});
|
2010-06-07 17:39:24 -07:00
|
|
|
|
2011-10-15 01:08:36 +02:00
|
|
|
client_tcp.on('close', function() {
|
2010-04-11 16:13:32 -07:00
|
|
|
server_tcp.close();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function unix_test() {
|
2010-12-05 01:45:52 +03:00
|
|
|
server_unix = net.createServer(function(socket) {
|
2010-04-11 16:13:32 -07:00
|
|
|
assert.strictEqual(server_unix, socket.server);
|
|
|
|
|
2011-10-15 01:08:36 +02:00
|
|
|
socket.on('end', function() {
|
2010-04-11 16:13:32 -07:00
|
|
|
socket.end();
|
|
|
|
});
|
|
|
|
|
2016-02-25 00:26:41 +05:30
|
|
|
replServer = repl.start({
|
2012-10-12 16:34:36 -07:00
|
|
|
prompt: prompt_unix,
|
|
|
|
input: socket,
|
|
|
|
output: socket,
|
|
|
|
useGlobal: true
|
2016-02-25 00:26:41 +05:30
|
|
|
});
|
|
|
|
replServer.context.message = message;
|
2010-04-11 16:13:32 -07:00
|
|
|
});
|
|
|
|
|
2011-10-15 01:08:36 +02:00
|
|
|
server_unix.on('listening', function() {
|
2010-12-05 01:45:52 +03:00
|
|
|
var read_buffer = '';
|
2010-06-07 17:39:24 -07:00
|
|
|
|
2011-08-09 16:06:32 -07:00
|
|
|
client_unix = net.createConnection(common.PIPE);
|
2010-04-11 16:13:32 -07:00
|
|
|
|
2011-10-15 01:08:36 +02:00
|
|
|
client_unix.on('connect', function() {
|
2010-04-11 16:13:32 -07:00
|
|
|
assert.equal(true, client_unix.readable);
|
|
|
|
assert.equal(true, client_unix.writable);
|
|
|
|
|
|
|
|
send_expect([
|
2010-12-05 22:15:30 +03:00
|
|
|
{ client: client_unix, send: '',
|
|
|
|
expect: prompt_unix },
|
2012-04-06 12:20:01 -07:00
|
|
|
{ client: client_unix, send: 'message',
|
2010-12-05 22:15:30 +03:00
|
|
|
expect: ('\'' + message + '\'\n' + prompt_unix) },
|
2012-04-06 12:20:01 -07:00
|
|
|
{ client: client_unix, send: 'invoke_me(987)',
|
2010-12-05 22:15:30 +03:00
|
|
|
expect: ('\'' + 'invoked 987' + '\'\n' + prompt_unix) },
|
2012-04-06 12:20:01 -07:00
|
|
|
{ client: client_unix, send: 'a = 12345',
|
2011-01-01 21:14:06 -08:00
|
|
|
expect: ('12345' + '\n' + prompt_unix) },
|
2012-04-06 12:20:01 -07:00
|
|
|
{ client: client_unix, send: '{a:1}',
|
2011-10-04 18:08:18 -04:00
|
|
|
expect: ('{ a: 1 }' + '\n' + prompt_unix) }
|
2010-12-05 22:15:30 +03:00
|
|
|
]);
|
2010-04-11 16:13:32 -07:00
|
|
|
});
|
|
|
|
|
2011-10-15 01:08:36 +02:00
|
|
|
client_unix.on('data', function(data) {
|
2010-09-06 12:12:36 -07:00
|
|
|
read_buffer += data.toString('ascii', 0, data.length);
|
2013-08-27 18:53:39 -07:00
|
|
|
console.error('Unix data: ' + JSON.stringify(read_buffer) +
|
2010-12-05 01:45:52 +03:00
|
|
|
', expecting ' + JSON.stringify(client_unix.expect));
|
2010-04-12 14:29:49 -07:00
|
|
|
if (read_buffer.indexOf(prompt_unix) !== -1) {
|
|
|
|
assert.strictEqual(client_unix.expect, read_buffer);
|
2013-08-27 18:53:39 -07:00
|
|
|
console.error('match');
|
2010-12-05 01:45:52 +03:00
|
|
|
read_buffer = '';
|
2010-04-12 14:29:49 -07:00
|
|
|
if (client_unix.list && client_unix.list.length > 0) {
|
|
|
|
send_expect(client_unix.list);
|
2010-06-07 17:39:24 -07:00
|
|
|
} else {
|
2013-08-27 18:53:39 -07:00
|
|
|
console.error('End of Unix test, running Error test.\n');
|
2010-11-20 18:44:58 -05:00
|
|
|
process.nextTick(error_test);
|
2010-04-12 14:29:49 -07:00
|
|
|
}
|
2010-12-01 13:43:05 -08:00
|
|
|
} else {
|
2013-08-27 18:53:39 -07:00
|
|
|
console.error('didn\'t see prompt yet, buffering.');
|
2010-04-11 16:13:32 -07:00
|
|
|
}
|
|
|
|
});
|
2010-06-07 17:39:24 -07:00
|
|
|
|
2011-10-15 01:08:36 +02:00
|
|
|
client_unix.on('error', function(e) {
|
2010-04-11 16:13:32 -07:00
|
|
|
throw e;
|
|
|
|
});
|
|
|
|
|
2011-10-15 01:08:36 +02:00
|
|
|
client_unix.on('close', function() {
|
2010-04-11 16:13:32 -07:00
|
|
|
server_unix.close();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2011-08-09 16:06:32 -07:00
|
|
|
server_unix.listen(common.PIPE);
|
2010-04-11 16:13:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
unix_test();
|
2010-11-20 18:44:58 -05:00
|
|
|
|
2010-12-05 01:45:52 +03:00
|
|
|
timer = setTimeout(function() {
|
2015-10-14 21:22:55 -07:00
|
|
|
assert.fail(null, null, 'Timeout');
|
2011-01-25 17:35:06 -08:00
|
|
|
}, 5000);
|