mirror of
https://github.com/RGBCube/serenity
synced 2025-05-28 13:55:06 +00:00
Userland+Tests: Split out generic test runner from JS TestRunner
Split out the functionality to gather multiple tests from the filesystem and run them in turn into Test::TestRunner, and leave the JavaScript specific test harness logic in Test::JS::TestRunner and friends.
This commit is contained in:
parent
44a6715584
commit
601c9e89de
4 changed files with 287 additions and 237 deletions
|
@ -10,24 +10,27 @@
|
|||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
|
||||
namespace Test::JS {
|
||||
namespace Test {
|
||||
|
||||
TestRunner* ::Test::TestRunner::s_the = nullptr;
|
||||
|
||||
namespace JS {
|
||||
|
||||
RefPtr<::JS::VM> g_vm;
|
||||
bool g_collect_on_every_allocation = false;
|
||||
bool g_run_bytecode = false;
|
||||
bool g_dump_bytecode = false;
|
||||
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;
|
||||
char** g_test_argv;
|
||||
|
||||
}
|
||||
} // namespace JS
|
||||
} // namespace Test
|
||||
|
||||
using namespace Test::JS;
|
||||
|
||||
|
@ -36,7 +39,7 @@ static StringView g_program_name { "test-js"sv };
|
|||
static void handle_sigabrt(int)
|
||||
{
|
||||
dbgln("{}: SIGABRT received, cleaning up.", g_program_name);
|
||||
cleanup();
|
||||
Test::cleanup();
|
||||
struct sigaction act;
|
||||
memset(&act, 0, sizeof(act));
|
||||
act.sa_flags = SA_NOCLDWAIT;
|
||||
|
@ -69,7 +72,7 @@ int main(int argc, char** argv)
|
|||
#ifdef SIGINFO
|
||||
signal(SIGINFO, [](int) {
|
||||
static char buffer[4096];
|
||||
auto& counts = TestRunner::the()->counts();
|
||||
auto& counts = ::Test::TestRunner::the()->counts();
|
||||
int len = snprintf(buffer, sizeof(buffer), "Pass: %d, Fail: %d, Skip: %d\nCurrent test: %s\n", counts.tests_passed, counts.tests_failed, counts.tests_skipped, g_currently_running_test.characters());
|
||||
write(STDOUT_FILENO, buffer, len);
|
||||
});
|
||||
|
@ -85,6 +88,7 @@ int main(int argc, char** argv)
|
|||
bool print_json = false;
|
||||
const char* specified_test_root = nullptr;
|
||||
String common_path;
|
||||
String test_glob;
|
||||
|
||||
Core::ArgsParser args_parser;
|
||||
args_parser.add_option(print_times, "Show duration of each test", "show-time", 't');
|
||||
|
@ -107,14 +111,14 @@ 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_run_bytecode, "Use the bytecode interpreter", "run-bytecode", 'b');
|
||||
args_parser.add_option(g_dump_bytecode, "Dump the bytecode", "dump-bytecode", 'd');
|
||||
args_parser.add_option(g_test_glob, "Only run tests matching the given glob", "filter", 'f', "glob");
|
||||
args_parser.add_option(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);
|
||||
|
||||
g_test_glob = String::formatted("*{}*", g_test_glob);
|
||||
test_glob = String::formatted("*{}*", test_glob);
|
||||
|
||||
if (getenv("DISABLE_DBG_OUTPUT")) {
|
||||
AK::set_debug_enabled(false);
|
||||
|
@ -175,8 +179,8 @@ int main(int argc, char** argv)
|
|||
if (!g_vm)
|
||||
g_vm = JS::VM::create();
|
||||
|
||||
TestRunner test_runner(test_root, common_path, print_times, print_progress, print_json);
|
||||
test_runner.run();
|
||||
Test::JS::TestRunner test_runner(test_root, common_path, print_times, print_progress, print_json);
|
||||
test_runner.run(test_glob);
|
||||
|
||||
g_vm = nullptr;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue