mirror of
https://github.com/gabime/spdlog.git
synced 2025-11-16 09:28:56 +08:00
Added no source location tests and fixed source location tests
This commit is contained in:
@@ -1,21 +1,25 @@
|
||||
#ifndef SPDLOG_NO_SOURCE_LOC
|
||||
#ifdef SPDLOG_NO_SOURCE_LOC
|
||||
#undef SPDLOG_NO_SOURCE_LOC
|
||||
#endif
|
||||
|
||||
#include "includes.h"
|
||||
#include "spdlog/sinks/ostream_sink.h"
|
||||
#include "test_sink.h"
|
||||
|
||||
|
||||
using spdlog::details::os::default_eol;
|
||||
|
||||
// test with source location
|
||||
TEST_CASE("test_source_location", "[source_location]") {
|
||||
std::ostringstream oss;
|
||||
auto oss_sink = std::make_shared<spdlog::sinks::ostream_sink_st>(oss);
|
||||
auto oss_logger = std::make_shared<spdlog::logger>("oss", oss_sink);
|
||||
//spdlog::logger oss_logger("oss", oss_sink);
|
||||
oss_logger->set_pattern("%s:%# %v");
|
||||
|
||||
SPDLOG_LOGGER_CALL(oss_logger, spdlog::level::info, "Hello {}", "source location");
|
||||
REQUIRE(oss.str() == std::string("test_source_location.cpp:17 Hello source location") + default_eol);
|
||||
auto test_sink = std::make_shared<spdlog::sinks::test_sink_mt>();
|
||||
auto logger = std::make_shared<spdlog::logger>("test", test_sink);
|
||||
logger->set_pattern("%s:%# %v");
|
||||
// test with source location with parameters
|
||||
SPDLOG_LOGGER_CALL(logger, spdlog::level::info, "Hello {}", "source location");
|
||||
REQUIRE(test_sink->lines().size() == 1);
|
||||
REQUIRE(test_sink->lines()[0] == "test_source_location.cpp:14 Hello source location");
|
||||
// test with source location without parameters
|
||||
SPDLOG_LOGGER_CALL(logger, spdlog::level::info, "Hello");
|
||||
REQUIRE(test_sink->lines().size() == 2);
|
||||
REQUIRE(test_sink->lines()[1] == "test_source_location.cpp:18 Hello");
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
//REQUIRE(oss.str() == std::string("test_source_location.cpp:20 Hello source location") + default_eol);
|
||||
|
||||
Reference in New Issue
Block a user