1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 21:07:35 +00:00

LibTest+test-js: Add back the lost test262 parser test option

Fixes #7566.
This commit is contained in:
Ali Mohammad Pur 2021-05-30 10:35:44 +04:30 committed by Linus Groh
parent 724b89f90c
commit f387da4a90
3 changed files with 132 additions and 0 deletions

View file

@ -9,6 +9,8 @@
TEST_ROOT("Userland/Libraries/LibJS/Tests");
TESTJS_PROGRAM_FLAG(test262_parser_tests, "Run test262 parser tests", "test262-parser-tests", 0);
TESTJS_GLOBAL_FUNCTION(is_strict_mode, isStrictMode, 0)
{
return JS::Value(vm.in_strict_mode());
@ -29,3 +31,63 @@ TESTJS_GLOBAL_FUNCTION(run_queued_promise_jobs, runQueuedPromiseJobs)
vm.run_queued_promise_jobs();
return JS::js_undefined();
}
TESTJS_RUN_FILE_FUNCTION(const String& test_file, JS::Interpreter&)
{
if (!test262_parser_tests)
return Test::JS::RunFileHookResult::RunAsNormal;
auto start_time = Test::JS::get_time_in_ms();
LexicalPath path(test_file);
auto& dirname = path.dirname();
enum {
Early,
Fail,
Pass,
ExplicitPass,
} expectation { Pass };
if (dirname.ends_with("early"))
expectation = Early;
else if (dirname.ends_with("fail"))
expectation = Fail;
else if (dirname.ends_with("pass-explicit"))
expectation = ExplicitPass;
else if (dirname.ends_with("pass"))
expectation = Pass;
else
return Test::JS::RunFileHookResult::SkipFile;
auto parse_result = Test::JS::parse_file(test_file);
bool test_passed = true;
String message;
String expectation_string;
switch (expectation) {
case Early:
case Fail:
expectation_string = "File should not parse";
test_passed = parse_result.is_error();
if (!test_passed)
message = "Expected the file to fail parsing, but it did not";
break;
case Pass:
case ExplicitPass:
expectation_string = "File should parse";
test_passed = !parse_result.is_error();
if (!test_passed)
message = "Expected the file to parse, but it did not";
break;
}
auto test_result = test_passed ? Test::Result::Pass : Test::Result::Fail;
return Test::JS::JSFileResult {
LexicalPath::relative_path(test_file, Test::JS::g_test_root),
{},
Test::JS::get_time_in_ms() - start_time,
test_result,
{ Test::Suite { "Parse file", test_result, { { expectation_string, test_result, message } } } }
};
}