1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 10: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

@ -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()) {

View file

@ -18,6 +18,8 @@ String g_currently_running_test;
String g_test_glob;
HashMap<String, FunctionWithLength> s_exposed_global_functions;
Function<void()> g_main_hook;
HashMap<bool*, Tuple<String, String, char>> g_extra_args;
IntermediateRunFileResult (*g_run_file)(const String&, JS::Interpreter&) = nullptr;
TestRunner* TestRunner::s_the = nullptr;
String g_test_root;
int g_test_argc;
@ -100,6 +102,8 @@ int main(int argc, char** argv)
});
args_parser.add_option(g_collect_on_every_allocation, "Collect garbage after every allocation", "collect-often", 'g');
args_parser.add_option(g_test_glob, "Only run tests matching the given glob", "filter", 'f', "glob");
for (auto& entry : g_extra_args)
args_parser.add_option(*entry.key, entry.value.get<0>().characters(), entry.value.get<1>().characters(), entry.value.get<2>());
args_parser.add_positional_argument(specified_test_root, "Tests root directory", "path", Core::ArgsParser::Required::No);
args_parser.add_positional_argument(common_path, "Path to tests-common.js", "common-path", Core::ArgsParser::Required::No);
args_parser.parse(argc, argv);
@ -145,6 +149,9 @@ int main(int argc, char** argv)
#endif
}
test_root = Core::File::real_path_for(test_root);
common_path = Core::File::real_path_for(common_path);
if (chdir(test_root.characters()) < 0) {
auto saved_errno = errno;
warnln("chdir failed: {}", strerror(saved_errno));