diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6b74dbac..42fe6449 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -141,7 +141,7 @@ jobs: make stats - name: test - if: ${{ matrix.config.configType != 'examples' }} + if: ${{ matrix.config.configType != 'examples' && matrix.config.configType != 'tcc' }} run: | make test @@ -214,16 +214,7 @@ jobs: cp build\${{matrix.buildType}}\point.dll examples\ build\${{matrix.buildType}}\qjs.exe examples\test_fib.js build\${{matrix.buildType}}\qjs.exe examples\test_point.js - build\${{matrix.buildType}}\qjs.exe tests\test_bigint.js - build\${{matrix.buildType}}\qjs.exe tests\test_bjson.js - build\${{matrix.buildType}}\qjs.exe tests\test_closure.js - build\${{matrix.buildType}}\qjs.exe tests\test_language.js - build\${{matrix.buildType}}\qjs.exe tests\test_builtin.js - build\${{matrix.buildType}}\qjs.exe tests\test_loop.js - build\${{matrix.buildType}}\qjs.exe tests\test_std.js - build\${{matrix.buildType}}\qjs.exe tests\test_worker.js - build\${{matrix.buildType}}\qjs.exe tests\test_queue_microtask.js - build\${{matrix.buildType}}\qjs.exe tests\test_module_detect.js + build\${{matrix.buildType}}\run-test262.exe -c tests.conf build\${{matrix.buildType}}\function_source.exe windows-clang: @@ -247,16 +238,7 @@ jobs: cp build\${{matrix.buildType}}\point.dll examples\ build\${{matrix.buildType}}\qjs.exe examples\test_fib.js build\${{matrix.buildType}}\qjs.exe examples\test_point.js - build\${{matrix.buildType}}\qjs.exe tests\test_bigint.js - build\${{matrix.buildType}}\qjs.exe tests\test_bjson.js - build\${{matrix.buildType}}\qjs.exe tests\test_closure.js - build\${{matrix.buildType}}\qjs.exe tests\test_language.js - build\${{matrix.buildType}}\qjs.exe tests\test_builtin.js - build\${{matrix.buildType}}\qjs.exe tests\test_loop.js - build\${{matrix.buildType}}\qjs.exe tests\test_std.js - build\${{matrix.buildType}}\qjs.exe tests\test_worker.js - build\${{matrix.buildType}}\qjs.exe tests\test_queue_microtask.js - build\${{matrix.buildType}}\qjs.exe tests\test_module_detect.js + build\${{matrix.buildType}}\run-test262.exe -c tests.conf build\${{matrix.buildType}}\function_source.exe windows-ninja: @@ -284,16 +266,7 @@ jobs: cp build\point.dll examples\ build\qjs.exe examples\test_fib.js build\qjs.exe examples\test_point.js - build\qjs.exe tests\test_bigint.js - build\qjs.exe tests\test_bjson.js - build\qjs.exe tests\test_closure.js - build\qjs.exe tests\test_language.js - build\qjs.exe tests\test_builtin.js - build\qjs.exe tests\test_loop.js - build\qjs.exe tests\test_std.js - build\qjs.exe tests\test_worker.js - build\qjs.exe tests\test_queue_microtask.js - build\qjs.exe tests\test_module_detect.js + build\run-test262.exe -c tests.conf build\function_source.exe windows-mingw: diff --git a/Makefile b/Makefile index 1703c07a..a5a5734f 100644 --- a/Makefile +++ b/Makefile @@ -80,15 +80,7 @@ stats: $(QJS) $(QJS) -qd test: $(QJS) - $(QJS) tests/test_bigint.js - $(QJS) tests/test_closure.js - $(QJS) tests/test_language.js - $(QJS) tests/test_builtin.js - $(QJS) tests/test_loop.js - $(QJS) tests/test_std.js - $(QJS) tests/test_worker.js - $(QJS) tests/test_queue_microtask.js - $(QJS) tests/test_module_detect.js + $(RUN262) -c tests.conf testconv: $(BUILD_DIR)/test_conv $(BUILD_DIR)/test_conv diff --git a/run-test262.c b/run-test262.c index c962475a..e9ff83b0 100644 --- a/run-test262.c +++ b/run-test262.c @@ -74,6 +74,7 @@ enum test_mode_t { TEST_STRICT, /* run tests as strict, skip nostrict tests */ TEST_ALL, /* run tests in both strict and nostrict, unless restricted by spec */ } test_mode = TEST_DEFAULT_NOSTRICT; +int local; int skip_async; int skip_module; int dump_memory; @@ -1129,6 +1130,10 @@ void load_config(const char *filename, const char *ignore) printf("%s:%d: ignoring %s=%s\n", filename, lineno, p, q); continue; } + if (str_equal(p, "local")) { + local = str_equal(q, "yes"); + continue; + } if (str_equal(p, "testdir")) { char *testdir = compose_path(base_name, q); enumerate_tests(testdir); @@ -1512,6 +1517,11 @@ static int eval_buf(JSContext *ctx, const char *buf, size_t buf_len, JS_FreeCString(ctx, msg); free(s); } + + if (local) { + js_std_loop(ctx); + } + JS_FreeCString(ctx, error_name); JS_FreeValue(ctx, exception_val); JS_FreeValue(ctx, res_val); @@ -1679,6 +1689,19 @@ void update_stats(JSRuntime *rt, const char *filename) { js_mutex_unlock(&stats_mutex); } +JSContext *JS_NewCustomContext(JSRuntime *rt) +{ + JSContext *ctx; + + ctx = JS_NewContext(rt); + if (ctx && local) { + js_init_module_std(ctx, "std"); + js_init_module_os(ctx, "os"); + js_init_module_bjson(ctx, "bjson"); + } + return ctx; +} + int run_test_buf(const char *filename, char *harness, namelist_t *ip, char *buf, size_t buf_len, const char* error_type, int eval_flags, BOOL is_negative, BOOL is_async, @@ -1692,7 +1715,8 @@ int run_test_buf(const char *filename, char *harness, namelist_t *ip, if (rt == NULL) { fatal(1, "JS_NewRuntime failure"); } - ctx = JS_NewContext(rt); + js_std_init_handlers(rt); + ctx = JS_NewCustomContext(rt); if (ctx == NULL) { JS_FreeRuntime(rt); fatal(1, "JS_NewContext failure"); @@ -1721,6 +1745,7 @@ int run_test_buf(const char *filename, char *harness, namelist_t *ip, } js_agent_free(ctx); JS_FreeContext(ctx); + js_std_free_handlers(rt); JS_FreeRuntime(rt); atomic_inc(&test_count); @@ -1757,8 +1782,10 @@ int run_test(const char *filename, int *msec) } harness = harnessbuf; } - namelist_add(ip, NULL, "sta.js"); - namelist_add(ip, NULL, "assert.js"); + if (!local) { + namelist_add(ip, NULL, "sta.js"); + namelist_add(ip, NULL, "assert.js"); + } /* extract the YAML frontmatter */ desc = extract_desc(buf, '-'); if (desc) { @@ -1874,6 +1901,9 @@ int run_test(const char *filename, int *msec) atomic_inc(&test_skipped); ret = -2; } else { + if (local) { + is_module = JS_DetectModule(buf, buf_len); + } if (is_module) { eval_flags = JS_EVAL_TYPE_MODULE; } else { @@ -2070,6 +2100,8 @@ int main(int argc, char **argv) BOOL is_test262_harness = FALSE; BOOL is_module = FALSE; + js_std_set_worker_new_context_func(JS_NewCustomContext); + tls = &(ThreadLocalStorage){}; init_thread_local_storage(tls); js_mutex_init(&stats_mutex); diff --git a/tests.conf b/tests.conf new file mode 100644 index 00000000..30ee794d --- /dev/null +++ b/tests.conf @@ -0,0 +1,8 @@ +[config] +local=yes +verbose=yes +testdir=tests + +[exclude] +tests/microbench.js +tests/test_worker_module.js diff --git a/tests/test_std.js b/tests/test_std.js index 7e9e2a42..b9ea6e2f 100644 --- a/tests/test_std.js +++ b/tests/test_std.js @@ -90,6 +90,7 @@ function test_popen() { var str, f, fname = "tmp_file.txt"; var content = "hello world"; + var cmd = isWin ? "type" : "cat"; f = std.open(fname, "w"); f.puts(content); @@ -98,8 +99,8 @@ function test_popen() /* test loadFile */ assert(std.loadFile(fname), content); - /* execute the 'cat' shell command */ - f = std.popen("cat " + fname, "r"); + /* execute shell command */ + f = std.popen(cmd + " " + fname, "r"); str = f.readAsString(); f.close();