Added source_location tests

This commit is contained in:
gabime 2023-09-16 01:06:21 +03:00
parent 5ae1ace844
commit 767ef493f7
3 changed files with 25 additions and 3 deletions

View File

@ -45,7 +45,8 @@ set(SPDLOG_UTESTS_SOURCES
test_time_point.cpp test_time_point.cpp
test_stopwatch.cpp test_stopwatch.cpp
test_circular_q.cpp test_circular_q.cpp
test_ringbuffer_sink.cpp) test_ringbuffer_sink.cpp
test_source_location.cpp)
if(NOT SPDLOG_NO_EXCEPTIONS) if(NOT SPDLOG_NO_EXCEPTIONS)
list(APPEND SPDLOG_UTESTS_SOURCES test_errors.cpp) list(APPEND SPDLOG_UTESTS_SOURCES test_errors.cpp)

View File

@ -71,7 +71,7 @@ TEST_CASE("flush_error_handler", "[errors]")
REQUIRE_THROWS_AS(logger->flush(), custom_ex); REQUIRE_THROWS_AS(logger->flush(), custom_ex);
} }
#if !defined(SPDLOG_USE_STD_FORMAT)
TEST_CASE("async_error_handler", "[errors]") TEST_CASE("async_error_handler", "[errors]")
{ {
prepare_logdir(); prepare_logdir();
@ -98,7 +98,7 @@ TEST_CASE("async_error_handler", "[errors]")
require_message_count(SIMPLE_ASYNC_LOG, 2); require_message_count(SIMPLE_ASYNC_LOG, 2);
REQUIRE(file_contents("test_logs/custom_err.txt") == err_msg); REQUIRE(file_contents("test_logs/custom_err.txt") == err_msg);
} }
#endif
// Make sure async error handler is executed // Make sure async error handler is executed
TEST_CASE("async_error_handler2", "[errors]") TEST_CASE("async_error_handler2", "[errors]")

View File

@ -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<spdlog::sinks::ostream_sink_st>(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