1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 05:27:43 +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

@ -68,9 +68,28 @@
} __testjs_common_register_##name {}; \
void __TestJS_main_hook::hook()
#define TESTJS_PROGRAM_FLAG(flag, help_string, long_name, short_name) \
bool flag { false }; \
struct __TestJS_flag_hook_##flag { \
__TestJS_flag_hook_##flag() \
{ \
::Test::JS::g_extra_args.set(&(flag), { help_string, long_name, short_name }); \
}; \
} __testjs_flag_hook_##flag;
#define TEST_ROOT(path) \
String Test::JS::g_test_root_fragment = path
#define TESTJS_RUN_FILE_FUNCTION(...) \
struct __TestJS_run_file { \
__TestJS_run_file() \
{ \
::Test::JS::g_run_file = hook; \
} \
static ::Test::JS::IntermediateRunFileResult hook(const String&, JS::Interpreter&); \
} __testjs_common_run_file {}; \
::Test::JS::IntermediateRunFileResult __TestJS_run_file::hook(__VA_ARGS__)
namespace Test::JS {
namespace JS = ::JS;
@ -96,6 +115,7 @@ extern String g_test_root;
extern int g_test_argc;
extern char** g_test_argv;
extern Function<void()> g_main_hook;
extern HashMap<bool*, Tuple<String, String, char>> g_extra_args;
struct ParserError {
JS::Parser::Error error;
@ -113,6 +133,14 @@ struct JSFileResult {
Vector<String> logged_messages {};
};
enum class RunFileHookResult {
RunAsNormal,
SkipFile,
};
using IntermediateRunFileResult = AK::Result<JSFileResult, RunFileHookResult>;
extern IntermediateRunFileResult (*g_run_file)(const String&, JS::Interpreter&);
class TestRunner {
public:
static TestRunner* the()
@ -302,6 +330,41 @@ inline JSFileResult TestRunner::run_file_test(const String& test_path)
interpreter->heap().set_should_collect_on_every_allocation(g_collect_on_every_allocation);
if (g_run_file) {
auto result = g_run_file(test_path, *interpreter);
if (result.is_error() && result.error() == RunFileHookResult::SkipFile) {
return {
test_path,
{},
0,
Test::Result::Skip,
{},
{}
};
}
if (!result.is_error()) {
auto value = result.release_value();
for (auto& suite : value.suites) {
if (suite.most_severe_test_result == Result::Pass)
m_counts.suites_passed++;
else if (suite.most_severe_test_result == Result::Fail)
m_counts.suites_failed++;
for (auto& test : suite.tests) {
if (test.result == Result::Pass)
m_counts.tests_passed++;
else if (test.result == Result::Fail)
m_counts.tests_failed++;
else if (test.result == Result::Skip)
m_counts.tests_skipped++;
}
}
++m_counts.files_total;
m_total_elapsed_time_in_ms += value.time_taken;
return value;
}
}
if (!m_test_program) {
auto result = parse_file(m_common_path);
if (result.is_error()) {