Luna/tests/run-tests.cpp

41 lines
1.1 KiB
C++
Raw Normal View History

#include <luna/String.h>
#include <os/ArgumentParser.h>
#include <os/Directory.h>
#include <os/File.h>
#include <os/Process.h>
#include <signal.h>
#include <stdlib.h>
#include <sys/wait.h>
Result<int> luna_main(int argc, char** argv)
{
StringView test_dir;
os::ArgumentParser parser;
parser.add_description("Run the system test suite.");
parser.add_system_program_info("run-tests"_sv);
parser.add_positional_argument(test_dir, "test-dir", "/bin/tests"_sv);
parser.parse(argc, argv);
auto dir = TRY(os::Directory::open(test_dir));
2023-06-15 13:50:04 +00:00
auto files = TRY(dir->list_names(os::Directory::Filter::Hidden));
for (const auto& program : files)
{
auto command = TRY(String::format("%s/%s"_sv, test_dir.chars(), program.chars()));
int status = system(command.chars());
if (WEXITSTATUS(status) != 0)
{
os::Process::kill(1, SIGQUIT); // Tell init to report a failed test run.
return WEXITSTATUS(status);
}
}
os::println("All tests passed.");
os::Process::kill(1, SIGTERM); // Tell init to report a successful test run.
return 0;
}