diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index fc6f2a79..d53eb9c8 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -45,7 +45,8 @@ set(SPDLOG_UTESTS_SOURCES test_time_point.cpp test_stopwatch.cpp test_circular_q.cpp - test_ringbuffer_sink.cpp) + test_ringbuffer_sink.cpp + test_source_location.cpp) if(NOT SPDLOG_NO_EXCEPTIONS) list(APPEND SPDLOG_UTESTS_SOURCES test_errors.cpp) diff --git a/tests/test_errors.cpp b/tests/test_errors.cpp index 78032482..5062e2b7 100644 --- a/tests/test_errors.cpp +++ b/tests/test_errors.cpp @@ -71,7 +71,7 @@ TEST_CASE("flush_error_handler", "[errors]") REQUIRE_THROWS_AS(logger->flush(), custom_ex); } -#if !defined(SPDLOG_USE_STD_FORMAT) + TEST_CASE("async_error_handler", "[errors]") { prepare_logdir(); @@ -98,7 +98,7 @@ TEST_CASE("async_error_handler", "[errors]") require_message_count(SIMPLE_ASYNC_LOG, 2); REQUIRE(file_contents("test_logs/custom_err.txt") == err_msg); } -#endif + // Make sure async error handler is executed TEST_CASE("async_error_handler2", "[errors]") diff --git a/tests/test_source_location.cpp b/tests/test_source_location.cpp new file mode 100644 index 00000000..8e1d5ae5 --- /dev/null +++ b/tests/test_source_location.cpp @@ -0,0 +1,21 @@ +#define SPDLOG_USE_SOURCE_LOCATION +#include "includes.h" +#include "test_sink.h" + +#if defined(SPDLOG_STD_SOURCE_LOCATION) || defined(SPDLOG_EXPERIMENTAL_SOURCE_LOCATION) + +using spdlog::details::os::default_eol; + +TEST_CASE("test_source_location", "[source_location]") +{ + std::ostringstream oss; + auto oss_sink = std::make_shared(oss); + spdlog::logger oss_logger("oss", oss_sink); + oss_logger.set_pattern("%s:%# %v"); + + oss_logger.info("Hello {}", "source location"); + REQUIRE(oss.str() == std::string("test_source_location.cpp:16 Hello source location") + default_eol); +} + +#endif +