2019-12-22 00:52:35 +08:00
|
|
|
#include "includes.h"
|
|
|
|
#include "test_sink.h"
|
|
|
|
|
2019-12-23 02:40:19 +08:00
|
|
|
#include <spdlog/cfg/env.h>
|
|
|
|
#include <spdlog/cfg/argv.h>
|
2019-12-22 01:45:14 +08:00
|
|
|
|
2019-12-23 02:40:19 +08:00
|
|
|
using spdlog::cfg::load_argv;
|
|
|
|
using spdlog::cfg::load_env;
|
2019-12-23 04:33:19 +08:00
|
|
|
using spdlog::sinks::test_sink_st;
|
2019-12-22 00:52:35 +08:00
|
|
|
|
2019-12-23 02:40:19 +08:00
|
|
|
TEST_CASE("env", "[cfg]")
|
2019-12-22 00:52:35 +08:00
|
|
|
{
|
2019-12-22 02:15:18 +08:00
|
|
|
spdlog::drop("l1");
|
2019-12-23 04:33:19 +08:00
|
|
|
auto l1 = spdlog::create<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);
|
2019-12-23 04:33:19 +08:00
|
|
|
spdlog::set_default_logger(spdlog::create<test_sink_st>("cfg-default"));
|
2019-12-22 01:25:54 +08:00
|
|
|
REQUIRE(spdlog::default_logger()->level() == spdlog::level::info);
|
2019-12-22 00:52:35 +08:00
|
|
|
}
|
|
|
|
|
2019-12-23 02:40:19 +08:00
|
|
|
TEST_CASE("argv1", "[cfg]")
|
2019-12-22 01:25:54 +08:00
|
|
|
{
|
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);
|
|
|
|
}
|
|
|
|
|
2019-12-23 02:40:19 +08:00
|
|
|
TEST_CASE("argv2", "[cfg]")
|
2019-12-22 01:25:54 +08:00
|
|
|
{
|
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-23 04:33:19 +08:00
|
|
|
auto l1 = spdlog::create<test_sink_st>("l1");
|
2019-12-22 01:25:54 +08:00
|
|
|
REQUIRE(l1->level() == spdlog::level::warn);
|
|
|
|
REQUIRE(spdlog::default_logger()->level() == spdlog::level::trace);
|
2019-12-23 04:33:19 +08:00
|
|
|
spdlog::set_level(spdlog::level::info);
|
2019-12-22 01:25:54 +08:00
|
|
|
}
|
|
|
|
|
2019-12-23 02:40:19 +08:00
|
|
|
TEST_CASE("argv3", "[cfg]")
|
2019-12-22 01:25:54 +08:00
|
|
|
{
|
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-23 04:33:19 +08:00
|
|
|
auto l1 = spdlog::create<test_sink_st>("l1");
|
2019-12-22 01:25:54 +08:00
|
|
|
REQUIRE(l1->level() == spdlog::level::info);
|
|
|
|
REQUIRE(spdlog::default_logger()->level() == spdlog::level::info);
|
|
|
|
}
|
|
|
|
|
2019-12-23 02:40:19 +08:00
|
|
|
TEST_CASE("argv4", "[cfg]")
|
2019-12-22 01:25:54 +08:00
|
|
|
{
|
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-23 04:33:19 +08:00
|
|
|
auto l1 = spdlog::create<test_sink_st>("l1");
|
2019-12-22 01:25:54 +08:00
|
|
|
REQUIRE(l1->level() == spdlog::level::info);
|
|
|
|
}
|
2019-12-22 02:01:25 +08:00
|
|
|
|
2019-12-23 02:40:19 +08:00
|
|
|
TEST_CASE("argv5", "[cfg]")
|
2019-12-22 02:01:25 +08:00
|
|
|
{
|
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));
|
2019-12-23 04:33:19 +08:00
|
|
|
auto l1 = spdlog::create<test_sink_st>("l1");
|
2019-12-22 02:01:25 +08:00
|
|
|
REQUIRE(l1->level() == spdlog::level::warn);
|
|
|
|
REQUIRE(spdlog::default_logger()->level() == spdlog::level::trace);
|
2019-12-23 04:33:19 +08:00
|
|
|
spdlog::set_level(spdlog::level::info);
|
2019-12-22 02:15:18 +08:00
|
|
|
}
|
|
|
|
|
2019-12-23 02:40:19 +08:00
|
|
|
TEST_CASE("argv6", "[cfg]")
|
2019-12-22 02:15:18 +08:00
|
|
|
{
|
|
|
|
spdlog::set_level(spdlog::level::err);
|
|
|
|
const char *argv[] = {""};
|
|
|
|
load_argv(1, const_cast<char**>(argv));
|
|
|
|
REQUIRE(spdlog::default_logger()->level() == spdlog::level::err);
|
2019-12-23 04:33:19 +08:00
|
|
|
spdlog::set_level(spdlog::level::info);
|
2019-12-22 02:15:18 +08:00
|
|
|
}
|
|
|
|
|
2019-12-23 02:40:19 +08:00
|
|
|
TEST_CASE("argv7", "[cfg]")
|
2019-12-22 02:15:18 +08:00
|
|
|
{
|
|
|
|
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-23 04:33:19 +08:00
|
|
|
spdlog::set_level(spdlog::level::info);
|
2019-12-22 02:01:25 +08:00
|
|
|
}
|