Add test-repl.js unit test.

Reviewed-by: asquare
This commit is contained in:
Kinsley Wong 2013-12-10 12:17:26 -08:00
parent 8a2eb3d13c
commit 7a056120f5
4 changed files with 78 additions and 2 deletions

View File

@ -310,6 +310,7 @@
<apply-diff src="test/simple" mod="${test.dir}/simple" name="test-pipe-head.js"/>
<apply-diff src="test/simple" mod="${test.dir}/simple" name="test-pipe-unref.js"/>
<apply-diff src="test/simple" mod="${test.dir}/simple" name="test-readline-interface.js"/>
<apply-diff src="test/simple" mod="${test.dir}/simple" name="test-repl.js"/>
<apply-diff src="test/simple" mod="${test.dir}/simple" name="test-repl-tab-complete.js"/>
<apply-diff src="test/simple" mod="${test.dir}/simple" name="test-script-context.js"/>
<apply-diff src="test/simple" mod="${test.dir}/simple" name="test-stream2-push.js"/>
@ -389,6 +390,7 @@
<apply-patch-file target="${test.dir}/simple" dir="test/simple" name="test-pipe-head.js"/>
<apply-patch-file target="${test.dir}/simple" dir="test/simple" name="test-pipe-unref.js"/>
<apply-patch-file target="${test.dir}/simple" dir="test/simple" name="test-readline-interface.js"/>
<apply-patch-file target="${test.dir}/simple" dir="test/simple" name="test-repl.js"/>
<apply-patch-file target="${test.dir}/simple" dir="test/simple" name="test-repl-tab-complete.js"/>
<apply-patch-file target="${test.dir}/simple" dir="test/simple" name="test-script-context.js"/>
<apply-patch-file target="${test.dir}/simple" dir="test/simple" name="test-stream2-push.js"/>

View File

@ -1,5 +1,5 @@
--- ../nodejs/lib/repl.js 2013-12-06 14:29:56.315446400 -0800
+++ src/main/js/lib/repl.js 2013-12-06 14:41:35.670447200 -0800
--- ../nodejs/lib/repl.js 2013-12-09 18:56:15.294402800 -0800
+++ src/main/js/lib/repl.js 2013-12-10 11:23:45.938789000 -0800
@@ -535,7 +535,7 @@
// Get global vars synchronously
if (this.useGlobal ||
@ -9,3 +9,10 @@
var contextProto = this.context;
while (contextProto = Object.getPrototypeOf(contextProto)) {
completionGroups.push(Object.getOwnPropertyNames(contextProto));
@@ -923,5 +923,5 @@
// "strict mode" syntax errors
!e.match(/^SyntaxError: .*strict mode.*/i) &&
// JSON.parse() error
- !e.match(/\n {4}at Object.parse \(native\)\n/);
+ !e.match(/^SyntaxError: Invalid JSON/);
}

View File

@ -0,0 +1,66 @@
--- ../nodejs/test/simple/test-repl.js 2013-12-10 12:00:28.170682600 -0800
+++ test/simple/test-repl.js 2013-12-10 12:08:06.413349900 -0800
@@ -131,40 +131,42 @@
// 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 i/ },
+ expect: /^SyntaxError: Invalid JSON/ },
// end of input to JSON.parse error is special case of syntax error,
// should throw
{ client: client_unix, send: 'JSON.parse(\'066\');',
- expect: /^SyntaxError: Unexpected number/ },
+ expect: /^SyntaxError: Invalid JSON/ },
// should throw
{ client: client_unix, send: 'JSON.parse(\'{\');',
- expect: /^SyntaxError: Unexpected end of input/ },
- // invalid RegExps are a special case of syntax error,
- // should throw
- { client: client_unix, send: '/(/;',
- expect: /^SyntaxError: Invalid regular expression\:/ },
- // 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/ },
- // strict mode syntax errors should be caught (GH-5178)
+ expect: /^SyntaxError: Invalid JSON/ },
+// RegExps errors show up as regular SyntaxErrors on Nashorn. Disable for now until we can
+// identify real SyntaxError from regular expression SyntaxErrors
+// // invalid RegExps are a special case of syntax error,
+// // should throw
+// { client: client_unix, send: '/(/;',
+// expect: /^SyntaxError: Invalid regular expression\:/ },
+// // 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/ },
+// // 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() { "use strict"; return { p: 1, p: 2 }; })()',
- expect: /^SyntaxError: Duplicate data property in object literal not allowed in strict mode/ },
+ expect: /^SyntaxError: repl:1:36 cannot use octal value in strict mode/ },
+// { client: client_unix, send: '(function() { "use strict"; return { p: 1, p: 2 }; })()',
+// expect: /^SyntaxError: Assignment to eval or arguments is not allowed in strict mode/ },
{ client: client_unix, send: '(function(a, a, b) { "use strict"; return a + b + c; })()',
- expect: /^SyntaxError: Strict mode function may not have duplicate parameter names/ },
+ expect: /^SyntaxError: repl:1:11 strict mode function cannot have duplicate parameter name "a"/ },
{ client: client_unix, send: '(function() { "use strict"; with (this) {} })()',
- expect: /^SyntaxError: Strict mode code may not include a with statement/ },
+ expect: /^SyntaxError: repl:1:29 "with" statement cannot be used in strict mode/ },
{ client: client_unix, send: '(function() { "use strict"; var x; delete x; })()',
- expect: /^SyntaxError: Delete of an unqualified identifier in strict mode/ },
+ expect: /^SyntaxError: cannot delete "x" in strict mode/ },
{ client: client_unix, send: '(function() { "use strict"; eval = 17; })()',
- expect: /^SyntaxError: Assignment to eval or arguments is not allowed in strict mode/ },
+ expect: /^SyntaxError: repl:1:29 "eval" cannot be used as assignment in strict mode/ },
{ client: client_unix, send: '(function() { "use strict"; if (true){ function f() { } } })()',
- expect: /^SyntaxError: In strict mode code, functions can only be declared at top level or immediately within another function/ },
+ expect: /^SyntaxError: repl:1:40 In strict mode, function declarations can only occur at program or function body level. You should use a function expression here instead./ },
// Named functions can be used:
{ client: client_unix, send: 'function blah() { return 1; }',
- expect: prompt_unix },
+ expect: '[Function: blah]\n' + prompt_unix },
{ client: client_unix, send: 'blah()',
expect: '1\n' + prompt_unix },
// Functions should not evaluate twice (#2773)

View File

@ -455,6 +455,7 @@ source.test.simple.list = \
test-regress-GH-877.js \
test-regress-GH-897.js \
test-regression-object-prototype.js \
test-repl.js \
test-repl-.save.load.js \
test-repl-autolibs.js \
test-repl-console.js \