light/modules/test/entrypoint.cpp
light7734 19187aa1d6
Some checks reported errors
continuous-integration/drone/push Build was killed
wip: feat: lsd
2025-11-18 19:06:44 +03:30

101 lines
2.4 KiB
C++

import logger;
import test.test;
import test.registry;
import lsd;
using namespace ::lt;
using namespace ::lt::test;
void parse_option(lsd::str_view argument, Registry::Options &options)
{
constexpr auto case_str = lsd::str_view { "--case=" };
constexpr auto suite_str = lsd::str_view { "--suite=" };
if (argument == "--stop-on-fail")
{
options.stop_on_fail = true;
return;
}
if (argument.starts_with("--mode=") && argument.substr(7ul) == "stats")
{
options.execution_policy = Registry::ExecutionPolicy::stats;
return;
}
if (argument.starts_with(suite_str) && argument.length() > suite_str.size())
{
options.suite_regex = argument.substr(suite_str.length());
lsd::println("SUITE REGEX: {}", options.suite_regex);
return;
}
if (argument.starts_with(case_str) && argument.length() > case_str.size())
{
options.case_regex = argument.substr(case_str.length());
lsd::println("CASE REGEX: {}", options.case_regex);
return;
}
throw std::invalid_argument { std::format("Invalid argument: {}", argument) };
}
void print_help()
{
lsd::println("Options: ");
lsd::println("--stop-on-fail --> Stops executing the remaining tests on first failure");
lsd::println("--suite --> Regex for running specific suite(s)");
lsd::println("--case --> Regex for running specific test(s)");
lsd::println("--mode=stats --> Executes tests with an alternative policy");
lsd::println("\t---> stats: Print statistics about the tests without running any");
lsd::println("--help | -h --> ~You just used it! :D");
}
auto main(i32 argc, char **argv) -> i32
try
{
auto raw_arguments = lsd::span<char *>(argv, argc);
auto options = Registry::Options {};
for (auto idx = 0; auto &raw_argument : raw_arguments)
{
// First argument is the "cwd'
if (idx++ == 0)
{
continue;
}
auto argument = lsd::str_view(raw_argument);
if (argument == "-h" || argument == "--help")
{
print_help();
return 0;
}
if (argument.starts_with("--") || argument.starts_with("-"))
{
parse_option(argument, options);
}
else
{
throw std::invalid_argument { std::format("Invalid argument: {}", argument) };
}
}
return static_cast<i32>(Registry::run_all(options));
}
catch (const lsd::exception &exp)
{
lt::log::critical("Terminated due to uncaught exception:");
lt::log::critical("\twhat: {}", exp.what());
return 1;
}
catch (...)
{
lt::log::critical("Terminated due to uncaught non-std exception!");
return 1;
}