|
|
36b9abe |
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
|
|
|
36b9abe |
index 7fe4791e..c0af3fd7 100644
|
|
|
36b9abe |
--- a/tests/CMakeLists.txt
|
|
|
36b9abe |
+++ b/tests/CMakeLists.txt
|
|
|
36b9abe |
@@ -13,6 +13,20 @@ if(PkgConfig_FOUND)
|
|
|
36b9abe |
pkg_check_modules(systemd libsystemd)
|
|
|
36b9abe |
endif()
|
|
|
36b9abe |
|
|
|
36b9abe |
+find_package(Catch2 3 QUIET)
|
|
|
36b9abe |
+if (Catch2_FOUND)
|
|
|
36b9abe |
+ message(STATUS "Packaged version of Catch will be used.")
|
|
|
36b9abe |
+else()
|
|
|
36b9abe |
+ message(STATUS "Bundled version of Catch will be downloaded and used.")
|
|
|
36b9abe |
+ include(FetchContent)
|
|
|
36b9abe |
+ FetchContent_Declare(
|
|
|
36b9abe |
+ Catch2
|
|
|
36b9abe |
+ GIT_REPOSITORY https://github.com/catchorg/Catch2.git
|
|
|
36b9abe |
+ GIT_TAG v3.3.2
|
|
|
36b9abe |
+ )
|
|
|
36b9abe |
+ FetchContent_MakeAvailable(Catch2)
|
|
|
36b9abe |
+endif()
|
|
|
36b9abe |
+
|
|
|
36b9abe |
set(SPDLOG_UTESTS_SOURCES
|
|
|
36b9abe |
test_file_helper.cpp
|
|
|
36b9abe |
test_file_logging.cpp
|
|
|
36b9abe |
@@ -52,6 +66,7 @@ function(spdlog_prepare_test test_target spdlog_lib)
|
|
|
36b9abe |
if(systemd_FOUND)
|
|
|
36b9abe |
target_link_libraries(${test_target} PRIVATE ${systemd_LIBRARIES})
|
|
|
36b9abe |
endif()
|
|
|
36b9abe |
+ target_link_libraries(${test_target} PRIVATE Catch2::Catch2WithMain)
|
|
|
36b9abe |
if(SPDLOG_SANITIZE_ADDRESS)
|
|
|
36b9abe |
spdlog_enable_sanitizer(${test_target})
|
|
|
36b9abe |
endif()
|
|
|
36b9abe |
diff --git a/tests/includes.h b/tests/includes.h
|
|
|
36b9abe |
index 16394440..33e88bfb 100644
|
|
|
36b9abe |
--- a/tests/includes.h
|
|
|
36b9abe |
+++ b/tests/includes.h
|
|
|
36b9abe |
@@ -4,7 +4,7 @@
|
|
|
36b9abe |
# pragma GCC diagnostic push
|
|
|
36b9abe |
# pragma GCC diagnostic ignored "-Wmaybe-uninitialized" // Workaround for GCC 12
|
|
|
36b9abe |
#endif
|
|
|
36b9abe |
-#include "catch.hpp"
|
|
|
36b9abe |
+#include <catch2/catch_all.hpp>
|
|
|
36b9abe |
#if defined(__GNUC__) && __GNUC__ == 12
|
|
|
36b9abe |
# pragma GCC diagnostic pop
|
|
|
36b9abe |
#endif
|
|
|
36b9abe |
diff --git a/tests/main.cpp b/tests/main.cpp
|
|
|
36b9abe |
index f8ed5192..c8dca193 100644
|
|
|
36b9abe |
--- a/tests/main.cpp
|
|
|
36b9abe |
+++ b/tests/main.cpp
|
|
|
36b9abe |
@@ -3,8 +3,7 @@
|
|
|
36b9abe |
# pragma GCC diagnostic ignored "-Wmaybe-uninitialized" // Workaround for GCC 12
|
|
|
36b9abe |
#endif
|
|
|
36b9abe |
|
|
|
36b9abe |
-#define CATCH_CONFIG_MAIN
|
|
|
36b9abe |
-#include "catch.hpp"
|
|
|
36b9abe |
+#include <catch2/catch_all.hpp>
|
|
|
36b9abe |
|
|
|
36b9abe |
#if defined(__GNUC__) && __GNUC__ == 12
|
|
|
36b9abe |
# pragma GCC diagnostic pop
|
|
|
36b9abe |
diff --git a/tests/test_daily_logger.cpp b/tests/test_daily_logger.cpp
|
|
|
36b9abe |
index c6e685de..82f28941 100644
|
|
|
36b9abe |
--- a/tests/test_daily_logger.cpp
|
|
|
36b9abe |
+++ b/tests/test_daily_logger.cpp
|
|
|
36b9abe |
@@ -87,19 +87,19 @@ TEST_CASE("daily_logger with custom calculator", "[daily_logger]")
|
|
|
36b9abe |
* File name calculations
|
|
|
36b9abe |
*/
|
|
|
36b9abe |
|
|
|
36b9abe |
-TEST_CASE("rotating_file_sink::calc_filename1", "[rotating_file_sink]]")
|
|
|
36b9abe |
+TEST_CASE("rotating_file_sink::calc_filename1", "[rotating_file_sink]")
|
|
|
36b9abe |
{
|
|
|
36b9abe |
auto filename = spdlog::sinks::rotating_file_sink_st::calc_filename(SPDLOG_FILENAME_T("rotated.txt"), 3);
|
|
|
36b9abe |
REQUIRE(filename == SPDLOG_FILENAME_T("rotated.3.txt"));
|
|
|
36b9abe |
}
|
|
|
36b9abe |
|
|
|
36b9abe |
-TEST_CASE("rotating_file_sink::calc_filename2", "[rotating_file_sink]]")
|
|
|
36b9abe |
+TEST_CASE("rotating_file_sink::calc_filename2", "[rotating_file_sink]")
|
|
|
36b9abe |
{
|
|
|
36b9abe |
auto filename = spdlog::sinks::rotating_file_sink_st::calc_filename(SPDLOG_FILENAME_T("rotated"), 3);
|
|
|
36b9abe |
REQUIRE(filename == SPDLOG_FILENAME_T("rotated.3"));
|
|
|
36b9abe |
}
|
|
|
36b9abe |
|
|
|
36b9abe |
-TEST_CASE("rotating_file_sink::calc_filename3", "[rotating_file_sink]]")
|
|
|
36b9abe |
+TEST_CASE("rotating_file_sink::calc_filename3", "[rotating_file_sink]")
|
|
|
36b9abe |
{
|
|
|
36b9abe |
auto filename = spdlog::sinks::rotating_file_sink_st::calc_filename(SPDLOG_FILENAME_T("rotated.txt"), 0);
|
|
|
36b9abe |
REQUIRE(filename == SPDLOG_FILENAME_T("rotated.txt"));
|
|
|
36b9abe |
@@ -110,7 +110,7 @@ TEST_CASE("rotating_file_sink::calc_filename3", "[rotating_file_sink]]")
|
|
|
36b9abe |
|
|
|
36b9abe |
# include <regex>
|
|
|
36b9abe |
|
|
|
36b9abe |
-TEST_CASE("daily_file_sink::daily_filename_calculator", "[daily_file_sink]]")
|
|
|
36b9abe |
+TEST_CASE("daily_file_sink::daily_filename_calculator", "[daily_file_sink]")
|
|
|
36b9abe |
{
|
|
|
36b9abe |
// daily_YYYY-MM-DD_hh-mm.txt
|
|
|
36b9abe |
auto filename =
|
|
|
36b9abe |
@@ -123,7 +123,7 @@ TEST_CASE("daily_file_sink::daily_filename_calculator", "[daily_file_sink]]")
|
|
|
36b9abe |
}
|
|
|
36b9abe |
#endif
|
|
|
36b9abe |
|
|
|
36b9abe |
-TEST_CASE("daily_file_sink::daily_filename_format_calculator", "[daily_file_sink]]")
|
|
|
36b9abe |
+TEST_CASE("daily_file_sink::daily_filename_format_calculator", "[daily_file_sink]")
|
|
|
36b9abe |
{
|
|
|
36b9abe |
std::tm tm = spdlog::details::os::localtime();
|
|
|
36b9abe |
// example-YYYY-MM-DD.log
|
|
|
36b9abe |
diff --git a/tests/test_errors.cpp b/tests/test_errors.cpp
|
|
|
36b9abe |
index 896e5b0a..939f1aeb 100644
|
|
|
36b9abe |
--- a/tests/test_errors.cpp
|
|
|
36b9abe |
+++ b/tests/test_errors.cpp
|
|
|
36b9abe |
@@ -22,7 +22,7 @@ protected:
|
|
|
36b9abe |
}
|
|
|
36b9abe |
};
|
|
|
36b9abe |
|
|
|
36b9abe |
-TEST_CASE("default_error_handler", "[errors]]")
|
|
|
36b9abe |
+TEST_CASE("default_error_handler", "[errors]")
|
|
|
36b9abe |
{
|
|
|
36b9abe |
prepare_logdir();
|
|
|
36b9abe |
spdlog::filename_t filename = SPDLOG_FILENAME_T(SIMPLE_LOG);
|
|
|
36b9abe |
@@ -40,7 +40,7 @@ TEST_CASE("default_error_handler", "[errors]]")
|
|
|
36b9abe |
|
|
|
36b9abe |
struct custom_ex
|
|
|
36b9abe |
{};
|
|
|
36b9abe |
-TEST_CASE("custom_error_handler", "[errors]]")
|
|
|
36b9abe |
+TEST_CASE("custom_error_handler", "[errors]")
|
|
|
36b9abe |
{
|
|
|
36b9abe |
prepare_logdir();
|
|
|
36b9abe |
spdlog::filename_t filename = SPDLOG_FILENAME_T(SIMPLE_LOG);
|
|
|
36b9abe |
@@ -54,7 +54,7 @@ TEST_CASE("custom_error_handler", "[errors]]")
|
|
|
36b9abe |
require_message_count(SIMPLE_LOG, 2);
|
|
|
36b9abe |
}
|
|
|
36b9abe |
|
|
|
36b9abe |
-TEST_CASE("default_error_handler2", "[errors]]")
|
|
|
36b9abe |
+TEST_CASE("default_error_handler2", "[errors]")
|
|
|
36b9abe |
{
|
|
|
36b9abe |
spdlog::drop_all();
|
|
|
36b9abe |
auto logger = spdlog::create<failing_sink>("failed_logger");
|
|
|
36b9abe |
@@ -62,7 +62,7 @@ TEST_CASE("default_error_handler2", "[errors]]")
|
|
|
36b9abe |
REQUIRE_THROWS_AS(logger->info("Some message"), custom_ex);
|
|
|
36b9abe |
}
|
|
|
36b9abe |
|
|
|
36b9abe |
-TEST_CASE("flush_error_handler", "[errors]]")
|
|
|
36b9abe |
+TEST_CASE("flush_error_handler", "[errors]")
|
|
|
36b9abe |
{
|
|
|
36b9abe |
spdlog::drop_all();
|
|
|
36b9abe |
auto logger = spdlog::create<failing_sink>("failed_logger");
|
|
|
36b9abe |
@@ -70,7 +70,7 @@ TEST_CASE("flush_error_handler", "[errors]]")
|
|
|
36b9abe |
REQUIRE_THROWS_AS(logger->flush(), custom_ex);
|
|
|
36b9abe |
}
|
|
|
36b9abe |
|
|
|
36b9abe |
-TEST_CASE("async_error_handler", "[errors]]")
|
|
|
36b9abe |
+TEST_CASE("async_error_handler", "[errors]")
|
|
|
36b9abe |
{
|
|
|
36b9abe |
prepare_logdir();
|
|
|
36b9abe |
std::string err_msg("log failed with some msg");
|
|
|
36b9abe |
@@ -98,7 +98,7 @@ TEST_CASE("async_error_handler", "[errors]]")
|
|
|
36b9abe |
}
|
|
|
36b9abe |
|
|
|
36b9abe |
// Make sure async error handler is executed
|
|
|
36b9abe |
-TEST_CASE("async_error_handler2", "[errors]]")
|
|
|
36b9abe |
+TEST_CASE("async_error_handler2", "[errors]")
|
|
|
36b9abe |
{
|
|
|
36b9abe |
prepare_logdir();
|
|
|
36b9abe |
std::string err_msg("This is async handler error message");
|
|
|
36b9abe |
diff --git a/tests/test_file_helper.cpp b/tests/test_file_helper.cpp
|
|
|
36b9abe |
index 1d947078..dd3ca4f8 100644
|
|
|
36b9abe |
--- a/tests/test_file_helper.cpp
|
|
|
36b9abe |
+++ b/tests/test_file_helper.cpp
|
|
|
36b9abe |
@@ -15,7 +15,7 @@ static void write_with_helper(file_helper &helper, size_t howmany)
|
|
|
36b9abe |
helper.flush();
|
|
|
36b9abe |
}
|
|
|
36b9abe |
|
|
|
36b9abe |
-TEST_CASE("file_helper_filename", "[file_helper::filename()]]")
|
|
|
36b9abe |
+TEST_CASE("file_helper_filename", "[file_helper::filename()]")
|
|
|
36b9abe |
{
|
|
|
36b9abe |
prepare_logdir();
|
|
|
36b9abe |
|
|
|
36b9abe |
@@ -25,7 +25,7 @@ TEST_CASE("file_helper_filename", "[file_helper::filename()]]")
|
|
|
36b9abe |
REQUIRE(helper.filename() == target_filename);
|
|
|
36b9abe |
}
|
|
|
36b9abe |
|
|
|
36b9abe |
-TEST_CASE("file_helper_size", "[file_helper::size()]]")
|
|
|
36b9abe |
+TEST_CASE("file_helper_size", "[file_helper::size()]")
|
|
|
36b9abe |
{
|
|
|
36b9abe |
prepare_logdir();
|
|
|
36b9abe |
spdlog::filename_t target_filename = SPDLOG_FILENAME_T(TEST_FILENAME);
|
|
|
36b9abe |
@@ -39,7 +39,7 @@ TEST_CASE("file_helper_size", "[file_helper::size()]]")
|
|
|
36b9abe |
REQUIRE(get_filesize(TEST_FILENAME) == expected_size);
|
|
|
36b9abe |
}
|
|
|
36b9abe |
|
|
|
36b9abe |
-TEST_CASE("file_helper_reopen", "[file_helper::reopen()]]")
|
|
|
36b9abe |
+TEST_CASE("file_helper_reopen", "[file_helper::reopen()]")
|
|
|
36b9abe |
{
|
|
|
36b9abe |
prepare_logdir();
|
|
|
36b9abe |
spdlog::filename_t target_filename = SPDLOG_FILENAME_T(TEST_FILENAME);
|
|
|
36b9abe |
@@ -51,7 +51,7 @@ TEST_CASE("file_helper_reopen", "[file_helper::reopen()]]")
|
|
|
36b9abe |
REQUIRE(helper.size() == 0);
|
|
|
36b9abe |
}
|
|
|
36b9abe |
|
|
|
36b9abe |
-TEST_CASE("file_helper_reopen2", "[file_helper::reopen(false)]]")
|
|
|
36b9abe |
+TEST_CASE("file_helper_reopen2", "[file_helper::reopen(false)]")
|
|
|
36b9abe |
{
|
|
|
36b9abe |
prepare_logdir();
|
|
|
36b9abe |
spdlog::filename_t target_filename = SPDLOG_FILENAME_T(TEST_FILENAME);
|
|
|
36b9abe |
@@ -78,7 +78,7 @@ static void test_split_ext(const spdlog::filename_t::value_type *fname, const sp
|
|
|
36b9abe |
REQUIRE(ext == expected_ext);
|
|
|
36b9abe |
}
|
|
|
36b9abe |
|
|
|
36b9abe |
-TEST_CASE("file_helper_split_by_extension", "[file_helper::split_by_extension()]]")
|
|
|
36b9abe |
+TEST_CASE("file_helper_split_by_extension", "[file_helper::split_by_extension()]")
|
|
|
36b9abe |
{
|
|
|
36b9abe |
test_split_ext(SPDLOG_FILENAME_T("mylog.txt"), SPDLOG_FILENAME_T("mylog"), SPDLOG_FILENAME_T(".txt"));
|
|
|
36b9abe |
test_split_ext(SPDLOG_FILENAME_T(".mylog.txt"), SPDLOG_FILENAME_T(".mylog"), SPDLOG_FILENAME_T(".txt"));
|
|
|
36b9abe |
diff --git a/tests/test_file_logging.cpp b/tests/test_file_logging.cpp
|
|
|
36b9abe |
index 1c7a1853..7a7119ad 100644
|
|
|
36b9abe |
--- a/tests/test_file_logging.cpp
|
|
|
36b9abe |
+++ b/tests/test_file_logging.cpp
|
|
|
36b9abe |
@@ -6,7 +6,7 @@
|
|
|
36b9abe |
#define SIMPLE_LOG "test_logs/simple_log"
|
|
|
36b9abe |
#define ROTATING_LOG "test_logs/rotating_log"
|
|
|
36b9abe |
|
|
|
36b9abe |
-TEST_CASE("simple_file_logger", "[simple_logger]]")
|
|
|
36b9abe |
+TEST_CASE("simple_file_logger", "[simple_logger]")
|
|
|
36b9abe |
{
|
|
|
36b9abe |
prepare_logdir();
|
|
|
36b9abe |
spdlog::filename_t filename = SPDLOG_FILENAME_T(SIMPLE_LOG);
|
|
|
36b9abe |
@@ -23,7 +23,7 @@ TEST_CASE("simple_file_logger", "[simple_logger]]")
|
|
|
36b9abe |
REQUIRE(file_contents(SIMPLE_LOG) == spdlog::fmt_lib::format("Test message 1{}Test message 2{}", default_eol, default_eol));
|
|
|
36b9abe |
}
|
|
|
36b9abe |
|
|
|
36b9abe |
-TEST_CASE("flush_on", "[flush_on]]")
|
|
|
36b9abe |
+TEST_CASE("flush_on", "[flush_on]")
|
|
|
36b9abe |
{
|
|
|
36b9abe |
prepare_logdir();
|
|
|
36b9abe |
spdlog::filename_t filename = SPDLOG_FILENAME_T(SIMPLE_LOG);
|
|
|
36b9abe |
@@ -44,7 +44,7 @@ TEST_CASE("flush_on", "[flush_on]]")
|
|
|
36b9abe |
spdlog::fmt_lib::format("Should not be flushed{}Test message 1{}Test message 2{}", default_eol, default_eol, default_eol));
|
|
|
36b9abe |
}
|
|
|
36b9abe |
|
|
|
36b9abe |
-TEST_CASE("rotating_file_logger1", "[rotating_logger]]")
|
|
|
36b9abe |
+TEST_CASE("rotating_file_logger1", "[rotating_logger]")
|
|
|
36b9abe |
{
|
|
|
36b9abe |
prepare_logdir();
|
|
|
36b9abe |
size_t max_size = 1024 * 10;
|
|
|
36b9abe |
@@ -60,7 +60,7 @@ TEST_CASE("rotating_file_logger1", "[rotating_logger]]")
|
|
|
36b9abe |
require_message_count(ROTATING_LOG, 10);
|
|
|
36b9abe |
}
|
|
|
36b9abe |
|
|
|
36b9abe |
-TEST_CASE("rotating_file_logger2", "[rotating_logger]]")
|
|
|
36b9abe |
+TEST_CASE("rotating_file_logger2", "[rotating_logger]")
|
|
|
36b9abe |
{
|
|
|
36b9abe |
prepare_logdir();
|
|
|
36b9abe |
size_t max_size = 1024 * 10;
|
|
|
36b9abe |
@@ -100,7 +100,7 @@ TEST_CASE("rotating_file_logger2", "[rotating_logger]]")
|
|
|
36b9abe |
}
|
|
|
36b9abe |
|
|
|
36b9abe |
// test that passing max_size=0 throws
|
|
|
36b9abe |
-TEST_CASE("rotating_file_logger3", "[rotating_logger]]")
|
|
|
36b9abe |
+TEST_CASE("rotating_file_logger3", "[rotating_logger]")
|
|
|
36b9abe |
{
|
|
|
36b9abe |
prepare_logdir();
|
|
|
36b9abe |
size_t max_size = 0;
|
|
|
36b9abe |
diff --git a/tests/test_macros.cpp b/tests/test_macros.cpp
|
|
|
36b9abe |
index 2aeeecff..36537958 100644
|
|
|
36b9abe |
--- a/tests/test_macros.cpp
|
|
|
36b9abe |
+++ b/tests/test_macros.cpp
|
|
|
36b9abe |
@@ -10,7 +10,7 @@
|
|
|
36b9abe |
|
|
|
36b9abe |
#define TEST_FILENAME "test_logs/simple_log"
|
|
|
36b9abe |
|
|
|
36b9abe |
-TEST_CASE("debug and trace w/o format string", "[macros]]")
|
|
|
36b9abe |
+TEST_CASE("debug and trace w/o format string", "[macros]")
|
|
|
36b9abe |
{
|
|
|
36b9abe |
|
|
|
36b9abe |
prepare_logdir();
|