import logger; import test.test; import test.registry; import lsd; using namespace ::lt; using namespace ::lt::test; constexpr lsd::str_view operator""_sv(const char *str, unsigned long len) noexcept { return lsd::str_view { str, len }; } 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"_sv) { options.stop_on_fail = true; return; } if (argument.starts_with("--mode="_sv) && 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(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(Registry::run_all(options)); } catch (const std::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; }