test-js: Add argument for explicit test root directory

Right now test-js has a hardcoded test root directory when running on
Serenity or will get it based on SERENITY_ROOT otherwise. Now it is
also possible to pass a path to the command which will take precedence
over these mechanisms.

This will also be useful for adding test262 support as those files will
not have a default location.
This commit is contained in:
Linus Groh 2020-10-18 19:11:57 +01:00 committed by Andreas Kling
parent 69a015cd9a
commit cce673e7b0
Notes: sideshowbarker 2024-07-19 01:51:13 +09:00

View file

@ -1,5 +1,6 @@
/*
* Copyright (c) 2020, Matthew Olsson <matthewcolsson@gmail.com>
* Copyright (c) 2020, Linus Groh <mail@linusgroh.de>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -580,7 +581,6 @@ void TestRunner::print_test_results() const
int main(int argc, char** argv)
{
bool print_times = false;
struct sigaction act;
memset(&act, 0, sizeof(act));
act.sa_flags = SA_NOCLDWAIT;
@ -600,27 +600,39 @@ int main(int argc, char** argv)
});
#endif
bool print_times = false;
const char* test_root = nullptr;
Core::ArgsParser args_parser;
args_parser.add_option(print_times, "Show duration of each test", "show-time", 't');
args_parser.add_option(collect_on_every_allocation, "Collect garbage after every allocation", "collect-often", 'g');
args_parser.add_positional_argument(test_root, "Tests root directory", "path", Core::ArgsParser::Required::No);
args_parser.parse(argc, argv);
if (getenv("DISABLE_DBG_OUTPUT")) {
DebugLogStream::set_enabled(false);
}
vm = JS::VM::create();
if (!test_root) {
#ifdef __serenity__
TestRunner("/home/anon/js-tests", print_times).run();
test_root = "/home/anon/js-tests";
#else
char* serenity_root = getenv("SERENITY_ROOT");
if (!serenity_root) {
printf("test-js requires the SERENITY_ROOT environment variable to be set");
char* serenity_root = getenv("SERENITY_ROOT");
if (!serenity_root) {
printf("No test root given, test-js requires the SERENITY_ROOT environment variable to be set");
return 1;
}
test_root = String::formatted("{}/Libraries/LibJS/Tests", serenity_root).characters();
#endif
}
if (!Core::File::is_directory(test_root)) {
fprintf(stderr, "Test root is not a directory: %s\n", test_root);
return 1;
}
TestRunner(String::format("%s/Libraries/LibJS/Tests", serenity_root), print_times).run();
#endif
vm = JS::VM::create();
TestRunner(test_root, print_times).run();
vm = nullptr;