mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 19:27:45 +00:00
run-tests: Port to LibMain
This commit is contained in:
parent
7d87f0d56d
commit
bb4994d67b
2 changed files with 15 additions and 13 deletions
|
@ -176,7 +176,7 @@ target_link_libraries(reboot LibMain)
|
||||||
target_link_libraries(rev LibMain)
|
target_link_libraries(rev LibMain)
|
||||||
target_link_libraries(rm LibMain)
|
target_link_libraries(rm LibMain)
|
||||||
target_link_libraries(rmdir LibMain)
|
target_link_libraries(rmdir LibMain)
|
||||||
target_link_libraries(run-tests LibRegex LibCoredump)
|
target_link_libraries(run-tests LibRegex LibCoredump LibMain)
|
||||||
target_link_libraries(shot LibGUI LibMain)
|
target_link_libraries(shot LibGUI LibMain)
|
||||||
target_link_libraries(shuf LibMain)
|
target_link_libraries(shuf LibMain)
|
||||||
target_link_libraries(shutdown LibMain)
|
target_link_libraries(shutdown LibMain)
|
||||||
|
|
|
@ -8,7 +8,9 @@
|
||||||
#include <LibCore/ArgsParser.h>
|
#include <LibCore/ArgsParser.h>
|
||||||
#include <LibCore/ConfigFile.h>
|
#include <LibCore/ConfigFile.h>
|
||||||
#include <LibCore/File.h>
|
#include <LibCore/File.h>
|
||||||
|
#include <LibCore/System.h>
|
||||||
#include <LibCoredump/Backtrace.h>
|
#include <LibCoredump/Backtrace.h>
|
||||||
|
#include <LibMain/Main.h>
|
||||||
#include <LibRegex/Regex.h>
|
#include <LibRegex/Regex.h>
|
||||||
#include <LibTest/TestRunner.h>
|
#include <LibTest/TestRunner.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
@ -289,18 +291,18 @@ FileResult TestRunner::run_test_file(const String& test_path)
|
||||||
return FileResult { move(path_for_test), get_time_in_ms() - start_time, test_result, child_out_err_file, child_pid };
|
return FileResult { move(path_for_test), get_time_in_ms() - start_time, test_result, child_out_err_file, child_pid };
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
{
|
{
|
||||||
|
|
||||||
auto program_name = LexicalPath::basename(argv[0]);
|
auto program_name = LexicalPath::basename(arguments.strings[0]);
|
||||||
|
|
||||||
#ifdef SIGINFO
|
#ifdef SIGINFO
|
||||||
signal(SIGINFO, [](int) {
|
TRY(Core::System::signal(SIGINFO, [](int) {
|
||||||
static char buffer[4096];
|
static char buffer[4096];
|
||||||
auto& counts = ::Test::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());
|
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);
|
write(STDOUT_FILENO, buffer, len);
|
||||||
});
|
}));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool print_progress =
|
bool print_progress =
|
||||||
|
@ -342,7 +344,7 @@ int main(int argc, char** argv)
|
||||||
args_parser.add_option(exclude_pattern, "Regular expression to use to exclude paths from being considered tests", "exclude-pattern", 'e', "pattern");
|
args_parser.add_option(exclude_pattern, "Regular expression to use to exclude paths from being considered tests", "exclude-pattern", 'e', "pattern");
|
||||||
args_parser.add_option(config_file, "Configuration file to use", "config-file", 'c', "filename");
|
args_parser.add_option(config_file, "Configuration file to use", "config-file", 'c', "filename");
|
||||||
args_parser.add_positional_argument(specified_test_root, "Tests root directory", "path", Core::ArgsParser::Required::No);
|
args_parser.add_positional_argument(specified_test_root, "Tests root directory", "path", Core::ArgsParser::Required::No);
|
||||||
args_parser.parse(argc, argv);
|
args_parser.parse(arguments);
|
||||||
|
|
||||||
test_glob = String::formatted("*{}*", test_glob);
|
test_glob = String::formatted("*{}*", test_glob);
|
||||||
|
|
||||||
|
@ -351,10 +353,10 @@ int main(int argc, char** argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make UBSAN deadly for all tests we run by default.
|
// Make UBSAN deadly for all tests we run by default.
|
||||||
setenv("UBSAN_OPTIONS", "halt_on_error=1", true);
|
TRY(Core::System::setenv("UBSAN_OPTIONS", "halt_on_error=1", true));
|
||||||
|
|
||||||
if (!run_benchmarks)
|
if (!run_benchmarks)
|
||||||
setenv("TESTS_ONLY", "1", true);
|
TRY(Core::System::setenv("TESTS_ONLY", "1", true));
|
||||||
|
|
||||||
String test_root;
|
String test_root;
|
||||||
|
|
||||||
|
@ -370,16 +372,16 @@ int main(int argc, char** argv)
|
||||||
|
|
||||||
test_root = Core::File::real_path_for(test_root);
|
test_root = Core::File::real_path_for(test_root);
|
||||||
|
|
||||||
if (chdir(test_root.characters()) < 0) {
|
auto void_or_error = Core::System::chdir(test_root);
|
||||||
auto saved_errno = errno;
|
if (void_or_error.is_error()) {
|
||||||
warnln("chdir failed: {}", strerror(saved_errno));
|
warnln("chdir failed: {}", void_or_error.error());
|
||||||
return 1;
|
return void_or_error.release_error();
|
||||||
}
|
}
|
||||||
|
|
||||||
auto config_or_error = config_file.is_empty() ? Core::ConfigFile::open_for_app("Tests") : Core::ConfigFile::open(config_file);
|
auto config_or_error = config_file.is_empty() ? Core::ConfigFile::open_for_app("Tests") : Core::ConfigFile::open(config_file);
|
||||||
if (config_or_error.is_error()) {
|
if (config_or_error.is_error()) {
|
||||||
warnln("Failed to open configuration file ({}): {}", config_file.is_empty() ? "User config for Tests" : config_file.characters(), config_or_error.error());
|
warnln("Failed to open configuration file ({}): {}", config_file.is_empty() ? "User config for Tests" : config_file.characters(), config_or_error.error());
|
||||||
return 1;
|
return config_or_error.release_error();
|
||||||
}
|
}
|
||||||
auto config = config_or_error.release_value();
|
auto config = config_or_error.release_value();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue