Revert 7f15fb2a21 since it breaks the ABI

This commit is contained in:
gabime
2020-06-07 14:38:16 +03:00
parent 7f15fb2a21
commit a0dae55a69
5 changed files with 73 additions and 205 deletions

View File

@@ -2,47 +2,46 @@ cmake_minimum_required(VERSION 3.2)
project(spdlog_utests CXX)
if(NOT TARGET spdlog)
if (NOT TARGET spdlog)
# Stand-alone build
find_package(spdlog REQUIRED)
endif()
endif ()
include(../cmake/utils.cmake)
find_package(PkgConfig)
if(PkgConfig_FOUND)
if (PkgConfig_FOUND)
pkg_check_modules(systemd libsystemd)
endif()
endif ()
set(SPDLOG_UTESTS_SOURCES
test_file_helper.cpp
test_file_logging.cpp
test_daily_logger.cpp
test_rotating_logger.cpp
test_misc.cpp
test_eventlog.cpp
test_pattern_formatter.cpp
test_async.cpp
test_registry.cpp
test_macros.cpp
utils.cpp
main.cpp
test_mpmc_q.cpp
test_dup_filter.cpp
test_fmt_helper.cpp
test_stdout_api.cpp
test_backtrace.cpp
test_create_dir.cpp
test_cfg.cpp
test_time_point.cpp)
test_file_helper.cpp
test_file_logging.cpp
test_daily_logger.cpp
test_misc.cpp
test_eventlog.cpp
test_pattern_formatter.cpp
test_async.cpp
test_registry.cpp
test_macros.cpp
utils.cpp
main.cpp
test_mpmc_q.cpp
test_dup_filter.cpp
test_fmt_helper.cpp
test_stdout_api.cpp
test_backtrace.cpp
test_create_dir.cpp
test_cfg.cpp
test_time_point.cpp)
if(NOT SPDLOG_NO_EXCEPTIONS)
if (NOT SPDLOG_NO_EXCEPTIONS)
list(APPEND SPDLOG_UTESTS_SOURCES test_errors.cpp)
endif()
endif ()
if(systemd_FOUND)
if (systemd_FOUND)
list(APPEND SPDLOG_UTESTS_SOURCES test_systemd.cpp)
endif()
endif ()
enable_testing()
@@ -50,22 +49,22 @@ function(spdlog_prepare_test test_target spdlog_lib)
add_executable(${test_target} ${SPDLOG_UTESTS_SOURCES})
spdlog_enable_warnings(${test_target})
target_link_libraries(${test_target} PRIVATE ${spdlog_lib})
if(systemd_FOUND)
if (systemd_FOUND)
target_link_libraries(${test_target} PRIVATE ${systemd_LIBRARIES})
endif()
if(SPDLOG_SANITIZE_ADDRESS)
endif ()
if (SPDLOG_SANITIZE_ADDRESS)
spdlog_enable_sanitizer(${test_target})
endif()
endif ()
add_test(NAME ${test_target} COMMAND ${test_target})
set_tests_properties(${test_target} PROPERTIES RUN_SERIAL ON)
endfunction()
# The compiled library tests
if(SPDLOG_BUILD_TESTS OR SPDLOG_BUILD_ALL)
if (SPDLOG_BUILD_TESTS OR SPDLOG_BUILD_ALL)
spdlog_prepare_test(spdlog-utests spdlog::spdlog)
endif()
endif ()
# The header-only library version tests
if(SPDLOG_BUILD_TESTS_HO OR SPDLOG_BUILD_ALL)
if (SPDLOG_BUILD_TESTS_HO OR SPDLOG_BUILD_ALL)
spdlog_prepare_test(spdlog-utests-ho spdlog::spdlog_header_only)
endif()
endif ()

View File

@@ -61,6 +61,28 @@ TEST_CASE("daily_logger with custom calculator", "[daily_logger]")
require_message_count(filename, 10);
}
/*
* File name calculations
*/
TEST_CASE("rotating_file_sink::calc_filename1", "[rotating_file_sink]]")
{
auto filename = spdlog::sinks::rotating_file_sink_st::calc_filename("rotated.txt", 3);
REQUIRE(filename == "rotated.3.txt");
}
TEST_CASE("rotating_file_sink::calc_filename2", "[rotating_file_sink]]")
{
auto filename = spdlog::sinks::rotating_file_sink_st::calc_filename("rotated", 3);
REQUIRE(filename == "rotated.3");
}
TEST_CASE("rotating_file_sink::calc_filename3", "[rotating_file_sink]]")
{
auto filename = spdlog::sinks::rotating_file_sink_st::calc_filename("rotated.txt", 0);
REQUIRE(filename == "rotated.txt");
}
// regex supported only from gcc 4.9 and above
#if defined(_MSC_VER) || !(__GNUC__ <= 4 && __GNUC_MINOR__ < 9)

View File

@@ -1,77 +0,0 @@
/*
* This content is released under the MIT License as specified in https://raw.githubusercontent.com/gabime/spdlog/master/LICENSE
*/
#include "includes.h"
TEST_CASE("rotating_looger with default calculator", "[rotating_logger]")
{
using sink_type = spdlog::sinks::rotating_file_sink<std::mutex, spdlog::sinks::rotating_filename_calculator>;
prepare_logdir();
std::string filename = "test_logs/rotating_default";
auto logger = spdlog::create<sink_type>("logger", filename, 5 * 1024, 1);
for (int i = 0; i < 10; ++i)
{
logger->info("Hello World!", i);
}
logger->flush();
require_message_count(filename, 10);
}
struct custom_rotating_file_name_calculator
{
static spdlog::filename_t calc_filename(const spdlog::filename_t &filename, std::size_t)
{
spdlog::filename_t basename, ext;
std::tie(basename, ext) = spdlog::details::file_helper::split_by_extension(filename);
return fmt::format(SPDLOG_FILENAME_T("{}_custom{}"), basename, ext);
}
};
TEST_CASE("rotating_logger with custom calculator", "[rotating_logger]")
{
using sink_type = spdlog::sinks::rotating_file_sink<std::mutex, custom_rotating_file_name_calculator>;
prepare_logdir();
// calculate filename
std::string basename = "test_logs/rotating";
spdlog::memory_buf_t w;
fmt::format_to(w, "{}_custom", basename);
auto logger = spdlog::create<sink_type>("logger", basename, 5 * 1024, 1);
for (int i = 0; i < 10; ++i)
{
logger->info("Hello World!");
}
logger->flush();
auto filename = fmt::to_string(w);
require_message_count(filename, 10);
}
/*
* File name calculations
*/
TEST_CASE("rotating_file_sink::calc_filename1", "[rotating_file_sink]]")
{
auto filename = spdlog::sinks::rotating_filename_calculator::calc_filename("rotated.txt", 3);
REQUIRE(filename == "rotated.3.txt");
}
TEST_CASE("rotating_file_sink::calc_filename2", "[rotating_file_sink]]")
{
auto filename = spdlog::sinks::rotating_filename_calculator::calc_filename("rotated", 3);
REQUIRE(filename == "rotated.3");
}
TEST_CASE("rotating_file_sink::calc_filename3", "[rotating_file_sink]]")
{
auto filename = spdlog::sinks::rotating_filename_calculator::calc_filename("rotated.txt", 0);
REQUIRE(filename == "rotated.txt");
}