mirror of
https://github.com/gabime/spdlog.git
synced 2024-11-15 16:35:45 +08:00
added loaders tests
This commit is contained in:
parent
28e334c728
commit
e13e978af4
@ -22,7 +22,7 @@ namespace spdlog {
|
||||
namespace cfg {
|
||||
namespace argv {
|
||||
// search for SPDLOG_LEVEL= in the args and use it to init the levels
|
||||
void load_levels(int args, char *argv[])
|
||||
void load_levels(int args, const char *argv[])
|
||||
{
|
||||
const std::string spdlog_level_prefix = "SPDLOG_LEVEL=";
|
||||
for (int i = 1; i < args; i++)
|
||||
|
@ -11,8 +11,7 @@ namespace spdlog {
|
||||
namespace cfg {
|
||||
class log_levels
|
||||
{
|
||||
using levels_map = std::unordered_map<std::string, spdlog::level::level_enum>;
|
||||
levels_map levels_;
|
||||
std::unordered_map<std::string, spdlog::level::level_enum> levels_;
|
||||
spdlog::level::level_enum default_level_ = level::info;
|
||||
|
||||
public:
|
||||
|
@ -23,7 +23,8 @@ set(SPDLOG_UTESTS_SOURCES
|
||||
test_fmt_helper.cpp
|
||||
test_stdout_api.cpp
|
||||
test_backtrace.cpp
|
||||
test_create_dir.cpp)
|
||||
test_create_dir.cpp
|
||||
test_cfg.cpp)
|
||||
|
||||
if(NOT SPDLOG_NO_EXCEPTIONS)
|
||||
list(APPEND SPDLOG_UTESTS_SOURCES test_errors.cpp)
|
||||
|
@ -11,6 +11,7 @@
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <iomanip>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define SPDLOG_ACTIVE_LEVEL SPDLOG_LEVEL_DEBUG
|
||||
|
||||
|
@ -14,7 +14,8 @@ test_sources = files([
|
||||
'test_fmt_helper.cpp',
|
||||
'test_stdout_api.cpp',
|
||||
'test_backtrace.cpp',
|
||||
'test_create_dir.cpp'
|
||||
'test_create_dir.cpp',
|
||||
'test_cfg.cpp',
|
||||
])
|
||||
|
||||
if not get_option('no_exceptions')
|
||||
|
@ -2,9 +2,56 @@
|
||||
#include "test_sink.h"
|
||||
|
||||
#include <spdlog/cfg/env.h>
|
||||
#include <spdlog/cfg/argv.h>
|
||||
|
||||
TEST_CASE("env", "[cfg]")
|
||||
TEST_CASE("env", "[loaders]")
|
||||
{
|
||||
spdlog::logger l{"l1"};
|
||||
auto l1 = spdlog::create<spdlog::sinks::test_sink_st >("l1");
|
||||
setenv("SPDLOG_LEVEL", "l1=warn", 1);
|
||||
spdlog::cfg::env::load_levels();
|
||||
REQUIRE(l1->level() == spdlog::level::warn);
|
||||
REQUIRE(spdlog::default_logger()->level() == spdlog::level::info);
|
||||
spdlog::drop(l1->name());
|
||||
}
|
||||
|
||||
TEST_CASE("argv1", "[loaders]")
|
||||
{
|
||||
const char* argv[] = {"ignore", "SPDLOG_LEVEL=l1=warn"};
|
||||
spdlog::cfg::argv::load_levels(2, argv);
|
||||
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]")
|
||||
{
|
||||
const char* argv[] = {"ignore", "SPDLOG_LEVEL=l1=warn,trace"};
|
||||
spdlog::cfg::argv::load_levels(2, 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);
|
||||
spdlog::drop(l1->name());
|
||||
}
|
||||
|
||||
TEST_CASE("argv3", "[loaders]")
|
||||
{
|
||||
const char* argv[] = {"ignore", "SPDLOG_LEVEL="};
|
||||
spdlog::cfg::argv::load_levels(2, argv);
|
||||
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]")
|
||||
{
|
||||
const char* argv[] = {"ignore", "SPDLOG_LEVEL=junk"};
|
||||
spdlog::cfg::argv::load_levels(2, argv);
|
||||
auto l1 = spdlog::create<spdlog::sinks::test_sink_st>("l1");
|
||||
REQUIRE(l1->level() == spdlog::level::info);
|
||||
spdlog::drop(l1->name());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user