From: Dmitry Volyntsev Date: Thu, 27 Jan 2022 13:01:55 +0000 (+0000) Subject: Tests: refactored modules tests using test262 test suite. X-Git-Tag: 0.7.3~13 X-Git-Url: http://www.kaiwu.me/postgresql/commit/?a=commitdiff_plain;h=7bd570b39297d3d91902c93a624c89b08be7a6fe;p=njs.git Tests: refactored modules tests using test262 test suite. --- diff --git a/auto/expect b/auto/expect index 1bb03251..db9bb859 100644 --- a/auto/expect +++ b/auto/expect @@ -20,9 +20,9 @@ fi if [ $njs_found = yes -a $NJS_HAVE_READLINE = YES ]; then cat << END >> $NJS_MAKEFILE -expect_test: njs test/njs_expect_test.exp +shell_test: njs test/shell_test.exp INPUTRC=test/inputrc PATH=$NJS_BUILD_DIR:\$(PATH) \ - expect -f test/njs_expect_test.exp + expect -f test/shell_test.exp END else @@ -30,7 +30,7 @@ else cat << END >> $NJS_MAKEFILE -expect_test: +shell_test: @echo "Skipping expect tests" END diff --git a/auto/make b/auto/make index 6fa45404..14263c1f 100644 --- a/auto/make +++ b/auto/make @@ -249,7 +249,7 @@ unit_test: $NJS_BUILD_DIR/njs_auto_config.h \\ $NJS_BUILD_DIR/njs_unit_test -test: expect_test unit_test test262 +test: shell_test unit_test test262 benchmark: $NJS_BUILD_DIR/njs_auto_config.h \\ $NJS_BUILD_DIR/njs_benchmark diff --git a/test/js/import_declaration_exception.t.js b/test/js/import_declaration_exception.t.js new file mode 100644 index 00000000..521cc005 --- /dev/null +++ b/test/js/import_declaration_exception.t.js @@ -0,0 +1,9 @@ +/*--- +includes: [] +flags: [] +paths: [test/js/module, test/js/module/libs] +negative: + phase: runtime +---*/ + +import m from 'declaration_exception.js'; diff --git a/test/js/import_exception.t.js b/test/js/import_exception.t.js new file mode 100644 index 00000000..343cb24a --- /dev/null +++ b/test/js/import_exception.t.js @@ -0,0 +1,11 @@ +/*--- +includes: [] +flags: [] +paths: [test/js/module, test/js/module/libs] +negative: + phase: runtime +---*/ + +import lib from 'lib3.js'; + +lib.exception(); diff --git a/test/js/import_export_comma_expression.t.js b/test/js/import_export_comma_expression.t.js new file mode 100644 index 00000000..185d3a6d --- /dev/null +++ b/test/js/import_export_comma_expression.t.js @@ -0,0 +1,9 @@ +/*--- +includes: [] +flags: [] +paths: [test/js/module] +---*/ + +import m from 'export_comma_expression.js'; + +assert.sameValue(m.prod(3,5), 15); diff --git a/test/js/import_export_empty.t.js b/test/js/import_export_empty.t.js new file mode 100644 index 00000000..cf6ec367 --- /dev/null +++ b/test/js/import_export_empty.t.js @@ -0,0 +1,9 @@ +/*--- +includes: [] +flags: [] +paths: [test/js/module, test/js/module/libs] +negative: + phase: runtime +---*/ + +import m from 'empty.js'; diff --git a/test/js/import_export_expression.t.js b/test/js/import_export_expression.t.js new file mode 100644 index 00000000..bf6fd5fb --- /dev/null +++ b/test/js/import_export_expression.t.js @@ -0,0 +1,9 @@ +/*--- +includes: [] +flags: [] +paths: [test/js/module] +---*/ + +import m from 'export_expression.js'; + +assert.sameValue(m.sum(3,4), 7); diff --git a/test/js/import_export_multi_default.t.js b/test/js/import_export_multi_default.t.js new file mode 100644 index 00000000..1e4cf08a --- /dev/null +++ b/test/js/import_export_multi_default.t.js @@ -0,0 +1,9 @@ +/*--- +includes: [] +flags: [] +paths: [test/js/module, test/js/module/libs] +negative: + phase: runtime +---*/ + +import m from 'export.js'; diff --git a/test/js/import_export_non_assignment.t.js b/test/js/import_export_non_assignment.t.js new file mode 100644 index 00000000..f8d6361a --- /dev/null +++ b/test/js/import_export_non_assignment.t.js @@ -0,0 +1,9 @@ +/*--- +includes: [] +flags: [] +paths: [test/js/module, test/js/module/libs] +negative: + phase: runtime +---*/ + +import m from 'export_non_assignment.js'; diff --git a/test/js/import_export_non_default.t.js b/test/js/import_export_non_default.t.js new file mode 100644 index 00000000..6b53010f --- /dev/null +++ b/test/js/import_export_non_default.t.js @@ -0,0 +1,9 @@ +/*--- +includes: [] +flags: [] +paths: [test/js/module, test/js/module/libs] +negative: + phase: runtime +---*/ + +import m from 'export_non_default.js'; diff --git a/test/js/import_export_object.t.js b/test/js/import_export_object.t.js new file mode 100644 index 00000000..d430742d --- /dev/null +++ b/test/js/import_export_object.t.js @@ -0,0 +1,9 @@ +/*--- +includes: [] +flags: [] +paths: [test/js/module] +---*/ + +import m from 'export_name.js'; + +assert.sameValue(m.prod(3,4), 12); diff --git a/test/js/import_export_ref_exception.t.js b/test/js/import_export_ref_exception.t.js new file mode 100644 index 00000000..654933a0 --- /dev/null +++ b/test/js/import_export_ref_exception.t.js @@ -0,0 +1,9 @@ +/*--- +includes: [] +flags: [] +paths: [test/js/module, test/js/module/libs] +negative: + phase: runtime +---*/ + +import m from 'ref_exception.js'; diff --git a/test/js/import_export_return.t.js b/test/js/import_export_return.t.js new file mode 100644 index 00000000..64fd5e21 --- /dev/null +++ b/test/js/import_export_return.t.js @@ -0,0 +1,9 @@ +/*--- +includes: [] +flags: [] +paths: [test/js/module, test/js/module/libs] +negative: + phase: runtime +---*/ + +import m from 'return.js' diff --git a/test/js/import_loading_exception.t.js b/test/js/import_loading_exception.t.js new file mode 100644 index 00000000..1cf8e489 --- /dev/null +++ b/test/js/import_loading_exception.t.js @@ -0,0 +1,9 @@ +/*--- +includes: [] +flags: [] +paths: [test/js/module, test/js/module/libs] +negative: + phase: runtime +---*/ + +import m from 'loading_exception.js'; diff --git a/test/js/import_normal.t.js b/test/js/import_normal.t.js new file mode 100644 index 00000000..85ced08f --- /dev/null +++ b/test/js/import_normal.t.js @@ -0,0 +1,31 @@ +/*--- +includes: [] +flags: [] +paths: [test/js/module/, test/js/module/libs/] +---*/ + +import name from 'name.js'; +import lib1 from 'lib1.js'; +import lib2 from 'lib2.js'; +import lib1_2 from 'lib1.js'; + +import crypto from 'crypto'; +var h = crypto.createHash('md5'); +var hash = h.update('AB').digest('hex'); + +assert.sameValue(name, "name"); + +assert.sameValue(lib1.name, "libs.name"); + +assert.sameValue(lib1.hash(), hash); +assert.sameValue(lib2.hash(), hash); + +assert.sameValue(lib1.get(), 0); + +assert.sameValue(lib1_2.get(), 0); + +lib1.inc(); + +assert.sameValue(lib1.get(), 1); + +assert.sameValue(lib1_2.get(), 1); diff --git a/test/js/import_not_enough.t.js b/test/js/import_not_enough.t.js new file mode 100644 index 00000000..fae5ec60 --- /dev/null +++ b/test/js/import_not_enough.t.js @@ -0,0 +1,10 @@ +/*--- +includes: [] +flags: [] +paths: [test/js/module] +negative: + phase: runtime +---*/ + +import name from 'name.js'; +import lib1 from 'lib1.js'; diff --git a/test/js/import_not_found.t.js b/test/js/import_not_found.t.js new file mode 100644 index 00000000..d7b3ba02 --- /dev/null +++ b/test/js/import_not_found.t.js @@ -0,0 +1,9 @@ +/*--- +includes: [] +flags: [] +njs_cmd_args: [] +negative: + phase: runtime +---*/ + +import name from 'name.js'; diff --git a/test/js/import_recursive.t.js b/test/js/import_recursive.t.js new file mode 100644 index 00000000..976e23d3 --- /dev/null +++ b/test/js/import_recursive.t.js @@ -0,0 +1,9 @@ +/*--- +includes: [] +flags: [] +paths: [test/js/module/] +negative: + phase: runtime +---*/ + +import lib from 'import_recursive.t.js'; diff --git a/test/module/declaration_exception.js b/test/js/module/declaration_exception.js similarity index 100% rename from test/module/declaration_exception.js rename to test/js/module/declaration_exception.js diff --git a/test/module/empty.js b/test/js/module/empty.js similarity index 100% rename from test/module/empty.js rename to test/js/module/empty.js diff --git a/test/module/exception.js b/test/js/module/exception.js similarity index 100% rename from test/module/exception.js rename to test/js/module/exception.js diff --git a/test/module/export.js b/test/js/module/export.js similarity index 100% rename from test/module/export.js rename to test/js/module/export.js diff --git a/test/module/export_expression2.js b/test/js/module/export_comma_expression.js similarity index 100% rename from test/module/export_expression2.js rename to test/js/module/export_comma_expression.js diff --git a/test/module/export_expression.js b/test/js/module/export_expression.js similarity index 100% rename from test/module/export_expression.js rename to test/js/module/export_expression.js diff --git a/test/module/export_name.js b/test/js/module/export_name.js similarity index 100% rename from test/module/export_name.js rename to test/js/module/export_name.js diff --git a/test/module/export_non_assignment.js b/test/js/module/export_non_assignment.js similarity index 100% rename from test/module/export_non_assignment.js rename to test/js/module/export_non_assignment.js diff --git a/test/module/export_non_default.js b/test/js/module/export_non_default.js similarity index 100% rename from test/module/export_non_default.js rename to test/js/module/export_non_default.js diff --git a/test/module/lib1.js b/test/js/module/lib1.js similarity index 100% rename from test/module/lib1.js rename to test/js/module/lib1.js diff --git a/test/module/lib2.js b/test/js/module/lib2.js similarity index 100% rename from test/module/lib2.js rename to test/js/module/lib2.js diff --git a/test/module/lib3.js b/test/js/module/lib3.js similarity index 100% rename from test/module/lib3.js rename to test/js/module/lib3.js diff --git a/test/module/libs/hash.js b/test/js/module/libs/hash.js similarity index 100% rename from test/module/libs/hash.js rename to test/js/module/libs/hash.js diff --git a/test/module/libs/name.js b/test/js/module/libs/name.js similarity index 100% rename from test/module/libs/name.js rename to test/js/module/libs/name.js diff --git a/test/module/loading_exception.js b/test/js/module/loading_exception.js similarity index 100% rename from test/module/loading_exception.js rename to test/js/module/loading_exception.js diff --git a/test/module/name.js b/test/js/module/name.js similarity index 100% rename from test/module/name.js rename to test/js/module/name.js diff --git a/test/module/ref_exception.js b/test/js/module/ref_exception.js similarity index 100% rename from test/module/ref_exception.js rename to test/js/module/ref_exception.js diff --git a/test/module/return.js b/test/js/module/return.js similarity index 100% rename from test/module/return.js rename to test/js/module/return.js diff --git a/test/module/sub/sub1.js b/test/js/module/sub/sub1.js similarity index 100% rename from test/module/sub/sub1.js rename to test/js/module/sub/sub1.js diff --git a/test/module/sub/sub2.js b/test/js/module/sub/sub2.js similarity index 100% rename from test/module/sub/sub2.js rename to test/js/module/sub/sub2.js diff --git a/test/module/normal.js b/test/module/normal.js deleted file mode 100644 index 678da8c7..00000000 --- a/test/module/normal.js +++ /dev/null @@ -1,51 +0,0 @@ -import name from 'name.js'; -import lib1 from 'lib1.js'; -import lib2 from 'lib2.js'; -import lib1_2 from 'lib1.js'; - -import crypto from 'crypto'; -var h = crypto.createHash('md5'); -var hash = h.update('AB').digest('hex'); - -var fails = 0; - -if (name != 'name') { - fails++; -} - -if (lib1.name != 'libs.name') { - fails++; -} - -if (lib1.hash() != hash) { - fails++; -} - -if (lib2.hash() != hash) { - fails++; -} - -if (lib1.get() != 0) { - fails++; -} - -if (lib1_2.get() != 0) { - fails++; -} - -lib1.inc(); - -if (lib1.get() != 1) { - fails++; -} - -if (lib1_2.get() != 1) { - fails++; -} - -if (JSON.stringify({}) != "{}") { - fails++; -} - -setImmediate(console.log, - fails ? "failed: " + fails : "passed!"); diff --git a/test/module/recursive.js b/test/module/recursive.js deleted file mode 100644 index cd08ec1b..00000000 --- a/test/module/recursive.js +++ /dev/null @@ -1 +0,0 @@ -import lib from 'recursive.js'; diff --git a/test/njs_expect_test.exp b/test/shell_test.exp similarity index 87% rename from test/njs_expect_test.exp rename to test/shell_test.exp index 69d9cc8d..bb9b8c10 100644 --- a/test/njs_expect_test.exp +++ b/test/shell_test.exp @@ -470,26 +470,6 @@ ReferenceError: \"ref\" is not defined at anonymous \\\(string:1\\\) at main \\\(string:1\\\)\n$" -# Modules - -njs_run {"-p" "test/module/libs" "./test/module/normal.js"} \ - "passed!" - -njs_run {"-p" "test/module/libs/" "./test/module/normal.js"} \ - "passed!" - -njs_run {"-p" "test/module" "-p" "test/module/libs" "./test/module/normal.js"} \ - "passed!" - -njs_run {"./test/module/normal.js"} \ - "SyntaxError: Cannot find module \"hash.js\" in lib1.js:13" - -njs_run {"-p" "test/module/libs" "./test/module/exception.js"} \ - "at error \\(sub1.js:6\\)" - -njs_run {"-p" "test/module" "./test/module/recursive.js"} \ - "SyntaxError: Cannot import itself \"./test/module/recursive.js\" in recursive.js:1" - # CLI OPTIONS # help @@ -558,50 +538,18 @@ njs_test { "undefined\r\n"} {"lib1.get()\r\n" "1\r\n"} - {"import m from 'return.js'\r\n" - "Illegal return statement in return.js:1\r\n"} - {"import m from 'empty.js'\r\n" - "export statement is required in empty.js:1\r\n"} - {"import m from 'export.js'\r\n" - "Identifier \"default\" has already been declared in export.js:5\r\n"} - {"import m from 'export_non_default.js'\r\n" - "Non-default export is not supported in export_non_default.js:3\r\n"} - {"import m from 'export_non_assignment.js'\r\n" - "Unexpected token \",\" in export_non_assignment.js:1\r\n"} {"import ref from 'ref_exception.js'\r\n" "ReferenceError: \"undeclared\" is not defined"} {"var ref\r\n" "undefined\r\n"} {"import ref from 'ref_exception.js'\r\n" "ReferenceError: \"undeclared\" is not defined"} - {"import m from 'declaration_exception.js'\r\n" - "SyntaxError: \"f\" has already been declared in declaration_exception.js:6"} - {"import m from 'loading_exception.js'\r\n" - "Error: loading exception\r\n at module \\(loading_exception.js:1\\)"} - {"import lib3 from 'lib1.js'\r\n" - "undefined\r\n"} -} "-p test/module/ -p test/module/libs/" - -njs_test { - {"import m from 'export_name.js'\r\n" - "undefined\r\n"} - {"m.prod(3,4)\r\n" - "12\r\n"} - {"import m from 'export_expression.js'\r\n" - "undefined\r\n"} - {"m.sum(3,4)\r\n" - "7\r\n"} - {"import m from 'export_expression2.js'\r\n" - "undefined\r\n"} - {"m.prod(3,4)\r\n" - "12\r\n"} -} "-p test/module/" +} "-p test/js/module/ -p test/js/module/libs/" -njs_run {"-q" "./test/module/normal.js"} \ - "SyntaxError: Cannot find module \"hash.js\" in 13" +# quiet mode -njs_run {"-p" "test/module/libs/" "-d" "./test/module/normal.js"} \ - "passed!" +njs_run {"-q" "test/js/import_normal.t.js"} \ + "SyntaxError: Cannot find module \"name.js\" in 7" # sandboxing