update spdlog
This commit is contained in:
46
third_party/spdlog/tests/CMakeLists.txt
vendored
46
third_party/spdlog/tests/CMakeLists.txt
vendored
@ -14,18 +14,16 @@ set(SPDLOG_UTESTS_SOURCES
|
||||
test_misc.cpp
|
||||
test_pattern_formatter.cpp
|
||||
test_async.cpp
|
||||
includes.h
|
||||
test_registry.cpp
|
||||
test_macros.cpp
|
||||
utils.cpp
|
||||
utils.h
|
||||
main.cpp
|
||||
test_mpmc_q.cpp
|
||||
test_sink.h
|
||||
test_dup_filter.cpp
|
||||
test_fmt_helper.cpp
|
||||
test_stdout_api.cpp
|
||||
test_dup_filter.cpp
|
||||
test_backtrace.cpp)
|
||||
test_backtrace.cpp
|
||||
test_create_dir.cpp)
|
||||
|
||||
if(NOT SPDLOG_NO_EXCEPTIONS)
|
||||
list(APPEND SPDLOG_UTESTS_SOURCES test_errors.cpp)
|
||||
@ -35,34 +33,28 @@ if(systemd_FOUND)
|
||||
list(APPEND SPDLOG_UTESTS_SOURCES test_systemd.cpp)
|
||||
endif()
|
||||
|
||||
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/logs")
|
||||
|
||||
enable_testing()
|
||||
|
||||
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)
|
||||
target_link_libraries(${test_target} PRIVATE ${systemd_LIBRARIES})
|
||||
endif()
|
||||
if(SPDLOG_SANITIZE_ADDRESS)
|
||||
spdlog_enable_sanitizer(${test_target})
|
||||
endif()
|
||||
add_test(NAME ${test_target} COMMAND ${test_target})
|
||||
endfunction()
|
||||
|
||||
# The compiled library tests
|
||||
if(SPDLOG_BUILD_TESTS)
|
||||
add_executable(spdlog-utests ${SPDLOG_UTESTS_SOURCES})
|
||||
spdlog_enable_warnings(spdlog-utests)
|
||||
target_link_libraries(spdlog-utests PRIVATE spdlog)
|
||||
|
||||
if(systemd_FOUND)
|
||||
target_link_libraries(spdlog-utests PRIVATE ${systemd_LIBRARIES})
|
||||
endif()
|
||||
if(SPDLOG_SANITIZE_ADDRESS)
|
||||
spdlog_enable_sanitizer(spdlog-utests)
|
||||
endif()
|
||||
add_test(NAME spdlog-utests COMMAND spdlog-utests)
|
||||
spdlog_prepare_test(spdlog-utests spdlog::spdlog)
|
||||
endif()
|
||||
|
||||
# The header-only library version tests
|
||||
if(SPDLOG_BUILD_TESTS_HO)
|
||||
add_executable(spdlog-utests-ho ${SPDLOG_UTESTS_SOURCES})
|
||||
spdlog_enable_warnings(spdlog-utests-ho)
|
||||
target_link_libraries(spdlog-utests-ho PRIVATE spdlog::spdlog_header_only)
|
||||
if(systemd_FOUND)
|
||||
target_link_libraries(spdlog-utests-ho PRIVATE ${systemd_LIBRARIES})
|
||||
endif()
|
||||
if(SPDLOG_SANITIZE_ADDRESS)
|
||||
spdlog_set_address_sanitizer(spdlog-utests-ho)
|
||||
endif()
|
||||
add_test(NAME spdlog-utests-ho COMMAND spdlog-utests-ho)
|
||||
spdlog_prepare_test(spdlog-utests-ho spdlog::spdlog_header_only)
|
||||
endif()
|
||||
|
27
third_party/spdlog/tests/meson.build
vendored
27
third_party/spdlog/tests/meson.build
vendored
@ -5,19 +5,18 @@ test_sources = files([
|
||||
'test_misc.cpp',
|
||||
'test_pattern_formatter.cpp',
|
||||
'test_async.cpp',
|
||||
'includes.h',
|
||||
'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_dup_filter.cpp',
|
||||
'test_backtrace.cpp'
|
||||
'test_backtrace.cpp',
|
||||
'test_create_dir.cpp'
|
||||
])
|
||||
|
||||
|
||||
if not get_option('no_exceptions')
|
||||
test_sources += 'test_errors.cpp'
|
||||
endif
|
||||
@ -35,19 +34,15 @@ if systemd_dep.found()
|
||||
global_test_deps += systemd_dep
|
||||
endif
|
||||
|
||||
run_command('mkdir', 'logs')
|
||||
# --------------------------------------
|
||||
# --- Build the test executables ---
|
||||
# --------------------------------------
|
||||
if get_option('enable_tests')
|
||||
test_exe = executable('spdlog-utests', test_sources, dependencies: global_test_deps + [spdlog_dep])
|
||||
test('test_spdlog', test_exe, is_parallel : false)
|
||||
endif
|
||||
|
||||
test_matrix = [
|
||||
['spdlog-utests', spdlog_dep],
|
||||
['spdlog-utests-ho', spdlog_headeronly_dep],
|
||||
]
|
||||
|
||||
foreach i : test_matrix
|
||||
test_exe = executable(i[0], test_sources, dependencies: global_test_deps + [i[1]])
|
||||
test('test_' + i[0], test_exe)
|
||||
endforeach
|
||||
|
||||
run_command(find_program('mkdir'), meson.current_build_dir() + '/logs')
|
||||
if get_option('enable_tests_ho')
|
||||
test_exe = executable('spdlog-utests-ho', test_sources, dependencies: global_test_deps + [spdlog_headeronly_dep])
|
||||
test('test_spdlog-ho', test_exe, is_parallel : false)
|
||||
endif
|
4
third_party/spdlog/tests/test_async.cpp
vendored
4
third_party/spdlog/tests/test_async.cpp
vendored
@ -157,7 +157,7 @@ TEST_CASE("to_file", "[async]")
|
||||
prepare_logdir();
|
||||
size_t messages = 1024;
|
||||
size_t tp_threads = 1;
|
||||
std::string filename = "logs/async_test.log";
|
||||
std::string filename = "test_logs/async_test.log";
|
||||
{
|
||||
auto file_sink = std::make_shared<spdlog::sinks::basic_file_sink_mt>(filename, true);
|
||||
auto tp = std::make_shared<spdlog::details::thread_pool>(messages, tp_threads);
|
||||
@ -179,7 +179,7 @@ TEST_CASE("to_file multi-workers", "[async]")
|
||||
prepare_logdir();
|
||||
size_t messages = 1024 * 10;
|
||||
size_t tp_threads = 10;
|
||||
std::string filename = "logs/async_test.log";
|
||||
std::string filename = "test_logs/async_test.log";
|
||||
{
|
||||
auto file_sink = std::make_shared<spdlog::sinks::basic_file_sink_mt>(filename, true);
|
||||
auto tp = std::make_shared<spdlog::details::thread_pool>(messages, tp_threads);
|
||||
|
80
third_party/spdlog/tests/test_create_dir.cpp
vendored
Normal file
80
third_party/spdlog/tests/test_create_dir.cpp
vendored
Normal file
@ -0,0 +1,80 @@
|
||||
/*
|
||||
* This content is released under the MIT License as specified in https://raw.githubusercontent.com/gabime/spdlog/master/LICENSE
|
||||
*/
|
||||
#include "includes.h"
|
||||
|
||||
using spdlog::details::os::create_dir;
|
||||
using spdlog::details::os::path_exists;
|
||||
|
||||
bool try_create_dir(const char *path, const char *normalized_path)
|
||||
{
|
||||
auto rv = create_dir(path);
|
||||
REQUIRE(rv == true);
|
||||
return path_exists(normalized_path);
|
||||
}
|
||||
|
||||
TEST_CASE("create_dir", "[create_dir]")
|
||||
{
|
||||
prepare_logdir();
|
||||
|
||||
REQUIRE(try_create_dir("test_logs/dir1/dir1", "test_logs/dir1/dir1"));
|
||||
REQUIRE(try_create_dir("test_logs/dir1/dir1", "test_logs/dir1/dir1")); // test existing
|
||||
REQUIRE(try_create_dir("test_logs/dir1///dir2//", "test_logs/dir1/dir2"));
|
||||
REQUIRE(try_create_dir("./test_logs/dir1/dir3", "test_logs/dir1/dir3"));
|
||||
REQUIRE(try_create_dir("test_logs/../test_logs/dir1/dir4", "test_logs/dir1/dir4"));
|
||||
|
||||
#ifdef WIN32
|
||||
// test backslash folder separator
|
||||
REQUIRE(try_create_dir("test_logs\\dir1\\dir222", "test_logs\\dir1\\dir222"));
|
||||
REQUIRE(try_create_dir("test_logs\\dir1\\dir223\\", "test_logs\\dir1\\dir223\\"));
|
||||
REQUIRE(try_create_dir(".\\test_logs\\dir1\\dir2\\dir99\\..\\dir23", "test_logs\\dir1\\dir2\\dir23"));
|
||||
REQUIRE(try_create_dir("test_logs\\..\\test_logs\\dir1\\dir5", "test_logs\\dir1\\dir5"));
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST_CASE("create_invalid_dir", "[create_dir]")
|
||||
{
|
||||
REQUIRE(create_dir("") == false);
|
||||
REQUIRE(create_dir(spdlog::filename_t{}) == false);
|
||||
#ifdef __linux__
|
||||
REQUIRE(create_dir("/proc/spdlog-utest") == false);
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST_CASE("dir_name", "[create_dir]")
|
||||
{
|
||||
using spdlog::details::os::dir_name;
|
||||
REQUIRE(dir_name("").empty());
|
||||
REQUIRE(dir_name("dir").empty());
|
||||
|
||||
#ifdef WIN32
|
||||
REQUIRE(dir_name(R"(dir\)") == "dir");
|
||||
REQUIRE(dir_name(R"(dir\\\)") == R"(dir\\)");
|
||||
REQUIRE(dir_name(R"(dir\file)") == "dir");
|
||||
REQUIRE(dir_name(R"(dir/file)") == "dir");
|
||||
REQUIRE(dir_name(R"(dir\file.txt)") == "dir");
|
||||
REQUIRE(dir_name(R"(dir/file)") == "dir");
|
||||
REQUIRE(dir_name(R"(dir\file.txt\)") == R"(dir\file.txt)");
|
||||
REQUIRE(dir_name(R"(dir/file.txt/)") == R"(dir\file.txt)");
|
||||
REQUIRE(dir_name(R"(\dir\file.txt)") == R"(\dir)");
|
||||
REQUIRE(dir_name(R"(/dir/file.txt)") == R"(\dir)");
|
||||
REQUIRE(dir_name(R"(\\dir\file.txt)") == R"(\\dir)");
|
||||
REQUIRE(dir_name(R"(//dir/file.txt)") == R"(\\dir)");
|
||||
REQUIRE(dir_name(R"(..\file.txt)") == "..");
|
||||
REQUIRE(dir_name(R"(../file.txt)") == "..");
|
||||
REQUIRE(dir_name(R"(.\file.txt)") == ".");
|
||||
REQUIRE(dir_name(R"(./file.txt)") == ".");
|
||||
REQUIRE(dir_name(R"(c:\\a\b\c\d\file.txt)") == R"(c:\\a\b\c\d)");
|
||||
REQUIRE(dir_name(R"(c://a/b/c/d/file.txt)") == R"(c:\\a\b\c\d)");
|
||||
#else
|
||||
REQUIRE(dir_name("dir/") == "dir");
|
||||
REQUIRE(dir_name("dir///") == "dir//");
|
||||
REQUIRE(dir_name("dir/file") == "dir");
|
||||
REQUIRE(dir_name("dir/file.txt") == "dir");
|
||||
REQUIRE(dir_name("dir/file.txt/") == "dir/file.txt");
|
||||
REQUIRE(dir_name("/dir/file.txt") == "/dir");
|
||||
REQUIRE(dir_name("//dir/file.txt") == "//dir");
|
||||
REQUIRE(dir_name("../file.txt") == "..");
|
||||
REQUIRE(dir_name("./file.txt") == ".");
|
||||
#endif
|
||||
}
|
@ -10,7 +10,7 @@ TEST_CASE("daily_logger with dateonly calculator", "[daily_logger]")
|
||||
prepare_logdir();
|
||||
|
||||
// calculate filename (time based)
|
||||
std::string basename = "logs/daily_dateonly";
|
||||
std::string basename = "test_logs/daily_dateonly";
|
||||
std::tm tm = spdlog::details::os::localtime();
|
||||
spdlog::memory_buf_t w;
|
||||
fmt::format_to(w, "{}_{:04d}-{:02d}-{:02d}", basename, tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday);
|
||||
@ -44,7 +44,7 @@ TEST_CASE("daily_logger with custom calculator", "[daily_logger]")
|
||||
prepare_logdir();
|
||||
|
||||
// calculate filename (time based)
|
||||
std::string basename = "logs/daily_dateonly";
|
||||
std::string basename = "test_logs/daily_dateonly";
|
||||
std::tm tm = spdlog::details::os::localtime();
|
||||
spdlog::memory_buf_t w;
|
||||
fmt::format_to(w, "{}{:04d}{:02d}{:02d}", basename, tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday);
|
||||
@ -119,7 +119,7 @@ static void test_rotate(int days_to_run, uint16_t max_days, uint16_t expected_n_
|
||||
|
||||
prepare_logdir();
|
||||
|
||||
std::string basename = "logs/daily_rotate.txt";
|
||||
std::string basename = "test_logs/daily_rotate.txt";
|
||||
daily_file_sink_st sink{basename, 2, 30, true, max_days};
|
||||
|
||||
// simulate messages with 24 intervals
|
||||
@ -130,7 +130,7 @@ static void test_rotate(int days_to_run, uint16_t max_days, uint16_t expected_n_
|
||||
sink.log(create_msg(offset));
|
||||
}
|
||||
|
||||
REQUIRE(count_files("logs") == static_cast<size_t>(expected_n_files));
|
||||
REQUIRE(count_files("test_logs") == static_cast<size_t>(expected_n_files));
|
||||
}
|
||||
|
||||
TEST_CASE("daily_logger rotate", "[daily_file_sink]")
|
||||
|
19
third_party/spdlog/tests/test_errors.cpp
vendored
19
third_party/spdlog/tests/test_errors.cpp
vendored
@ -26,7 +26,7 @@ protected:
|
||||
TEST_CASE("default_error_handler", "[errors]]")
|
||||
{
|
||||
prepare_logdir();
|
||||
std::string filename = "logs/simple_log.txt";
|
||||
std::string filename = "test_logs/simple_log.txt";
|
||||
|
||||
auto logger = spdlog::create<spdlog::sinks::basic_file_sink_mt>("test-error", filename, true);
|
||||
logger->set_pattern("%v");
|
||||
@ -43,7 +43,7 @@ struct custom_ex
|
||||
TEST_CASE("custom_error_handler", "[errors]]")
|
||||
{
|
||||
prepare_logdir();
|
||||
std::string filename = "logs/simple_log.txt";
|
||||
std::string filename = "test_logs/simple_log.txt";
|
||||
auto logger = spdlog::create<spdlog::sinks::basic_file_sink_mt>("logger", filename, true);
|
||||
logger->flush_on(spdlog::level::info);
|
||||
logger->set_error_handler([=](const std::string &) { throw custom_ex(); });
|
||||
@ -75,15 +75,15 @@ TEST_CASE("async_error_handler", "[errors]]")
|
||||
prepare_logdir();
|
||||
std::string err_msg("log failed with some msg");
|
||||
|
||||
std::string filename = "logs/simple_async_log.txt";
|
||||
std::string filename = "test_logs/simple_async_log.txt";
|
||||
{
|
||||
spdlog::init_thread_pool(128, 1);
|
||||
auto logger = spdlog::create_async<spdlog::sinks::basic_file_sink_mt>("logger", filename, true);
|
||||
logger->set_error_handler([=](const std::string &) {
|
||||
std::ofstream ofs("logs/custom_err.txt");
|
||||
std::ofstream ofs("test_logs/custom_err.txt");
|
||||
if (!ofs)
|
||||
{
|
||||
throw std::runtime_error("Failed open logs/custom_err.txt");
|
||||
throw std::runtime_error("Failed open test_logs/custom_err.txt");
|
||||
}
|
||||
ofs << err_msg;
|
||||
});
|
||||
@ -94,7 +94,7 @@ TEST_CASE("async_error_handler", "[errors]]")
|
||||
}
|
||||
spdlog::init_thread_pool(128, 1);
|
||||
REQUIRE(count_lines(filename) == 2);
|
||||
REQUIRE(file_contents("logs/custom_err.txt") == err_msg);
|
||||
REQUIRE(file_contents("test_logs/custom_err.txt") == err_msg);
|
||||
}
|
||||
|
||||
// Make sure async error handler is executed
|
||||
@ -103,12 +103,13 @@ TEST_CASE("async_error_handler2", "[errors]]")
|
||||
prepare_logdir();
|
||||
std::string err_msg("This is async handler error message");
|
||||
{
|
||||
spdlog::details::os::create_dir("test_logs");
|
||||
spdlog::init_thread_pool(128, 1);
|
||||
auto logger = spdlog::create_async<failing_sink>("failed_logger");
|
||||
logger->set_error_handler([=](const std::string &) {
|
||||
std::ofstream ofs("logs/custom_err2.txt");
|
||||
std::ofstream ofs("test_logs/custom_err2.txt");
|
||||
if (!ofs)
|
||||
throw std::runtime_error("Failed open logs/custom_err2.txt");
|
||||
throw std::runtime_error("Failed open test_logs/custom_err2.txt");
|
||||
ofs << err_msg;
|
||||
});
|
||||
logger->info("Hello failure");
|
||||
@ -116,5 +117,5 @@ TEST_CASE("async_error_handler2", "[errors]]")
|
||||
}
|
||||
|
||||
spdlog::init_thread_pool(128, 1);
|
||||
REQUIRE(file_contents("logs/custom_err2.txt") == err_msg);
|
||||
REQUIRE(file_contents("test_logs/custom_err2.txt") == err_msg);
|
||||
}
|
||||
|
11
third_party/spdlog/tests/test_file_helper.cpp
vendored
11
third_party/spdlog/tests/test_file_helper.cpp
vendored
@ -6,7 +6,7 @@
|
||||
using spdlog::details::file_helper;
|
||||
using spdlog::details::log_msg;
|
||||
|
||||
static const std::string target_filename = "logs/file_helper_test.txt";
|
||||
static const std::string target_filename = "test_logs/file_helper_test.txt";
|
||||
|
||||
static void write_with_helper(file_helper &helper, size_t howmany)
|
||||
{
|
||||
@ -38,15 +38,6 @@ TEST_CASE("file_helper_size", "[file_helper::size()]]")
|
||||
REQUIRE(get_filesize(target_filename) == expected_size);
|
||||
}
|
||||
|
||||
TEST_CASE("file_helper_exists", "[file_helper::file_exists()]]")
|
||||
{
|
||||
prepare_logdir();
|
||||
REQUIRE(!file_helper::file_exists(target_filename));
|
||||
file_helper helper;
|
||||
helper.open(target_filename);
|
||||
REQUIRE(file_helper::file_exists(target_filename));
|
||||
}
|
||||
|
||||
TEST_CASE("file_helper_reopen", "[file_helper::reopen()]]")
|
||||
{
|
||||
prepare_logdir();
|
||||
|
@ -6,7 +6,7 @@
|
||||
TEST_CASE("simple_file_logger", "[simple_logger]]")
|
||||
{
|
||||
prepare_logdir();
|
||||
std::string filename = "logs/simple_log";
|
||||
std::string filename = "test_logs/simple_log";
|
||||
|
||||
auto logger = spdlog::create<spdlog::sinks::basic_file_sink_mt>("logger", filename);
|
||||
logger->set_pattern("%v");
|
||||
@ -22,7 +22,7 @@ TEST_CASE("simple_file_logger", "[simple_logger]]")
|
||||
TEST_CASE("flush_on", "[flush_on]]")
|
||||
{
|
||||
prepare_logdir();
|
||||
std::string filename = "logs/simple_log";
|
||||
std::string filename = "test_logs/simple_log";
|
||||
|
||||
auto logger = spdlog::create<spdlog::sinks::basic_file_sink_mt>("logger", filename);
|
||||
logger->set_pattern("%v");
|
||||
@ -42,7 +42,7 @@ TEST_CASE("rotating_file_logger1", "[rotating_logger]]")
|
||||
{
|
||||
prepare_logdir();
|
||||
size_t max_size = 1024 * 10;
|
||||
std::string basename = "logs/rotating_log";
|
||||
std::string basename = "test_logs/rotating_log";
|
||||
auto logger = spdlog::rotating_logger_mt("logger", basename, max_size, 0);
|
||||
|
||||
for (int i = 0; i < 10; ++i)
|
||||
@ -59,7 +59,7 @@ TEST_CASE("rotating_file_logger2", "[rotating_logger]]")
|
||||
{
|
||||
prepare_logdir();
|
||||
size_t max_size = 1024 * 10;
|
||||
std::string basename = "logs/rotating_log";
|
||||
std::string basename = "test_logs/rotating_log";
|
||||
|
||||
{
|
||||
// make an initial logger to create the first output file
|
||||
|
20
third_party/spdlog/tests/test_macros.cpp
vendored
20
third_party/spdlog/tests/test_macros.cpp
vendored
@ -12,7 +12,7 @@ TEST_CASE("debug and trace w/o format string", "[macros]]")
|
||||
{
|
||||
|
||||
prepare_logdir();
|
||||
std::string filename = "logs/simple_log";
|
||||
std::string filename = "test_logs/simple_log";
|
||||
|
||||
auto logger = spdlog::create<spdlog::sinks::basic_file_sink_mt>("logger", filename);
|
||||
logger->set_pattern("%v");
|
||||
@ -39,3 +39,21 @@ TEST_CASE("disable param evaluation", "[macros]")
|
||||
{
|
||||
SPDLOG_TRACE("Test message {}", throw std::runtime_error("Should not be evaluated"));
|
||||
}
|
||||
|
||||
TEST_CASE("pass logger pointer", "[macros]")
|
||||
{
|
||||
auto logger = spdlog::create<spdlog::sinks::null_sink_mt>("refmacro");
|
||||
auto &ref = *logger;
|
||||
SPDLOG_LOGGER_TRACE(&ref, "Test message 1");
|
||||
SPDLOG_LOGGER_DEBUG(&ref, "Test message 2");
|
||||
}
|
||||
|
||||
// ensure that even if right macro level is on- don't evaluate if the logger's level is not high enough
|
||||
// TEST_CASE("disable param evaluation2", "[macros]")
|
||||
//{
|
||||
// auto logger = std::make_shared<spdlog::logger>("test-macro");
|
||||
// logger->set_level(spdlog::level::off);
|
||||
// int x = 0;
|
||||
// SPDLOG_LOGGER_DEBUG(logger, "Test message {}", ++x);
|
||||
// REQUIRE(x == 0);
|
||||
//}
|
||||
|
@ -1,4 +1,5 @@
|
||||
#include "includes.h"
|
||||
#include "test_sink.h"
|
||||
|
||||
using spdlog::memory_buf_t;
|
||||
|
||||
@ -138,58 +139,111 @@ TEST_CASE("color range test6", "[pattern_formatter]")
|
||||
TEST_CASE("level_left_padded", "[pattern_formatter]")
|
||||
{
|
||||
REQUIRE(log_to_str("Some message", "[%8l] %v", spdlog::pattern_time_type::local, "\n") == "[ info] Some message\n");
|
||||
REQUIRE(log_to_str("Some message", "[%8!l] %v", spdlog::pattern_time_type::local, "\n") == "[ info] Some message\n");
|
||||
}
|
||||
|
||||
TEST_CASE("level_right_padded", "[pattern_formatter]")
|
||||
{
|
||||
REQUIRE(log_to_str("Some message", "[%-8l] %v", spdlog::pattern_time_type::local, "\n") == "[info ] Some message\n");
|
||||
REQUIRE(log_to_str("Some message", "[%-8!l] %v", spdlog::pattern_time_type::local, "\n") == "[info ] Some message\n");
|
||||
}
|
||||
|
||||
TEST_CASE("level_center_padded", "[pattern_formatter]")
|
||||
{
|
||||
REQUIRE(log_to_str("Some message", "[%=8l] %v", spdlog::pattern_time_type::local, "\n") == "[ info ] Some message\n");
|
||||
REQUIRE(log_to_str("Some message", "[%=8!l] %v", spdlog::pattern_time_type::local, "\n") == "[ info ] Some message\n");
|
||||
}
|
||||
|
||||
TEST_CASE("short level_left_padded", "[pattern_formatter]")
|
||||
{
|
||||
REQUIRE(log_to_str("Some message", "[%3L] %v", spdlog::pattern_time_type::local, "\n") == "[ I] Some message\n");
|
||||
REQUIRE(log_to_str("Some message", "[%3!L] %v", spdlog::pattern_time_type::local, "\n") == "[ I] Some message\n");
|
||||
}
|
||||
|
||||
TEST_CASE("short level_right_padded", "[pattern_formatter]")
|
||||
{
|
||||
REQUIRE(log_to_str("Some message", "[%-3L] %v", spdlog::pattern_time_type::local, "\n") == "[I ] Some message\n");
|
||||
REQUIRE(log_to_str("Some message", "[%-3!L] %v", spdlog::pattern_time_type::local, "\n") == "[I ] Some message\n");
|
||||
}
|
||||
|
||||
TEST_CASE("short level_center_padded", "[pattern_formatter]")
|
||||
{
|
||||
REQUIRE(log_to_str("Some message", "[%=3L] %v", spdlog::pattern_time_type::local, "\n") == "[ I ] Some message\n");
|
||||
REQUIRE(log_to_str("Some message", "[%=3!L] %v", spdlog::pattern_time_type::local, "\n") == "[ I ] Some message\n");
|
||||
}
|
||||
|
||||
TEST_CASE("left_padded_short", "[pattern_formatter]")
|
||||
{
|
||||
REQUIRE(log_to_str("Some message", "[%3n] %v", spdlog::pattern_time_type::local, "\n") == "[pattern_tester] Some message\n");
|
||||
REQUIRE(log_to_str("Some message", "[%3!n] %v", spdlog::pattern_time_type::local, "\n") == "[pat] Some message\n");
|
||||
}
|
||||
|
||||
TEST_CASE("right_padded_short", "[pattern_formatter]")
|
||||
{
|
||||
REQUIRE(log_to_str("Some message", "[%-3n] %v", spdlog::pattern_time_type::local, "\n") == "[pattern_tester] Some message\n");
|
||||
REQUIRE(log_to_str("Some message", "[%-3!n] %v", spdlog::pattern_time_type::local, "\n") == "[pat] Some message\n");
|
||||
}
|
||||
|
||||
TEST_CASE("center_padded_short", "[pattern_formatter]")
|
||||
{
|
||||
REQUIRE(log_to_str("Some message", "[%=3n] %v", spdlog::pattern_time_type::local, "\n") == "[pattern_tester] Some message\n");
|
||||
REQUIRE(log_to_str("Some message", "[%=3!n] %v", spdlog::pattern_time_type::local, "\n") == "[pat] Some message\n");
|
||||
}
|
||||
|
||||
TEST_CASE("left_padded_huge", "[pattern_formatter]")
|
||||
{
|
||||
REQUIRE(log_to_str("Some message", "[%-300n] %v", spdlog::pattern_time_type::local, "\n") ==
|
||||
"[pattern_tester ] Some message\n");
|
||||
|
||||
REQUIRE(log_to_str("Some message", "[%-300!n] %v", spdlog::pattern_time_type::local, "\n") ==
|
||||
"[pattern_tester ] Some message\n");
|
||||
}
|
||||
|
||||
TEST_CASE("left_padded_max", "[pattern_formatter]")
|
||||
{
|
||||
REQUIRE(log_to_str("Some message", "[%-64n] %v", spdlog::pattern_time_type::local, "\n") ==
|
||||
"[pattern_tester ] Some message\n");
|
||||
|
||||
REQUIRE(log_to_str("Some message", "[%-64!n] %v", spdlog::pattern_time_type::local, "\n") ==
|
||||
"[pattern_tester ] Some message\n");
|
||||
}
|
||||
|
||||
// Test padding + truncate flag
|
||||
|
||||
TEST_CASE("paddinng_truncate", "[pattern_formatter]")
|
||||
{
|
||||
REQUIRE(log_to_str("123456", "%6!v", spdlog::pattern_time_type::local, "\n") == "123456\n");
|
||||
REQUIRE(log_to_str("123456", "%5!v", spdlog::pattern_time_type::local, "\n") == "12345\n");
|
||||
REQUIRE(log_to_str("123456", "%7!v", spdlog::pattern_time_type::local, "\n") == " 123456\n");
|
||||
|
||||
REQUIRE(log_to_str("123456", "%-6!v", spdlog::pattern_time_type::local, "\n") == "123456\n");
|
||||
REQUIRE(log_to_str("123456", "%-5!v", spdlog::pattern_time_type::local, "\n") == "12345\n");
|
||||
REQUIRE(log_to_str("123456", "%-7!v", spdlog::pattern_time_type::local, "\n") == "123456 \n");
|
||||
|
||||
REQUIRE(log_to_str("123456", "%=6!v", spdlog::pattern_time_type::local, "\n") == "123456\n");
|
||||
REQUIRE(log_to_str("123456", "%=5!v", spdlog::pattern_time_type::local, "\n") == "12345\n");
|
||||
REQUIRE(log_to_str("123456", "%=7!v", spdlog::pattern_time_type::local, "\n") == "123456 \n");
|
||||
|
||||
REQUIRE(log_to_str("123456", "%0!v", spdlog::pattern_time_type::local, "\n") == "\n");
|
||||
}
|
||||
|
||||
TEST_CASE("paddinng_truncate_funcname", "[pattern_formatter]")
|
||||
{
|
||||
spdlog::sinks::test_sink_st test_sink;
|
||||
|
||||
const char *pattern = "%v [%5!!]";
|
||||
auto formatter = std::unique_ptr<spdlog::formatter>(new spdlog::pattern_formatter(pattern));
|
||||
test_sink.set_formatter(std::move(formatter));
|
||||
|
||||
spdlog::details::log_msg msg1{spdlog::source_loc{"ignored", 1, "func"}, "test_logger", spdlog::level::info, "message"};
|
||||
test_sink.log(msg1);
|
||||
|
||||
spdlog::details::log_msg msg2{spdlog::source_loc{"ignored", 1, "function"}, "test_logger", spdlog::level::info, "message"};
|
||||
test_sink.log(msg2);
|
||||
|
||||
auto lines = test_sink.lines();
|
||||
REQUIRE(lines[0] == "message [ func]");
|
||||
REQUIRE(lines[1] == "message [funct]");
|
||||
}
|
||||
|
||||
TEST_CASE("clone-default-formatter", "[pattern_formatter]")
|
||||
|
4
third_party/spdlog/tests/test_registry.cpp
vendored
4
third_party/spdlog/tests/test_registry.cpp
vendored
@ -9,7 +9,7 @@ TEST_CASE("register_drop", "[registry]")
|
||||
spdlog::drop_all();
|
||||
spdlog::create<spdlog::sinks::null_sink_mt>(tested_logger_name);
|
||||
REQUIRE(spdlog::get(tested_logger_name) != nullptr);
|
||||
// Throw if registring existing name
|
||||
// Throw if registering existing name
|
||||
REQUIRE_THROWS_AS(spdlog::create<spdlog::sinks::null_sink_mt>(tested_logger_name), spdlog::spdlog_ex);
|
||||
}
|
||||
|
||||
@ -19,7 +19,7 @@ TEST_CASE("explicit register", "[registry]")
|
||||
auto logger = std::make_shared<spdlog::logger>(tested_logger_name, std::make_shared<spdlog::sinks::null_sink_st>());
|
||||
spdlog::register_logger(logger);
|
||||
REQUIRE(spdlog::get(tested_logger_name) != nullptr);
|
||||
// Throw if registring existing name
|
||||
// Throw if registering existing name
|
||||
REQUIRE_THROWS_AS(spdlog::create<spdlog::sinks::null_sink_mt>(tested_logger_name), spdlog::spdlog_ex);
|
||||
}
|
||||
#endif
|
||||
|
12
third_party/spdlog/tests/utils.cpp
vendored
12
third_party/spdlog/tests/utils.cpp
vendored
@ -9,18 +9,12 @@ void prepare_logdir()
|
||||
{
|
||||
spdlog::drop_all();
|
||||
#ifdef _WIN32
|
||||
system("if not exist logs mkdir logs");
|
||||
system("del /F /Q logs\\*");
|
||||
system("rmdir /S /Q test_logs");
|
||||
#else
|
||||
auto rv = system("mkdir -p logs");
|
||||
auto rv = system("rm -rf test_logs");
|
||||
if (rv != 0)
|
||||
{
|
||||
throw std::runtime_error("Failed to mkdir -p logs");
|
||||
}
|
||||
rv = system("rm -f logs/*");
|
||||
if (rv != 0)
|
||||
{
|
||||
throw std::runtime_error("Failed to rm -f logs/*");
|
||||
throw std::runtime_error("Failed to rm -rf test_logs");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
Reference in New Issue
Block a user