2021-03-01 21:07:32 +00:00
|
|
|
#include <catch2/catch.hpp>
|
2023-01-09 17:47:41 +00:00
|
|
|
#include <llarp/util/logging.hpp>
|
|
|
|
#include <llarp/config/config.hpp>
|
2022-07-19 16:19:35 +00:00
|
|
|
#include <oxen/log/level.hpp>
|
2020-01-21 18:21:11 +00:00
|
|
|
|
2020-01-21 18:35:52 +00:00
|
|
|
using TestString = std::string;
|
|
|
|
|
|
|
|
struct TestParseLog
|
|
|
|
{
|
|
|
|
TestString input;
|
2022-07-18 15:59:13 +00:00
|
|
|
std::optional<llarp::log::Level> level;
|
2020-01-21 18:35:52 +00:00
|
|
|
};
|
|
|
|
|
2021-03-01 21:07:32 +00:00
|
|
|
std::vector<TestParseLog> testParseLog{// bad cases
|
|
|
|
{"bogus", {}},
|
|
|
|
{"BOGUS", {}},
|
|
|
|
{"", {}},
|
|
|
|
{" ", {}},
|
2022-07-18 15:59:13 +00:00
|
|
|
{"infogarbage", {}},
|
|
|
|
{"notcritical", {}},
|
2021-03-01 21:07:32 +00:00
|
|
|
// good cases
|
2022-07-18 15:59:13 +00:00
|
|
|
{"info", llarp::log::Level::info},
|
|
|
|
{"infO", llarp::log::Level::info},
|
|
|
|
{"iNfO", llarp::log::Level::info},
|
|
|
|
{"InfO", llarp::log::Level::info},
|
|
|
|
{"INFO", llarp::log::Level::info},
|
|
|
|
{"trace", llarp::log::Level::trace},
|
|
|
|
{"debug", llarp::log::Level::debug},
|
|
|
|
{"warn", llarp::log::Level::warn},
|
|
|
|
{"warning", llarp::log::Level::warn},
|
|
|
|
{"error", llarp::log::Level::err},
|
|
|
|
{"err", llarp::log::Level::err},
|
|
|
|
{"Critical", llarp::log::Level::critical},
|
|
|
|
{"off", llarp::log::Level::off},
|
|
|
|
{"none", llarp::log::Level::off}};
|
2021-03-01 21:07:32 +00:00
|
|
|
|
|
|
|
TEST_CASE("parseLevel")
|
2020-01-21 18:21:11 +00:00
|
|
|
{
|
2022-07-19 16:19:35 +00:00
|
|
|
const auto& [input, expected] = GENERATE(from_range(testParseLog));
|
|
|
|
|
|
|
|
if (not expected)
|
|
|
|
REQUIRE_THROWS_AS(llarp::log::level_from_string(input), std::invalid_argument);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
llarp::log::Level level;
|
|
|
|
REQUIRE_NOTHROW(level = llarp::log::level_from_string(input));
|
|
|
|
CHECK(level == *expected);
|
|
|
|
}
|
2020-01-21 18:21:11 +00:00
|
|
|
}
|
2020-01-21 18:35:52 +00:00
|
|
|
|
2021-03-01 21:07:32 +00:00
|
|
|
TEST_CASE("TestLogLevelToString")
|
2020-01-21 19:15:04 +00:00
|
|
|
{
|
2022-07-18 15:59:13 +00:00
|
|
|
CHECK("trace" == llarp::log::to_string(llarp::log::Level::trace));
|
|
|
|
CHECK("debug" == llarp::log::to_string(llarp::log::Level::debug));
|
|
|
|
CHECK("info" == llarp::log::to_string(llarp::log::Level::info));
|
|
|
|
CHECK("warning" == llarp::log::to_string(llarp::log::Level::warn));
|
|
|
|
CHECK("error" == llarp::log::to_string(llarp::log::Level::err));
|
|
|
|
CHECK("critical" == llarp::log::to_string(llarp::log::Level::critical));
|
|
|
|
CHECK("off" == llarp::log::to_string(llarp::log::Level::off));
|
2020-01-21 19:15:04 +00:00
|
|
|
}
|