2017-10-13 07:04:31 +08:00
|
|
|
/*
|
2018-03-09 21:26:33 +08:00
|
|
|
* This content is released under the MIT License as specified in https://raw.githubusercontent.com/gabime/spdlog/master/LICENSE
|
|
|
|
*/
|
2017-10-13 07:04:31 +08:00
|
|
|
|
|
|
|
#include "includes.h"
|
|
|
|
|
2018-11-12 00:15:24 +08:00
|
|
|
#if SPDLOG_ACTIVE_LEVEL != SPDLOG_LEVEL_DEBUG
|
|
|
|
#error "Invalid SPDLOG_ACTIVE_LEVEL in test. Should be SPDLOG_LEVEL_DEBUG"
|
|
|
|
#endif
|
|
|
|
|
2017-10-13 07:04:31 +08:00
|
|
|
TEST_CASE("debug and trace w/o format string", "[macros]]")
|
|
|
|
{
|
2018-11-12 00:15:24 +08:00
|
|
|
|
2017-11-06 18:39:04 +08:00
|
|
|
prepare_logdir();
|
|
|
|
std::string filename = "logs/simple_log";
|
|
|
|
|
2018-07-07 17:12:45 +08:00
|
|
|
auto logger = spdlog::create<spdlog::sinks::basic_file_sink_mt>("logger", filename);
|
2017-11-06 18:39:04 +08:00
|
|
|
logger->set_pattern("%v");
|
|
|
|
logger->set_level(spdlog::level::trace);
|
|
|
|
|
2018-11-12 00:15:24 +08:00
|
|
|
SPDLOG_LOGGER_TRACE(logger, "Test message 1");
|
|
|
|
SPDLOG_LOGGER_DEBUG(logger, "Test message 2");
|
2017-11-06 18:39:04 +08:00
|
|
|
logger->flush();
|
|
|
|
|
|
|
|
REQUIRE(ends_with(file_contents(filename), "Test message 2\n"));
|
2018-11-12 00:15:24 +08:00
|
|
|
REQUIRE(count_lines(filename) == 1);
|
2017-10-13 07:04:31 +08:00
|
|
|
}
|
|
|
|
|
2018-11-12 00:15:24 +08:00
|
|
|
TEST_CASE("disable param evaluation", "[macros]")
|
2017-10-13 07:04:31 +08:00
|
|
|
{
|
2018-11-12 00:15:24 +08:00
|
|
|
SPDLOG_TRACE("Test message {}", throw std::runtime_error("Should not be evaluated"));
|
2017-10-13 07:04:31 +08:00
|
|
|
}
|