spdlog/tests/test_loaders.cpp

89 lines
2.6 KiB
C++
Raw Normal View History

2019-12-22 00:52:35 +08:00
#include "includes.h"
#include "test_sink.h"
2019-12-22 01:45:14 +08:00
#include <spdlog/loaders/env.h>
#include <spdlog/loaders/argv.h>
using spdlog::loaders::load_argv;
2019-12-22 01:52:37 +08:00
using spdlog::loaders::load_env;
2019-12-22 00:52:35 +08:00
2019-12-22 01:25:54 +08:00
TEST_CASE("env", "[loaders]")
2019-12-22 00:52:35 +08:00
{
2019-12-22 02:15:18 +08:00
spdlog::drop("l1");
2019-12-22 01:52:37 +08:00
auto l1 = spdlog::create<spdlog::sinks::test_sink_st>("l1");
2019-12-22 14:58:36 +08:00
#ifdef _MSC_VER
2019-12-22 06:17:32 +08:00
_putenv_s("SPDLOG_LEVEL", "l1=warn");
#else
2019-12-22 01:25:54 +08:00
setenv("SPDLOG_LEVEL", "l1=warn", 1);
2019-12-22 06:17:32 +08:00
#endif
2019-12-22 01:45:14 +08:00
load_env();
2019-12-22 01:25:54 +08:00
REQUIRE(l1->level() == spdlog::level::warn);
REQUIRE(spdlog::default_logger()->level() == spdlog::level::info);
2019-12-22 00:52:35 +08:00
}
2019-12-22 01:25:54 +08:00
TEST_CASE("argv1", "[loaders]")
{
2019-12-22 02:15:18 +08:00
spdlog::drop("l1");
2019-12-22 01:52:37 +08:00
const char *argv[] = {"ignore", "SPDLOG_LEVEL=l1=warn"};
2019-12-22 01:59:23 +08:00
load_argv(2, const_cast<char**>(argv));
2019-12-22 01:25:54 +08:00
auto l1 = spdlog::create<spdlog::sinks::test_sink_st>("l1");
REQUIRE(l1->level() == spdlog::level::warn);
REQUIRE(spdlog::default_logger()->level() == spdlog::level::info);
}
TEST_CASE("argv2", "[loaders]")
{
2019-12-22 02:15:18 +08:00
spdlog::drop("l1");
2019-12-22 01:52:37 +08:00
const char *argv[] = {"ignore", "SPDLOG_LEVEL=l1=warn,trace"};
2019-12-22 01:59:23 +08:00
load_argv(2, const_cast<char**>(argv));
2019-12-22 01:25:54 +08:00
auto l1 = spdlog::create<spdlog::sinks::test_sink_st>("l1");
REQUIRE(l1->level() == spdlog::level::warn);
REQUIRE(spdlog::default_logger()->level() == spdlog::level::trace);
}
TEST_CASE("argv3", "[loaders]")
{
2019-12-22 02:15:18 +08:00
spdlog::drop("l1");
2019-12-22 01:52:37 +08:00
const char *argv[] = {"ignore", "SPDLOG_LEVEL="};
2019-12-22 01:59:23 +08:00
load_argv(2, const_cast<char**>(argv));
2019-12-22 01:25:54 +08:00
auto l1 = spdlog::create<spdlog::sinks::test_sink_st>("l1");
REQUIRE(l1->level() == spdlog::level::info);
REQUIRE(spdlog::default_logger()->level() == spdlog::level::info);
}
TEST_CASE("argv4", "[loaders]")
{
2019-12-22 02:15:18 +08:00
spdlog::drop("l1");
2019-12-22 01:52:37 +08:00
const char *argv[] = {"ignore", "SPDLOG_LEVEL=junk"};
2019-12-22 01:59:23 +08:00
load_argv(2, const_cast<char**>(argv));
2019-12-22 01:25:54 +08:00
auto l1 = spdlog::create<spdlog::sinks::test_sink_st>("l1");
REQUIRE(l1->level() == spdlog::level::info);
}
2019-12-22 02:01:25 +08:00
TEST_CASE("argv5", "[loaders]")
{
2019-12-22 02:15:18 +08:00
spdlog::drop("l1");
2019-12-22 02:01:25 +08:00
const char *argv[] = {"ignore", "ignore", "SPDLOG_LEVEL=l1=warn,trace"};
load_argv(3, const_cast<char**>(argv));
auto l1 = spdlog::create<spdlog::sinks::test_sink_st>("l1");
REQUIRE(l1->level() == spdlog::level::warn);
REQUIRE(spdlog::default_logger()->level() == spdlog::level::trace);
2019-12-22 02:15:18 +08:00
}
TEST_CASE("argv6", "[loaders]")
{
spdlog::set_level(spdlog::level::err);
const char *argv[] = {""};
load_argv(1, const_cast<char**>(argv));
REQUIRE(spdlog::default_logger()->level() == spdlog::level::err);
}
TEST_CASE("argv7", "[loaders]")
{
spdlog::set_level(spdlog::level::err);
const char *argv[] = {""};
load_argv(0, const_cast<char**>(argv));
REQUIRE(spdlog::default_logger()->level() == spdlog::level::err);
2019-12-22 02:01:25 +08:00
}