]> git.kaiwu.me - njs.git/commitdiff
Tests: refactored modules tests using test262 test suite.
authorDmitry Volyntsev <xeioex@nginx.com>
Thu, 27 Jan 2022 13:01:55 +0000 (13:01 +0000)
committerDmitry Volyntsev <xeioex@nginx.com>
Thu, 27 Jan 2022 13:01:55 +0000 (13:01 +0000)
41 files changed:
auto/expect
auto/make
test/js/import_declaration_exception.t.js [new file with mode: 0644]
test/js/import_exception.t.js [new file with mode: 0644]
test/js/import_export_comma_expression.t.js [new file with mode: 0644]
test/js/import_export_empty.t.js [new file with mode: 0644]
test/js/import_export_expression.t.js [new file with mode: 0644]
test/js/import_export_multi_default.t.js [new file with mode: 0644]
test/js/import_export_non_assignment.t.js [new file with mode: 0644]
test/js/import_export_non_default.t.js [new file with mode: 0644]
test/js/import_export_object.t.js [new file with mode: 0644]
test/js/import_export_ref_exception.t.js [new file with mode: 0644]
test/js/import_export_return.t.js [new file with mode: 0644]
test/js/import_loading_exception.t.js [new file with mode: 0644]
test/js/import_normal.t.js [new file with mode: 0644]
test/js/import_not_enough.t.js [new file with mode: 0644]
test/js/import_not_found.t.js [new file with mode: 0644]
test/js/import_recursive.t.js [new file with mode: 0644]
test/js/module/declaration_exception.js [moved from test/module/declaration_exception.js with 100% similarity]
test/js/module/empty.js [moved from test/module/empty.js with 100% similarity]
test/js/module/exception.js [moved from test/module/exception.js with 100% similarity]
test/js/module/export.js [moved from test/module/export.js with 100% similarity]
test/js/module/export_comma_expression.js [moved from test/module/export_expression2.js with 100% similarity]
test/js/module/export_expression.js [moved from test/module/export_expression.js with 100% similarity]
test/js/module/export_name.js [moved from test/module/export_name.js with 100% similarity]
test/js/module/export_non_assignment.js [moved from test/module/export_non_assignment.js with 100% similarity]
test/js/module/export_non_default.js [moved from test/module/export_non_default.js with 100% similarity]
test/js/module/lib1.js [moved from test/module/lib1.js with 100% similarity]
test/js/module/lib2.js [moved from test/module/lib2.js with 100% similarity]
test/js/module/lib3.js [moved from test/module/lib3.js with 100% similarity]
test/js/module/libs/hash.js [moved from test/module/libs/hash.js with 100% similarity]
test/js/module/libs/name.js [moved from test/module/libs/name.js with 100% similarity]
test/js/module/loading_exception.js [moved from test/module/loading_exception.js with 100% similarity]
test/js/module/name.js [moved from test/module/name.js with 100% similarity]
test/js/module/ref_exception.js [moved from test/module/ref_exception.js with 100% similarity]
test/js/module/return.js [moved from test/module/return.js with 100% similarity]
test/js/module/sub/sub1.js [moved from test/module/sub/sub1.js with 100% similarity]
test/js/module/sub/sub2.js [moved from test/module/sub/sub2.js with 100% similarity]
test/module/normal.js [deleted file]
test/module/recursive.js [deleted file]
test/shell_test.exp [moved from test/njs_expect_test.exp with 87% similarity]

index 1bb032519f1a8d6ee5844ea11150536a05adb5e7..db9bb859977e93ec2b36f6bd61d738e44d499cdb 100644 (file)
@@ -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
 
index 6fa45404a464e5cc90917185b83fe17fbc5ca1e6..14263c1f5de3cb0729f50fc6ef21ad283164ea00 100644 (file)
--- 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 (file)
index 0000000..521cc00
--- /dev/null
@@ -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 (file)
index 0000000..343cb24
--- /dev/null
@@ -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 (file)
index 0000000..185d3a6
--- /dev/null
@@ -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 (file)
index 0000000..cf6ec36
--- /dev/null
@@ -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 (file)
index 0000000..bf6fd5f
--- /dev/null
@@ -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 (file)
index 0000000..1e4cf08
--- /dev/null
@@ -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 (file)
index 0000000..f8d6361
--- /dev/null
@@ -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 (file)
index 0000000..6b53010
--- /dev/null
@@ -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 (file)
index 0000000..d430742
--- /dev/null
@@ -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 (file)
index 0000000..654933a
--- /dev/null
@@ -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 (file)
index 0000000..64fd5e2
--- /dev/null
@@ -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 (file)
index 0000000..1cf8e48
--- /dev/null
@@ -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 (file)
index 0000000..85ced08
--- /dev/null
@@ -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 (file)
index 0000000..fae5ec6
--- /dev/null
@@ -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 (file)
index 0000000..d7b3ba0
--- /dev/null
@@ -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 (file)
index 0000000..976e23d
--- /dev/null
@@ -0,0 +1,9 @@
+/*---
+includes: []
+flags: []
+paths: [test/js/module/]
+negative:
+  phase: runtime
+---*/
+
+import lib from 'import_recursive.t.js';
similarity index 100%
rename from test/module/empty.js
rename to test/js/module/empty.js
similarity index 100%
rename from test/module/lib1.js
rename to test/js/module/lib1.js
similarity index 100%
rename from test/module/lib2.js
rename to test/js/module/lib2.js
similarity index 100%
rename from test/module/lib3.js
rename to test/js/module/lib3.js
similarity index 100%
rename from test/module/name.js
rename to test/js/module/name.js
diff --git a/test/module/normal.js b/test/module/normal.js
deleted file mode 100644 (file)
index 678da8c..0000000
+++ /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 (file)
index cd08ec1..0000000
+++ /dev/null
@@ -1 +0,0 @@
-import lib from 'recursive.js';
similarity index 87%
rename from test/njs_expect_test.exp
rename to test/shell_test.exp
index 69d9cc8d608bacb4d7651cc89f99b6f9f409b18d..bb9b8c10a80f2e553c2cc82e5025c6f113fb1afc 100644 (file)
@@ -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