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 01:52:37 +08:00
|
|
|
auto l1 = spdlog::create<spdlog::sinks::test_sink_st>("l1");
|
2019-12-22 01:25:54 +08:00
|
|
|
setenv("SPDLOG_LEVEL", "l1=warn", 1);
|
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);
|
|
|
|
spdlog::drop(l1->name());
|
2019-12-22 00:52:35 +08:00
|
|
|
}
|
|
|
|
|
2019-12-22 01:25:54 +08:00
|
|
|
TEST_CASE("argv1", "[loaders]")
|
|
|
|
{
|
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);
|
|
|
|
spdlog::drop(l1->name());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE("argv2", "[loaders]")
|
|
|
|
{
|
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);
|
|
|
|
spdlog::drop(l1->name());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE("argv3", "[loaders]")
|
|
|
|
{
|
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);
|
|
|
|
spdlog::drop(l1->name());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE("argv4", "[loaders]")
|
|
|
|
{
|
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);
|
|
|
|
spdlog::drop(l1->name());
|
|
|
|
}
|