update and change how we build with spdlog
This commit is contained in:
57
third_party/spdlog/tests/CMakeLists.txt
vendored
57
third_party/spdlog/tests/CMakeLists.txt
vendored
@ -1,11 +1,16 @@
|
||||
project(spdlog-utests CXX)
|
||||
project(spdlog_utests CXX)
|
||||
|
||||
find_package(Threads REQUIRED)
|
||||
include(../cmake/utils.cmake)
|
||||
|
||||
find_package(PkgConfig)
|
||||
if(PkgConfig_FOUND)
|
||||
pkg_check_modules(systemd libsystemd)
|
||||
endif()
|
||||
|
||||
set(SPDLOG_UTESTS_SOURCES
|
||||
test_errors.cpp
|
||||
test_file_helper.cpp
|
||||
test_file_logging.cpp
|
||||
test_daily_logger.cpp
|
||||
test_misc.cpp
|
||||
test_pattern_formatter.cpp
|
||||
test_async.cpp
|
||||
@ -17,13 +22,47 @@ set(SPDLOG_UTESTS_SOURCES
|
||||
main.cpp
|
||||
test_mpmc_q.cpp
|
||||
test_sink.h
|
||||
test_fmt_helper.cpp)
|
||||
test_fmt_helper.cpp
|
||||
test_stdout_api.cpp
|
||||
test_dup_filter.cpp
|
||||
test_backtrace.cpp)
|
||||
|
||||
add_executable(${PROJECT_NAME} ${SPDLOG_UTESTS_SOURCES})
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE Threads::Threads)
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE spdlog::spdlog)
|
||||
if(NOT SPDLOG_NO_EXCEPTIONS)
|
||||
list(APPEND SPDLOG_UTESTS_SOURCES test_errors.cpp)
|
||||
endif()
|
||||
|
||||
if(systemd_FOUND)
|
||||
list(APPEND SPDLOG_UTESTS_SOURCES test_systemd.cpp)
|
||||
endif()
|
||||
|
||||
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/logs")
|
||||
|
||||
enable_testing()
|
||||
add_test(NAME ${PROJECT_NAME} COMMAND ${PROJECT_NAME})
|
||||
|
||||
# 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)
|
||||
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)
|
||||
endif()
|
||||
|
24799
third_party/spdlog/tests/catch.hpp
vendored
24799
third_party/spdlog/tests/catch.hpp
vendored
File diff suppressed because it is too large
Load Diff
2
third_party/spdlog/tests/catch.license
vendored
2
third_party/spdlog/tests/catch.license
vendored
@ -20,4 +20,4 @@ FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
DEALINGS IN THE SOFTWARE.
|
||||
DEALINGS IN THE SOFTWARE.
|
||||
|
4
third_party/spdlog/tests/includes.h
vendored
4
third_party/spdlog/tests/includes.h
vendored
@ -8,10 +8,11 @@
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <ostream>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <iomanip>
|
||||
|
||||
#define SPDLOG_ACTIVE_LEVEL SPDLOG_LEVEL_DEBUG
|
||||
#define SPDLOG_ENABLE_MESSAGE_COUNTER
|
||||
|
||||
#include "spdlog/spdlog.h"
|
||||
#include "spdlog/async.h"
|
||||
@ -21,3 +22,4 @@
|
||||
#include "spdlog/sinks/ostream_sink.h"
|
||||
#include "spdlog/sinks/rotating_file_sink.h"
|
||||
#include "spdlog/sinks/stdout_color_sinks.h"
|
||||
#include "spdlog/details/pattern_formatter.h"
|
2
third_party/spdlog/tests/main.cpp
vendored
2
third_party/spdlog/tests/main.cpp
vendored
@ -1,2 +1,2 @@
|
||||
#define CATCH_CONFIG_MAIN
|
||||
#include "catch.hpp"
|
||||
#include "catch.hpp"
|
53
third_party/spdlog/tests/meson.build
vendored
Normal file
53
third_party/spdlog/tests/meson.build
vendored
Normal file
@ -0,0 +1,53 @@
|
||||
test_sources = files([
|
||||
'test_file_helper.cpp',
|
||||
'test_file_logging.cpp',
|
||||
'test_daily_logger.cpp',
|
||||
'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_fmt_helper.cpp',
|
||||
'test_stdout_api.cpp',
|
||||
'test_dup_filter.cpp',
|
||||
'test_backtrace.cpp'
|
||||
])
|
||||
|
||||
|
||||
if not get_option('no_exceptions')
|
||||
test_sources += 'test_errors.cpp'
|
||||
endif
|
||||
|
||||
global_test_deps = []
|
||||
|
||||
# -----------------------------------------------------
|
||||
# --- Add the systemd test if libsystemd is found ---
|
||||
# -----------------------------------------------------
|
||||
|
||||
systemd_dep = dependency('libsystemd', required: false)
|
||||
|
||||
if systemd_dep.found()
|
||||
test_sources += 'test_systemd.cpp'
|
||||
global_test_deps += systemd_dep
|
||||
endif
|
||||
|
||||
run_command('mkdir', 'logs')
|
||||
# --------------------------------------
|
||||
# --- Build the test executables ---
|
||||
# --------------------------------------
|
||||
|
||||
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')
|
65
third_party/spdlog/tests/test_backtrace.cpp
vendored
Normal file
65
third_party/spdlog/tests/test_backtrace.cpp
vendored
Normal file
@ -0,0 +1,65 @@
|
||||
#include "includes.h"
|
||||
#include "test_sink.h"
|
||||
#include "spdlog/async.h"
|
||||
|
||||
TEST_CASE("bactrace1", "[bactrace]")
|
||||
{
|
||||
|
||||
using spdlog::sinks::test_sink_st;
|
||||
auto test_sink = std::make_shared<test_sink_st>();
|
||||
size_t backtrace_size = 5;
|
||||
|
||||
spdlog::logger logger("test-backtrace", test_sink);
|
||||
logger.set_pattern("%v");
|
||||
logger.enable_backtrace(backtrace_size);
|
||||
|
||||
logger.info("info message");
|
||||
for (int i = 0; i < 100; i++)
|
||||
logger.debug("debug message {}", i);
|
||||
|
||||
REQUIRE(test_sink->lines().size() == 1);
|
||||
REQUIRE(test_sink->lines()[0] == "info message");
|
||||
|
||||
logger.dump_backtrace();
|
||||
REQUIRE(test_sink->lines().size() == backtrace_size + 3);
|
||||
REQUIRE(test_sink->lines()[1] == "****************** Backtrace Start ******************");
|
||||
REQUIRE(test_sink->lines()[2] == "debug message 95");
|
||||
REQUIRE(test_sink->lines()[3] == "debug message 96");
|
||||
REQUIRE(test_sink->lines()[4] == "debug message 97");
|
||||
REQUIRE(test_sink->lines()[5] == "debug message 98");
|
||||
REQUIRE(test_sink->lines()[6] == "debug message 99");
|
||||
REQUIRE(test_sink->lines()[7] == "****************** Backtrace End ********************");
|
||||
}
|
||||
|
||||
TEST_CASE("bactrace-async", "[bactrace]")
|
||||
{
|
||||
using spdlog::sinks::test_sink_mt;
|
||||
auto test_sink = std::make_shared<test_sink_mt>();
|
||||
using spdlog::details::os::sleep_for_millis;
|
||||
|
||||
size_t backtrace_size = 5;
|
||||
|
||||
spdlog::init_thread_pool(120, 1);
|
||||
auto logger = std::make_shared<spdlog::async_logger>("test-bactrace-async", test_sink, spdlog::thread_pool());
|
||||
logger->set_pattern("%v");
|
||||
logger->enable_backtrace(backtrace_size);
|
||||
|
||||
logger->info("info message");
|
||||
for (int i = 0; i < 100; i++)
|
||||
logger->debug("debug message {}", i);
|
||||
|
||||
sleep_for_millis(10);
|
||||
REQUIRE(test_sink->lines().size() == 1);
|
||||
REQUIRE(test_sink->lines()[0] == "info message");
|
||||
|
||||
logger->dump_backtrace();
|
||||
sleep_for_millis(100); // give time for the async dump to complete
|
||||
REQUIRE(test_sink->lines().size() == backtrace_size + 3);
|
||||
REQUIRE(test_sink->lines()[1] == "****************** Backtrace Start ******************");
|
||||
REQUIRE(test_sink->lines()[2] == "debug message 95");
|
||||
REQUIRE(test_sink->lines()[3] == "debug message 96");
|
||||
REQUIRE(test_sink->lines()[4] == "debug message 97");
|
||||
REQUIRE(test_sink->lines()[5] == "debug message 98");
|
||||
REQUIRE(test_sink->lines()[6] == "debug message 99");
|
||||
REQUIRE(test_sink->lines()[7] == "****************** Backtrace End ********************");
|
||||
}
|
152
third_party/spdlog/tests/test_daily_logger.cpp
vendored
Normal file
152
third_party/spdlog/tests/test_daily_logger.cpp
vendored
Normal file
@ -0,0 +1,152 @@
|
||||
/*
|
||||
* This content is released under the MIT License as specified in https://raw.githubusercontent.com/gabime/spdlog/master/LICENSE
|
||||
*/
|
||||
#include "includes.h"
|
||||
|
||||
TEST_CASE("daily_logger with dateonly calculator", "[daily_logger]")
|
||||
{
|
||||
using sink_type = spdlog::sinks::daily_file_sink<std::mutex, spdlog::sinks::daily_filename_calculator>;
|
||||
|
||||
prepare_logdir();
|
||||
|
||||
// calculate filename (time based)
|
||||
std::string basename = "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);
|
||||
|
||||
auto logger = spdlog::create<sink_type>("logger", basename, 0, 0);
|
||||
for (int i = 0; i < 10; ++i)
|
||||
{
|
||||
|
||||
logger->info("Test message {}", i);
|
||||
}
|
||||
logger->flush();
|
||||
|
||||
auto filename = fmt::to_string(w);
|
||||
REQUIRE(count_lines(filename) == 10);
|
||||
}
|
||||
|
||||
struct custom_daily_file_name_calculator
|
||||
{
|
||||
static spdlog::filename_t calc_filename(const spdlog::filename_t &basename, const tm &now_tm)
|
||||
{
|
||||
spdlog::memory_buf_t w;
|
||||
fmt::format_to(w, "{}{:04d}{:02d}{:02d}", basename, now_tm.tm_year + 1900, now_tm.tm_mon + 1, now_tm.tm_mday);
|
||||
return fmt::to_string(w);
|
||||
}
|
||||
};
|
||||
|
||||
TEST_CASE("daily_logger with custom calculator", "[daily_logger]")
|
||||
{
|
||||
using sink_type = spdlog::sinks::daily_file_sink<std::mutex, custom_daily_file_name_calculator>;
|
||||
|
||||
prepare_logdir();
|
||||
|
||||
// calculate filename (time based)
|
||||
std::string basename = "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);
|
||||
|
||||
auto logger = spdlog::create<sink_type>("logger", basename, 0, 0);
|
||||
for (int i = 0; i < 10; ++i)
|
||||
{
|
||||
logger->info("Test message {}", i);
|
||||
}
|
||||
|
||||
logger->
|
||||
|
||||
flush();
|
||||
|
||||
auto filename = fmt::to_string(w);
|
||||
REQUIRE(count_lines(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)
|
||||
|
||||
#include <regex>
|
||||
|
||||
TEST_CASE("daily_file_sink::daily_filename_calculator", "[daily_file_sink]]")
|
||||
{
|
||||
// daily_YYYY-MM-DD_hh-mm.txt
|
||||
auto filename = spdlog::sinks::daily_filename_calculator::calc_filename("daily.txt", spdlog::details::os::localtime());
|
||||
// date regex based on https://www.regular-expressions.info/dates.html
|
||||
std::regex re(R"(^daily_(19|20)\d\d-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])\.txt$)");
|
||||
std::smatch match;
|
||||
REQUIRE(std::regex_match(filename, match, re));
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Test removal of old files */
|
||||
static spdlog::details::log_msg create_msg(std::chrono::seconds offset)
|
||||
{
|
||||
using spdlog::log_clock;
|
||||
spdlog::details::log_msg msg{"test", spdlog::level::info, "Hello Message"};
|
||||
msg.time = log_clock::now() + offset;
|
||||
return msg;
|
||||
}
|
||||
|
||||
static void test_rotate(int days_to_run, uint16_t max_days, uint16_t expected_n_files)
|
||||
{
|
||||
using spdlog::log_clock;
|
||||
using spdlog::details::log_msg;
|
||||
using spdlog::sinks::daily_file_sink_st;
|
||||
using namespace spdlog::details;
|
||||
|
||||
prepare_logdir();
|
||||
|
||||
std::string basename = "logs/daily_rotate.txt";
|
||||
daily_file_sink_st sink{basename, 2, 30, true, max_days};
|
||||
|
||||
// simulate messages with 24 intervals
|
||||
|
||||
for (int i = 0; i < days_to_run; i++)
|
||||
{
|
||||
auto offset = std::chrono::seconds{24 * 3600 * i};
|
||||
sink.log(create_msg(offset));
|
||||
}
|
||||
|
||||
REQUIRE(count_files("logs") == static_cast<size_t>(expected_n_files));
|
||||
}
|
||||
|
||||
TEST_CASE("daily_logger rotate", "[daily_file_sink]")
|
||||
{
|
||||
int days_to_run = 1;
|
||||
test_rotate(days_to_run, 0, 1);
|
||||
test_rotate(days_to_run, 1, 1);
|
||||
test_rotate(days_to_run, 3, 1);
|
||||
test_rotate(days_to_run, 10, 1);
|
||||
|
||||
days_to_run = 10;
|
||||
test_rotate(days_to_run, 0, 10);
|
||||
test_rotate(days_to_run, 1, 1);
|
||||
test_rotate(days_to_run, 3, 3);
|
||||
test_rotate(days_to_run, 9, 9);
|
||||
test_rotate(days_to_run, 10, 10);
|
||||
test_rotate(days_to_run, 11, 10);
|
||||
test_rotate(days_to_run, 20, 10);
|
||||
}
|
76
third_party/spdlog/tests/test_dup_filter.cpp
vendored
Normal file
76
third_party/spdlog/tests/test_dup_filter.cpp
vendored
Normal file
@ -0,0 +1,76 @@
|
||||
#include "includes.h"
|
||||
#include "spdlog/sinks/dup_filter_sink.h"
|
||||
#include "test_sink.h"
|
||||
|
||||
using namespace spdlog;
|
||||
using namespace spdlog::sinks;
|
||||
|
||||
TEST_CASE("dup_filter_test1", "[dup_filter_sink]")
|
||||
{
|
||||
dup_filter_sink_st dup_sink{std::chrono::seconds{5}};
|
||||
auto test_sink = std::make_shared<test_sink_mt>();
|
||||
dup_sink.add_sink(test_sink);
|
||||
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
dup_sink.log(spdlog::details::log_msg{"test", spdlog::level::info, "message1"});
|
||||
}
|
||||
|
||||
REQUIRE(test_sink->msg_counter() == 1);
|
||||
}
|
||||
|
||||
TEST_CASE("dup_filter_test2", "[dup_filter_sink]")
|
||||
{
|
||||
dup_filter_sink_st dup_sink{std::chrono::seconds{0}};
|
||||
auto test_sink = std::make_shared<test_sink_mt>();
|
||||
dup_sink.add_sink(test_sink);
|
||||
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
dup_sink.log(spdlog::details::log_msg{"test", spdlog::level::info, "message1"});
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(5));
|
||||
}
|
||||
|
||||
REQUIRE(test_sink->msg_counter() == 10);
|
||||
}
|
||||
|
||||
TEST_CASE("dup_filter_test3", "[dup_filter_sink]")
|
||||
{
|
||||
dup_filter_sink_st dup_sink{std::chrono::seconds{1}};
|
||||
auto test_sink = std::make_shared<test_sink_mt>();
|
||||
dup_sink.add_sink(test_sink);
|
||||
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
dup_sink.log(spdlog::details::log_msg{"test", spdlog::level::info, "message1"});
|
||||
dup_sink.log(spdlog::details::log_msg{"test", spdlog::level::info, "message2"});
|
||||
}
|
||||
|
||||
REQUIRE(test_sink->msg_counter() == 20);
|
||||
}
|
||||
|
||||
TEST_CASE("dup_filter_test4", "[dup_filter_sink]")
|
||||
{
|
||||
dup_filter_sink_mt dup_sink{std::chrono::milliseconds{10}};
|
||||
auto test_sink = std::make_shared<test_sink_mt>();
|
||||
dup_sink.add_sink(test_sink);
|
||||
|
||||
dup_sink.log(spdlog::details::log_msg{"test", spdlog::level::info, "message"});
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(50));
|
||||
dup_sink.log(spdlog::details::log_msg{"test", spdlog::level::info, "message"});
|
||||
REQUIRE(test_sink->msg_counter() == 2);
|
||||
}
|
||||
|
||||
TEST_CASE("dup_filter_test5", "[dup_filter_sink]")
|
||||
{
|
||||
dup_filter_sink_mt dup_sink{std::chrono::seconds{5}};
|
||||
auto test_sink = std::make_shared<test_sink_mt>();
|
||||
dup_sink.add_sink(test_sink);
|
||||
|
||||
dup_sink.log(spdlog::details::log_msg{"test", spdlog::level::info, "message1"});
|
||||
dup_sink.log(spdlog::details::log_msg{"test", spdlog::level::info, "message1"});
|
||||
dup_sink.log(spdlog::details::log_msg{"test", spdlog::level::info, "message1"});
|
||||
dup_sink.log(spdlog::details::log_msg{"test", spdlog::level::info, "message2"});
|
||||
|
||||
REQUIRE(test_sink->msg_counter() == 3); // skip 2 messages but log the "skipped.." message before message2
|
||||
}
|
3
third_party/spdlog/tests/test_errors.cpp
vendored
3
third_party/spdlog/tests/test_errors.cpp
vendored
@ -39,8 +39,7 @@ TEST_CASE("default_error_handler", "[errors]]")
|
||||
}
|
||||
|
||||
struct custom_ex
|
||||
{
|
||||
};
|
||||
{};
|
||||
TEST_CASE("custom_error_handler", "[errors]]")
|
||||
{
|
||||
prepare_logdir();
|
||||
|
@ -10,7 +10,7 @@ static const std::string target_filename = "logs/file_helper_test.txt";
|
||||
|
||||
static void write_with_helper(file_helper &helper, size_t howmany)
|
||||
{
|
||||
fmt::memory_buffer formatted;
|
||||
spdlog::memory_buf_t formatted;
|
||||
fmt::format_to(formatted, "{}", std::string(howmany, '1'));
|
||||
helper.write(formatted);
|
||||
helper.flush();
|
||||
|
106
third_party/spdlog/tests/test_file_logging.cpp
vendored
106
third_party/spdlog/tests/test_file_logging.cpp
vendored
@ -60,7 +60,20 @@ TEST_CASE("rotating_file_logger2", "[rotating_logger]]")
|
||||
prepare_logdir();
|
||||
size_t max_size = 1024 * 10;
|
||||
std::string basename = "logs/rotating_log";
|
||||
auto logger = spdlog::rotating_logger_mt("logger", basename, max_size, 1);
|
||||
|
||||
{
|
||||
// make an initial logger to create the first output file
|
||||
auto logger = spdlog::rotating_logger_mt("logger", basename, max_size, 2, true);
|
||||
for (int i = 0; i < 10; ++i)
|
||||
{
|
||||
logger->info("Test message {}", i);
|
||||
}
|
||||
// drop causes the logger destructor to be called, which is required so the
|
||||
// next logger can rename the first output file.
|
||||
spdlog::drop(logger->name());
|
||||
}
|
||||
|
||||
auto logger = spdlog::rotating_logger_mt("logger", basename, max_size, 2, true);
|
||||
for (int i = 0; i < 10; ++i)
|
||||
{
|
||||
logger->info("Test message {}", i);
|
||||
@ -80,94 +93,3 @@ TEST_CASE("rotating_file_logger2", "[rotating_logger]]")
|
||||
auto filename1 = basename + ".1";
|
||||
REQUIRE(get_filesize(filename1) <= max_size);
|
||||
}
|
||||
|
||||
TEST_CASE("daily_logger with dateonly calculator", "[daily_logger_dateonly]]")
|
||||
{
|
||||
using sink_type = spdlog::sinks::daily_file_sink<std::mutex, spdlog::sinks::daily_filename_calculator>;
|
||||
|
||||
prepare_logdir();
|
||||
// calculate filename (time based)
|
||||
std::string basename = "logs/daily_dateonly";
|
||||
std::tm tm = spdlog::details::os::localtime();
|
||||
fmt::memory_buffer w;
|
||||
fmt::format_to(w, "{}_{:04d}-{:02d}-{:02d}", basename, tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday);
|
||||
|
||||
auto logger = spdlog::create<sink_type>("logger", basename, 0, 0);
|
||||
for (int i = 0; i < 10; ++i)
|
||||
{
|
||||
|
||||
logger->info("Test message {}", i);
|
||||
}
|
||||
logger->flush();
|
||||
auto filename = fmt::to_string(w);
|
||||
REQUIRE(count_lines(filename) == 10);
|
||||
}
|
||||
|
||||
struct custom_daily_file_name_calculator
|
||||
{
|
||||
static spdlog::filename_t calc_filename(const spdlog::filename_t &basename, const tm &now_tm)
|
||||
{
|
||||
fmt::memory_buffer w;
|
||||
fmt::format_to(w, "{}{:04d}{:02d}{:02d}", basename, now_tm.tm_year + 1900, now_tm.tm_mon + 1, now_tm.tm_mday);
|
||||
return fmt::to_string(w);
|
||||
}
|
||||
};
|
||||
|
||||
TEST_CASE("daily_logger with custom calculator", "[daily_logger_custom]]")
|
||||
{
|
||||
using sink_type = spdlog::sinks::daily_file_sink<std::mutex, custom_daily_file_name_calculator>;
|
||||
|
||||
prepare_logdir();
|
||||
// calculate filename (time based)
|
||||
std::string basename = "logs/daily_dateonly";
|
||||
std::tm tm = spdlog::details::os::localtime();
|
||||
fmt::memory_buffer w;
|
||||
fmt::format_to(w, "{}{:04d}{:02d}{:02d}", basename, tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday);
|
||||
|
||||
auto logger = spdlog::create<sink_type>("logger", basename, 0, 0);
|
||||
for (int i = 0; i < 10; ++i)
|
||||
{
|
||||
logger->info("Test message {}", i);
|
||||
}
|
||||
|
||||
logger->flush();
|
||||
auto filename = fmt::to_string(w);
|
||||
REQUIRE(count_lines(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)
|
||||
#include <regex>
|
||||
|
||||
TEST_CASE("daily_file_sink::daily_filename_calculator", "[daily_file_sink]]")
|
||||
{
|
||||
// daily_YYYY-MM-DD_hh-mm.txt
|
||||
auto filename = spdlog::sinks::daily_filename_calculator::calc_filename("daily.txt", spdlog::details::os::localtime());
|
||||
// date regex based on https://www.regular-expressions.info/dates.html
|
||||
std::regex re(R"(^daily_(19|20)\d\d-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])\.txt$)");
|
||||
std::smatch match;
|
||||
REQUIRE(std::regex_match(filename, match, re));
|
||||
}
|
||||
#endif
|
||||
|
11
third_party/spdlog/tests/test_fmt_helper.cpp
vendored
11
third_party/spdlog/tests/test_fmt_helper.cpp
vendored
@ -1,30 +1,33 @@
|
||||
|
||||
#include "includes.h"
|
||||
#include "spdlog/details/fmt_helper.h"
|
||||
|
||||
using spdlog::memory_buf_t;
|
||||
|
||||
void test_pad2(int n, const char *expected)
|
||||
{
|
||||
fmt::memory_buffer buf;
|
||||
memory_buf_t buf;
|
||||
spdlog::details::fmt_helper::pad2(n, buf);
|
||||
REQUIRE(fmt::to_string(buf) == expected);
|
||||
}
|
||||
|
||||
void test_pad3(uint32_t n, const char *expected)
|
||||
{
|
||||
fmt::memory_buffer buf;
|
||||
memory_buf_t buf;
|
||||
spdlog::details::fmt_helper::pad3(n, buf);
|
||||
REQUIRE(fmt::to_string(buf) == expected);
|
||||
}
|
||||
|
||||
void test_pad6(std::size_t n, const char *expected)
|
||||
{
|
||||
fmt::memory_buffer buf;
|
||||
memory_buf_t buf;
|
||||
spdlog::details::fmt_helper::pad6(n, buf);
|
||||
REQUIRE(fmt::to_string(buf) == expected);
|
||||
}
|
||||
|
||||
void test_pad9(std::size_t n, const char *expected)
|
||||
{
|
||||
fmt::memory_buffer buf;
|
||||
memory_buf_t buf;
|
||||
spdlog::details::fmt_helper::pad9(n, buf);
|
||||
REQUIRE(fmt::to_string(buf) == expected);
|
||||
}
|
||||
|
39
third_party/spdlog/tests/test_misc.cpp
vendored
39
third_party/spdlog/tests/test_misc.cpp
vendored
@ -1,5 +1,6 @@
|
||||
#include "includes.h"
|
||||
#include "test_sink.h"
|
||||
#include "spdlog/fmt/bin_to_hex.h"
|
||||
|
||||
template<class T>
|
||||
std::string log_info(const T &what, spdlog::level::level_enum logger_level = spdlog::level::info)
|
||||
@ -95,8 +96,9 @@ TEST_CASE("periodic flush", "[periodic_flush]")
|
||||
TEST_CASE("clone-logger", "[clone]")
|
||||
{
|
||||
using namespace spdlog;
|
||||
|
||||
auto logger = spdlog::create<sinks::test_sink_mt>("orig");
|
||||
auto test_sink = std::make_shared<sinks::test_sink_mt>();
|
||||
auto logger = std::make_shared<spdlog::logger>("orig", test_sink);
|
||||
logger->set_pattern("%v");
|
||||
auto cloned = logger->clone("clone");
|
||||
|
||||
REQUIRE(cloned->name() == "clone");
|
||||
@ -106,8 +108,9 @@ TEST_CASE("clone-logger", "[clone]")
|
||||
logger->info("Some message 1");
|
||||
cloned->info("Some message 2");
|
||||
|
||||
auto test_sink = std::static_pointer_cast<sinks::test_sink_mt>(cloned->sinks()[0]);
|
||||
REQUIRE(test_sink->msg_counter() == 2);
|
||||
REQUIRE(test_sink->lines().size() == 2);
|
||||
REQUIRE(test_sink->lines()[0] == "Some message 1");
|
||||
REQUIRE(test_sink->lines()[1] == "Some message 2");
|
||||
|
||||
spdlog::drop_all();
|
||||
}
|
||||
@ -116,7 +119,10 @@ TEST_CASE("clone async", "[clone]")
|
||||
{
|
||||
using namespace spdlog;
|
||||
|
||||
auto logger = spdlog::create_async<sinks::test_sink_mt>("orig");
|
||||
spdlog::init_thread_pool(4, 1);
|
||||
auto test_sink = std::make_shared<sinks::test_sink_st>();
|
||||
auto logger = std::make_shared<spdlog::async_logger>("orig", test_sink, spdlog::thread_pool());
|
||||
logger->set_pattern("%v");
|
||||
auto cloned = logger->clone("clone");
|
||||
|
||||
REQUIRE(cloned->name() == "clone");
|
||||
@ -129,14 +135,13 @@ TEST_CASE("clone async", "[clone]")
|
||||
|
||||
spdlog::details::os::sleep_for_millis(10);
|
||||
|
||||
auto test_sink = std::static_pointer_cast<sinks::test_sink_mt>(cloned->sinks()[0]);
|
||||
REQUIRE(test_sink->msg_counter() == 2);
|
||||
REQUIRE(test_sink->lines().size() == 2);
|
||||
REQUIRE(test_sink->lines()[0] == "Some message 1");
|
||||
REQUIRE(test_sink->lines()[1] == "Some message 2");
|
||||
|
||||
spdlog::drop_all();
|
||||
}
|
||||
|
||||
#include "spdlog/fmt/bin_to_hex.h"
|
||||
|
||||
TEST_CASE("to_hex", "[to_hex]")
|
||||
{
|
||||
std::ostringstream oss;
|
||||
@ -176,22 +181,6 @@ TEST_CASE("to_hex_no_delimiter", "[to_hex]")
|
||||
REQUIRE(ends_with(output, "0000: 090A0B0CFFFF" + std::string(spdlog::details::os::default_eol)));
|
||||
}
|
||||
|
||||
TEST_CASE("message_counter", "[message_counter]")
|
||||
{
|
||||
std::ostringstream oss;
|
||||
auto oss_sink = std::make_shared<spdlog::sinks::ostream_sink_mt>(oss);
|
||||
spdlog::logger oss_logger("oss", oss_sink);
|
||||
oss_logger.set_pattern("%i %v");
|
||||
|
||||
oss_logger.info("Hello");
|
||||
REQUIRE(oss.str() == "000001 Hello" + std::string(spdlog::details::os::default_eol));
|
||||
|
||||
oss.str("");
|
||||
oss_logger.info("Hello again");
|
||||
|
||||
REQUIRE(oss.str() == "000002 Hello again" + std::string(spdlog::details::os::default_eol));
|
||||
}
|
||||
|
||||
TEST_CASE("default logger API", "[default logger]")
|
||||
{
|
||||
std::ostringstream oss;
|
||||
|
2
third_party/spdlog/tests/test_mpmc_q.cpp
vendored
2
third_party/spdlog/tests/test_mpmc_q.cpp
vendored
@ -29,7 +29,7 @@ TEST_CASE("dequeue-empty-wait", "[mpmc_blocking_q]")
|
||||
|
||||
size_t q_size = 100;
|
||||
milliseconds wait_ms(250);
|
||||
milliseconds tolerance_wait(50);
|
||||
milliseconds tolerance_wait(250);
|
||||
|
||||
spdlog::details::mpmc_blocking_queue<int> q(q_size);
|
||||
int popped_item;
|
||||
|
119
third_party/spdlog/tests/test_pattern_formatter.cpp
vendored
119
third_party/spdlog/tests/test_pattern_formatter.cpp
vendored
@ -1,8 +1,9 @@
|
||||
#include "includes.h"
|
||||
|
||||
using spdlog::memory_buf_t;
|
||||
|
||||
// log to str and return it
|
||||
template<typename... Args>
|
||||
|
||||
static std::string log_to_str(const std::string &msg, const Args &... args)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
@ -61,11 +62,11 @@ TEST_CASE("color range test1", "[pattern_formatter]")
|
||||
{
|
||||
auto formatter = std::make_shared<spdlog::pattern_formatter>("%^%v%$", spdlog::pattern_time_type::local, "\n");
|
||||
|
||||
fmt::memory_buffer buf;
|
||||
memory_buf_t buf;
|
||||
fmt::format_to(buf, "Hello");
|
||||
fmt::memory_buffer formatted;
|
||||
memory_buf_t formatted;
|
||||
std::string logger_name = "test";
|
||||
spdlog::details::log_msg msg(&logger_name, spdlog::level::info, spdlog::string_view_t(buf.data(), buf.size()));
|
||||
spdlog::details::log_msg msg(logger_name, spdlog::level::info, spdlog::string_view_t(buf.data(), buf.size()));
|
||||
formatter->format(msg, formatted);
|
||||
REQUIRE(msg.color_range_start == 0);
|
||||
REQUIRE(msg.color_range_end == 5);
|
||||
@ -76,8 +77,8 @@ TEST_CASE("color range test2", "[pattern_formatter]")
|
||||
{
|
||||
auto formatter = std::make_shared<spdlog::pattern_formatter>("%^%$", spdlog::pattern_time_type::local, "\n");
|
||||
std::string logger_name = "test";
|
||||
spdlog::details::log_msg msg(&logger_name, spdlog::level::info, "");
|
||||
fmt::memory_buffer formatted;
|
||||
spdlog::details::log_msg msg(logger_name, spdlog::level::info, "");
|
||||
memory_buf_t formatted;
|
||||
formatter->format(msg, formatted);
|
||||
REQUIRE(msg.color_range_start == 0);
|
||||
REQUIRE(msg.color_range_end == 0);
|
||||
@ -88,8 +89,8 @@ TEST_CASE("color range test3", "[pattern_formatter]")
|
||||
{
|
||||
auto formatter = std::make_shared<spdlog::pattern_formatter>("%^***%$");
|
||||
std::string logger_name = "test";
|
||||
spdlog::details::log_msg msg(&logger_name, spdlog::level::info, "ignored");
|
||||
fmt::memory_buffer formatted;
|
||||
spdlog::details::log_msg msg(logger_name, spdlog::level::info, "ignored");
|
||||
memory_buf_t formatted;
|
||||
formatter->format(msg, formatted);
|
||||
REQUIRE(msg.color_range_start == 0);
|
||||
REQUIRE(msg.color_range_end == 3);
|
||||
@ -99,9 +100,9 @@ TEST_CASE("color range test4", "[pattern_formatter]")
|
||||
{
|
||||
auto formatter = std::make_shared<spdlog::pattern_formatter>("XX%^YYY%$", spdlog::pattern_time_type::local, "\n");
|
||||
std::string logger_name = "test";
|
||||
spdlog::details::log_msg msg(&logger_name, spdlog::level::info, "ignored");
|
||||
spdlog::details::log_msg msg(logger_name, spdlog::level::info, "ignored");
|
||||
|
||||
fmt::memory_buffer formatted;
|
||||
memory_buf_t formatted;
|
||||
formatter->format(msg, formatted);
|
||||
REQUIRE(msg.color_range_start == 2);
|
||||
REQUIRE(msg.color_range_end == 5);
|
||||
@ -112,8 +113,8 @@ TEST_CASE("color range test5", "[pattern_formatter]")
|
||||
{
|
||||
auto formatter = std::make_shared<spdlog::pattern_formatter>("**%^");
|
||||
std::string logger_name = "test";
|
||||
spdlog::details::log_msg msg(&logger_name, spdlog::level::info, "ignored");
|
||||
fmt::memory_buffer formatted;
|
||||
spdlog::details::log_msg msg(logger_name, spdlog::level::info, "ignored");
|
||||
memory_buf_t formatted;
|
||||
formatter->format(msg, formatted);
|
||||
REQUIRE(msg.color_range_start == 2);
|
||||
REQUIRE(msg.color_range_end == 0);
|
||||
@ -123,8 +124,8 @@ TEST_CASE("color range test6", "[pattern_formatter]")
|
||||
{
|
||||
auto formatter = std::make_shared<spdlog::pattern_formatter>("**%$");
|
||||
std::string logger_name = "test";
|
||||
spdlog::details::log_msg msg(&logger_name, spdlog::level::info, "ignored");
|
||||
fmt::memory_buffer formatted;
|
||||
spdlog::details::log_msg msg(logger_name, spdlog::level::info, "ignored");
|
||||
memory_buf_t formatted;
|
||||
formatter->format(msg, formatted);
|
||||
REQUIRE(msg.color_range_start == 0);
|
||||
REQUIRE(msg.color_range_end == 2);
|
||||
@ -181,18 +182,14 @@ TEST_CASE("center_padded_short", "[pattern_formatter]")
|
||||
|
||||
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", "[%-300n] %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", "[%-128n] %v", spdlog::pattern_time_type::local, "\n") ==
|
||||
"[pattern_tester ]"
|
||||
" Some message\n");
|
||||
REQUIRE(log_to_str("Some message", "[%-64n] %v", spdlog::pattern_time_type::local, "\n") ==
|
||||
"[pattern_tester ] Some message\n");
|
||||
}
|
||||
|
||||
TEST_CASE("clone-default-formatter", "[pattern_formatter]")
|
||||
@ -200,10 +197,10 @@ TEST_CASE("clone-default-formatter", "[pattern_formatter]")
|
||||
auto formatter_1 = std::make_shared<spdlog::pattern_formatter>();
|
||||
auto formatter_2 = formatter_1->clone();
|
||||
std::string logger_name = "test";
|
||||
spdlog::details::log_msg msg(&logger_name, spdlog::level::info, "some message");
|
||||
spdlog::details::log_msg msg(logger_name, spdlog::level::info, "some message");
|
||||
|
||||
fmt::memory_buffer formatted_1;
|
||||
fmt::memory_buffer formatted_2;
|
||||
memory_buf_t formatted_1;
|
||||
memory_buf_t formatted_2;
|
||||
formatter_1->format(msg, formatted_1);
|
||||
formatter_2->format(msg, formatted_2);
|
||||
|
||||
@ -215,10 +212,10 @@ TEST_CASE("clone-default-formatter2", "[pattern_formatter]")
|
||||
auto formatter_1 = std::make_shared<spdlog::pattern_formatter>("%+");
|
||||
auto formatter_2 = formatter_1->clone();
|
||||
std::string logger_name = "test";
|
||||
spdlog::details::log_msg msg(&logger_name, spdlog::level::info, "some message");
|
||||
spdlog::details::log_msg msg(logger_name, spdlog::level::info, "some message");
|
||||
|
||||
fmt::memory_buffer formatted_1;
|
||||
fmt::memory_buffer formatted_2;
|
||||
memory_buf_t formatted_1;
|
||||
memory_buf_t formatted_2;
|
||||
formatter_1->format(msg, formatted_1);
|
||||
formatter_2->format(msg, formatted_2);
|
||||
|
||||
@ -230,10 +227,10 @@ TEST_CASE("clone-formatter", "[pattern_formatter]")
|
||||
auto formatter_1 = std::make_shared<spdlog::pattern_formatter>("%D %X [%] [%n] %v");
|
||||
auto formatter_2 = formatter_1->clone();
|
||||
std::string logger_name = "test";
|
||||
spdlog::details::log_msg msg(&logger_name, spdlog::level::info, "some message");
|
||||
spdlog::details::log_msg msg(logger_name, spdlog::level::info, "some message");
|
||||
|
||||
fmt::memory_buffer formatted_1;
|
||||
fmt::memory_buffer formatted_2;
|
||||
memory_buf_t formatted_1;
|
||||
memory_buf_t formatted_2;
|
||||
formatter_1->format(msg, formatted_1);
|
||||
formatter_2->format(msg, formatted_2);
|
||||
REQUIRE(fmt::to_string(formatted_1) == fmt::to_string(formatted_2));
|
||||
@ -245,11 +242,65 @@ TEST_CASE("clone-formatter-2", "[pattern_formatter]")
|
||||
auto formatter_1 = std::make_shared<spdlog::pattern_formatter>("%D %X [%] [%n] %v", pattern_time_type::utc, "xxxxxx\n");
|
||||
auto formatter_2 = formatter_1->clone();
|
||||
std::string logger_name = "test2";
|
||||
spdlog::details::log_msg msg(&logger_name, spdlog::level::info, "some message");
|
||||
spdlog::details::log_msg msg(logger_name, spdlog::level::info, "some message");
|
||||
|
||||
fmt::memory_buffer formatted_1;
|
||||
fmt::memory_buffer formatted_2;
|
||||
memory_buf_t formatted_1;
|
||||
memory_buf_t formatted_2;
|
||||
formatter_1->format(msg, formatted_1);
|
||||
formatter_2->format(msg, formatted_2);
|
||||
REQUIRE(fmt::to_string(formatted_1) == fmt::to_string(formatted_2));
|
||||
}
|
||||
|
||||
//
|
||||
// Test source location formatting
|
||||
//
|
||||
|
||||
#ifdef _WIN32
|
||||
static const char *test_path = "\\a\\b\\myfile.cpp";
|
||||
#else
|
||||
static const char *test_path = "/a/b//myfile.cpp";
|
||||
#endif
|
||||
|
||||
TEST_CASE("short filename formatter-1", "[pattern_formatter]")
|
||||
{
|
||||
spdlog::pattern_formatter formatter("%s", spdlog::pattern_time_type::local, "");
|
||||
memory_buf_t formatted;
|
||||
std::string logger_name = "logger-name";
|
||||
spdlog::source_loc source_loc{test_path, 123, "some_func()"};
|
||||
spdlog::details::log_msg msg(source_loc, "logger-name", spdlog::level::info, "Hello");
|
||||
formatter.format(msg, formatted);
|
||||
REQUIRE(fmt::to_string(formatted) == "myfile.cpp");
|
||||
}
|
||||
|
||||
TEST_CASE("short filename formatter-2", "[pattern_formatter]")
|
||||
{
|
||||
spdlog::pattern_formatter formatter("%s:%#", spdlog::pattern_time_type::local, "");
|
||||
memory_buf_t formatted;
|
||||
std::string logger_name = "logger-name";
|
||||
spdlog::source_loc source_loc{"myfile.cpp", 123, "some_func()"};
|
||||
spdlog::details::log_msg msg(source_loc, "logger-name", spdlog::level::info, "Hello");
|
||||
formatter.format(msg, formatted);
|
||||
REQUIRE(fmt::to_string(formatted) == "myfile.cpp:123");
|
||||
}
|
||||
|
||||
TEST_CASE("short filename formatter-3", "[pattern_formatter]")
|
||||
{
|
||||
spdlog::pattern_formatter formatter("%s %v", spdlog::pattern_time_type::local, "");
|
||||
memory_buf_t formatted;
|
||||
std::string logger_name = "logger-name";
|
||||
spdlog::source_loc source_loc{"", 123, "some_func()"};
|
||||
spdlog::details::log_msg msg(source_loc, "logger-name", spdlog::level::info, "Hello");
|
||||
formatter.format(msg, formatted);
|
||||
REQUIRE(fmt::to_string(formatted) == " Hello");
|
||||
}
|
||||
|
||||
TEST_CASE("full filename formatter", "[pattern_formatter]")
|
||||
{
|
||||
spdlog::pattern_formatter formatter("%g", spdlog::pattern_time_type::local, "");
|
||||
memory_buf_t formatted;
|
||||
std::string logger_name = "logger-name";
|
||||
spdlog::source_loc source_loc{test_path, 123, "some_func()"};
|
||||
spdlog::details::log_msg msg(source_loc, "logger-name", spdlog::level::info, "Hello");
|
||||
formatter.format(msg, formatted);
|
||||
REQUIRE(fmt::to_string(formatted) == test_path);
|
||||
}
|
||||
|
6
third_party/spdlog/tests/test_registry.cpp
vendored
6
third_party/spdlog/tests/test_registry.cpp
vendored
@ -3,13 +3,14 @@
|
||||
static const char *tested_logger_name = "null_logger";
|
||||
static const char *tested_logger_name2 = "null_logger2";
|
||||
|
||||
#ifndef SPDLOG_NO_EXCEPTIONS
|
||||
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
|
||||
REQUIRE_THROWS_AS(spdlog::create<spdlog::sinks::null_sink_mt>(tested_logger_name), const spdlog::spdlog_ex &);
|
||||
REQUIRE_THROWS_AS(spdlog::create<spdlog::sinks::null_sink_mt>(tested_logger_name), spdlog::spdlog_ex);
|
||||
}
|
||||
|
||||
TEST_CASE("explicit register", "[registry]")
|
||||
@ -19,8 +20,9 @@ TEST_CASE("explicit register", "[registry]")
|
||||
spdlog::register_logger(logger);
|
||||
REQUIRE(spdlog::get(tested_logger_name) != nullptr);
|
||||
// Throw if registring existing name
|
||||
REQUIRE_THROWS_AS(spdlog::create<spdlog::sinks::null_sink_mt>(tested_logger_name), const spdlog::spdlog_ex &);
|
||||
REQUIRE_THROWS_AS(spdlog::create<spdlog::sinks::null_sink_mt>(tested_logger_name), spdlog::spdlog_ex);
|
||||
}
|
||||
#endif
|
||||
|
||||
TEST_CASE("apply_all", "[registry]")
|
||||
{
|
||||
|
26
third_party/spdlog/tests/test_sink.h
vendored
26
third_party/spdlog/tests/test_sink.h
vendored
@ -7,7 +7,7 @@
|
||||
|
||||
#include "spdlog/details/null_mutex.h"
|
||||
#include "spdlog/sinks/base_sink.h"
|
||||
|
||||
#include "spdlog/fmt/fmt.h"
|
||||
#include <chrono>
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
@ -18,6 +18,8 @@ namespace sinks {
|
||||
template<class Mutex>
|
||||
class test_sink : public base_sink<Mutex>
|
||||
{
|
||||
const size_t lines_to_save = 100;
|
||||
|
||||
public:
|
||||
size_t msg_counter()
|
||||
{
|
||||
@ -33,12 +35,28 @@ public:
|
||||
|
||||
void set_delay(std::chrono::milliseconds delay)
|
||||
{
|
||||
std::lock_guard<Mutex> lock(base_sink<Mutex>::mutex_);
|
||||
delay_ = delay;
|
||||
}
|
||||
|
||||
protected:
|
||||
void sink_it_(const details::log_msg &) override
|
||||
// return last output without the eol
|
||||
std::vector<std::string> lines()
|
||||
{
|
||||
std::lock_guard<Mutex> lock(base_sink<Mutex>::mutex_);
|
||||
return lines_;
|
||||
}
|
||||
|
||||
protected:
|
||||
void sink_it_(const details::log_msg &msg) override
|
||||
{
|
||||
memory_buf_t formatted;
|
||||
base_sink<Mutex>::formatter_->format(msg, formatted);
|
||||
// save the line without the eol
|
||||
auto eol_len = strlen(details::os::default_eol);
|
||||
if (lines_.size() < lines_to_save)
|
||||
{
|
||||
lines_.emplace_back(formatted.begin(), formatted.end() - eol_len);
|
||||
}
|
||||
msg_counter_++;
|
||||
std::this_thread::sleep_for(delay_);
|
||||
}
|
||||
@ -47,9 +65,11 @@ protected:
|
||||
{
|
||||
flush_counter_++;
|
||||
}
|
||||
|
||||
size_t msg_counter_{0};
|
||||
size_t flush_counter_{0};
|
||||
std::chrono::milliseconds delay_{std::chrono::milliseconds::zero()};
|
||||
std::vector<std::string> lines_;
|
||||
};
|
||||
|
||||
using test_sink_mt = test_sink<std::mutex>;
|
||||
|
98
third_party/spdlog/tests/test_stdout_api.cpp
vendored
Normal file
98
third_party/spdlog/tests/test_stdout_api.cpp
vendored
Normal file
@ -0,0 +1,98 @@
|
||||
/*
|
||||
* This content is released under the MIT License as specified in https://raw.githubusercontent.com/gabime/spdlog/master/LICENSE
|
||||
*/
|
||||
#include "includes.h"
|
||||
#include "spdlog/sinks/stdout_sinks.h"
|
||||
#include "spdlog/sinks/stdout_color_sinks.h"
|
||||
TEST_CASE("stdout_st", "[stdout]")
|
||||
{
|
||||
auto l = spdlog::stdout_logger_st("test");
|
||||
l->set_pattern("%+");
|
||||
l->set_level(spdlog::level::trace);
|
||||
l->trace("Test stdout_st");
|
||||
spdlog::drop_all();
|
||||
}
|
||||
|
||||
TEST_CASE("stdout_mt", "[stdout]")
|
||||
{
|
||||
auto l = spdlog::stdout_logger_mt("test");
|
||||
l->set_pattern("%+");
|
||||
l->set_level(spdlog::level::debug);
|
||||
l->debug("Test stdout_mt");
|
||||
spdlog::drop_all();
|
||||
}
|
||||
|
||||
TEST_CASE("stderr_st", "[stderr]")
|
||||
{
|
||||
auto l = spdlog::stderr_logger_st("test");
|
||||
l->set_pattern("%+");
|
||||
l->info("Test stderr_st");
|
||||
spdlog::drop_all();
|
||||
}
|
||||
|
||||
TEST_CASE("stderr_mt", "[stderr]")
|
||||
{
|
||||
auto l = spdlog::stderr_logger_mt("test");
|
||||
l->set_pattern("%+");
|
||||
l->info("Test stderr_mt");
|
||||
l->warn("Test stderr_mt");
|
||||
l->error("Test stderr_mt");
|
||||
l->critical("Test stderr_mt");
|
||||
spdlog::drop_all();
|
||||
}
|
||||
|
||||
// color loggers
|
||||
TEST_CASE("stdout_color_st", "[stdout]")
|
||||
{
|
||||
auto l = spdlog::stdout_color_st("test");
|
||||
l->set_pattern("%+");
|
||||
l->info("Test stdout_color_st");
|
||||
spdlog::drop_all();
|
||||
}
|
||||
|
||||
TEST_CASE("stdout_color_mt", "[stdout]")
|
||||
{
|
||||
auto l = spdlog::stdout_color_mt("test");
|
||||
l->set_pattern("%+");
|
||||
l->set_level(spdlog::level::trace);
|
||||
l->trace("Test stdout_color_mt");
|
||||
spdlog::drop_all();
|
||||
}
|
||||
|
||||
TEST_CASE("stderr_color_st", "[stderr]")
|
||||
{
|
||||
auto l = spdlog::stderr_color_st("test");
|
||||
l->set_pattern("%+");
|
||||
l->set_level(spdlog::level::debug);
|
||||
l->debug("Test stderr_color_st");
|
||||
spdlog::drop_all();
|
||||
}
|
||||
|
||||
TEST_CASE("stderr_color_mt", "[stderr]")
|
||||
{
|
||||
auto l = spdlog::stderr_color_mt("test");
|
||||
l->set_pattern("%+");
|
||||
l->info("Test stderr_color_mt");
|
||||
l->warn("Test stderr_color_mt");
|
||||
l->error("Test stderr_color_mt");
|
||||
l->critical("Test stderr_color_mt");
|
||||
spdlog::drop_all();
|
||||
}
|
||||
|
||||
#ifdef SPDLOG_WCHAR_TO_UTF8_SUPPORT
|
||||
|
||||
TEST_CASE("wchar_api", "[stdout]")
|
||||
{
|
||||
auto l = spdlog::stdout_logger_st("wchar_logger");
|
||||
l->set_pattern("%+");
|
||||
l->set_level(spdlog::level::trace);
|
||||
l->trace(L"Test wchar_api");
|
||||
l->trace(L"Test wchar_api {}", L"param");
|
||||
l->trace(L"Test wchar_api {}", 1);
|
||||
l->trace(L"Test wchar_api {}", std::wstring{L"wstring param"});
|
||||
l->trace(std::wstring{L"Test wchar_api wstring"});
|
||||
SPDLOG_LOGGER_DEBUG(l, L"Test SPDLOG_LOGGER_DEBUG {}", L"param");
|
||||
spdlog::drop_all();
|
||||
}
|
||||
|
||||
#endif
|
15
third_party/spdlog/tests/test_systemd.cpp
vendored
Normal file
15
third_party/spdlog/tests/test_systemd.cpp
vendored
Normal file
@ -0,0 +1,15 @@
|
||||
#include "includes.h"
|
||||
#include "spdlog/sinks/systemd_sink.h"
|
||||
|
||||
TEST_CASE("systemd", "[all]")
|
||||
{
|
||||
auto systemd_sink = std::make_shared<spdlog::sinks::systemd_sink_st>();
|
||||
spdlog::logger logger("spdlog_systemd_test", systemd_sink);
|
||||
logger.set_level(spdlog::level::trace);
|
||||
logger.trace("test spdlog trace");
|
||||
logger.debug("test spdlog debug");
|
||||
SPDLOG_LOGGER_INFO((&logger), "test spdlog info");
|
||||
SPDLOG_LOGGER_WARN((&logger), "test spdlog warn");
|
||||
SPDLOG_LOGGER_ERROR((&logger), "test spdlog error");
|
||||
SPDLOG_LOGGER_CRITICAL((&logger), "test spdlog critical");
|
||||
}
|
98
third_party/spdlog/tests/tests.sln
vendored
98
third_party/spdlog/tests/tests.sln
vendored
@ -1,98 +0,0 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 15
|
||||
VisualStudioVersion = 15.0.27428.2037
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "tests", "tests.vcxproj", "{59A07559-5F38-4DD6-A7FA-DB4153690B42}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "spdlog", "spdlog", "{0C043010-E40A-43B9-A5EA-B931FC8B6EFB}"
|
||||
ProjectSection(SolutionItems) = preProject
|
||||
..\include\spdlog\async.h = ..\include\spdlog\async.h
|
||||
..\include\spdlog\async_logger.h = ..\include\spdlog\async_logger.h
|
||||
..\include\spdlog\common.h = ..\include\spdlog\common.h
|
||||
..\include\spdlog\formatter.h = ..\include\spdlog\formatter.h
|
||||
..\include\spdlog\logger.h = ..\include\spdlog\logger.h
|
||||
..\include\spdlog\spdlog.h = ..\include\spdlog\spdlog.h
|
||||
..\include\spdlog\tweakme.h = ..\include\spdlog\tweakme.h
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "details", "details", "{C8A207B7-6930-4D28-85BB-EA79ADFD7DAC}"
|
||||
ProjectSection(SolutionItems) = preProject
|
||||
..\include\spdlog\details\async_logger_impl.h = ..\include\spdlog\details\async_logger_impl.h
|
||||
..\include\spdlog\details\file_helper.h = ..\include\spdlog\details\file_helper.h
|
||||
..\include\spdlog\details\log_msg.h = ..\include\spdlog\details\log_msg.h
|
||||
..\include\spdlog\details\logger_impl.h = ..\include\spdlog\details\logger_impl.h
|
||||
..\include\spdlog\details\mpmc_bounded_q.h = ..\include\spdlog\details\mpmc_bounded_q.h
|
||||
..\include\spdlog\details\null_mutex.h = ..\include\spdlog\details\null_mutex.h
|
||||
..\include\spdlog\details\os.h = ..\include\spdlog\details\os.h
|
||||
..\include\spdlog\details\pattern_formatter.h = ..\include\spdlog\details\pattern_formatter.h
|
||||
..\include\spdlog\details\registry.h = ..\include\spdlog\details\registry.h
|
||||
..\include\spdlog\details\spdlog_impl.h = ..\include\spdlog\details\spdlog_impl.h
|
||||
..\include\spdlog\details\thread_pool.h = ..\include\spdlog\details\thread_pool.h
|
||||
..\include\spdlog\details\traits.h = ..\include\spdlog\details\traits.h
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "fmt", "fmt", "{6512BA57-E9B9-4971-BC3A-83C784CC59A5}"
|
||||
ProjectSection(SolutionItems) = preProject
|
||||
..\include\spdlog\fmt\fmt.h = ..\include\spdlog\fmt\fmt.h
|
||||
..\include\spdlog\fmt\ostr.h = ..\include\spdlog\fmt\ostr.h
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "bundled", "bundled", "{F0D4A944-E0C7-4575-8254-06AC92B384E6}"
|
||||
ProjectSection(SolutionItems) = preProject
|
||||
..\include\spdlog\fmt\bundled\format.cc = ..\include\spdlog\fmt\bundled\format.cc
|
||||
..\include\spdlog\fmt\bundled\format.h = ..\include\spdlog\fmt\bundled\format.h
|
||||
..\include\spdlog\fmt\bundled\LICENSE.rst = ..\include\spdlog\fmt\bundled\LICENSE.rst
|
||||
..\include\spdlog\fmt\bundled\ostream.cc = ..\include\spdlog\fmt\bundled\ostream.cc
|
||||
..\include\spdlog\fmt\bundled\ostream.h = ..\include\spdlog\fmt\bundled\ostream.h
|
||||
..\include\spdlog\fmt\bundled\posix.cc = ..\include\spdlog\fmt\bundled\posix.cc
|
||||
..\include\spdlog\fmt\bundled\posix.h = ..\include\spdlog\fmt\bundled\posix.h
|
||||
..\include\spdlog\fmt\bundled\time.h = ..\include\spdlog\fmt\bundled\time.h
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "sinks", "sinks", "{093AE34A-B617-467E-8F31-3C5A85EF51EB}"
|
||||
ProjectSection(SolutionItems) = preProject
|
||||
..\include\spdlog\sinks\android_sink.h = ..\include\spdlog\sinks\android_sink.h
|
||||
..\include\spdlog\sinks\ansicolor_sink.h = ..\include\spdlog\sinks\ansicolor_sink.h
|
||||
..\include\spdlog\sinks\base_sink.h = ..\include\spdlog\sinks\base_sink.h
|
||||
..\include\spdlog\sinks\dist_sink.h = ..\include\spdlog\sinks\dist_sink.h
|
||||
..\include\spdlog\sinks\msvc_sink.h = ..\include\spdlog\sinks\msvc_sink.h
|
||||
..\include\spdlog\sinks\null_sink.h = ..\include\spdlog\sinks\null_sink.h
|
||||
..\include\spdlog\sinks\ostream_sink.h = ..\include\spdlog\sinks\ostream_sink.h
|
||||
..\include\spdlog\sinks\sink.h = ..\include\spdlog\sinks\sink.h
|
||||
..\include\spdlog\sinks\stdout_color_sinks.h = ..\include\spdlog\sinks\stdout_color_sinks.h
|
||||
..\include\spdlog\sinks\stdout_sinks.h = ..\include\spdlog\sinks\stdout_sinks.h
|
||||
..\include\spdlog\sinks\syslog_sink.h = ..\include\spdlog\sinks\syslog_sink.h
|
||||
..\include\spdlog\sinks\wincolor_sink.h = ..\include\spdlog\sinks\wincolor_sink.h
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Win32 = Debug|Win32
|
||||
Debug|x64 = Debug|x64
|
||||
Release|Win32 = Release|Win32
|
||||
Release|x64 = Release|x64
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{59A07559-5F38-4DD6-A7FA-DB4153690B42}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{59A07559-5F38-4DD6-A7FA-DB4153690B42}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{59A07559-5F38-4DD6-A7FA-DB4153690B42}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{59A07559-5F38-4DD6-A7FA-DB4153690B42}.Debug|x64.Build.0 = Debug|x64
|
||||
{59A07559-5F38-4DD6-A7FA-DB4153690B42}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{59A07559-5F38-4DD6-A7FA-DB4153690B42}.Release|Win32.Build.0 = Release|Win32
|
||||
{59A07559-5F38-4DD6-A7FA-DB4153690B42}.Release|x64.ActiveCfg = Release|x64
|
||||
{59A07559-5F38-4DD6-A7FA-DB4153690B42}.Release|x64.Build.0 = Release|x64
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(NestedProjects) = preSolution
|
||||
{C8A207B7-6930-4D28-85BB-EA79ADFD7DAC} = {0C043010-E40A-43B9-A5EA-B931FC8B6EFB}
|
||||
{6512BA57-E9B9-4971-BC3A-83C784CC59A5} = {0C043010-E40A-43B9-A5EA-B931FC8B6EFB}
|
||||
{F0D4A944-E0C7-4575-8254-06AC92B384E6} = {6512BA57-E9B9-4971-BC3A-83C784CC59A5}
|
||||
{093AE34A-B617-467E-8F31-3C5A85EF51EB} = {0C043010-E40A-43B9-A5EA-B931FC8B6EFB}
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {1D363F0E-2DC2-4544-963A-9812679AFF6B}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
148
third_party/spdlog/tests/tests.vcxproj
vendored
148
third_party/spdlog/tests/tests.vcxproj
vendored
@ -1,148 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{59A07559-5F38-4DD6-A7FA-DB4153690B42}</ProjectGuid>
|
||||
<RootNamespace>tests</RootNamespace>
|
||||
<WindowsTargetPlatformVersion>10.0.16299.0</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v141</PlatformToolset>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v141</PlatformToolset>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v141</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v141</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup />
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)\..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<SubSystem>Console</SubSystem>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>_MBCS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<SubSystem>Console</SubSystem>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)\..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<SubSystem>Console</SubSystem>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>_MBCS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<SubSystem>Console</SubSystem>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="errors.cpp" />
|
||||
<ClCompile Include="file_helper.cpp" />
|
||||
<ClCompile Include="file_log.cpp" />
|
||||
<ClCompile Include="test_async.cpp" />
|
||||
<ClCompile Include="test_misc.cpp" />
|
||||
<ClCompile Include="main.cpp" />
|
||||
<ClCompile Include="registry.cpp" />
|
||||
<ClCompile Include="test_macros.cpp" />
|
||||
<ClCompile Include="test_pattern_formatter.cpp" />
|
||||
<ClCompile Include="utils.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="catch.hpp" />
|
||||
<ClInclude Include="includes.h" />
|
||||
<ClInclude Include="utils.h" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
60
third_party/spdlog/tests/tests.vcxproj.filters
vendored
60
third_party/spdlog/tests/tests.vcxproj.filters
vendored
@ -1,60 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="Source Files">
|
||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Header Files">
|
||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Resource Files">
|
||||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="file_log.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="main.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="registry.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="file_helper.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="utils.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="errors.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="test_macros.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="test_pattern_formatter.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="test_misc.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="test_async.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="includes.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="catch.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="utils.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
4
third_party/spdlog/tests/tests.vcxproj.user
vendored
4
third_party/spdlog/tests/tests.vcxproj.user
vendored
@ -1,4 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup />
|
||||
</Project>
|
52
third_party/spdlog/tests/utils.cpp
vendored
52
third_party/spdlog/tests/utils.cpp
vendored
@ -1,5 +1,10 @@
|
||||
#include "includes.h"
|
||||
|
||||
#ifndef _WIN32
|
||||
#include <sys/types.h>
|
||||
#include <dirent.h>
|
||||
#endif
|
||||
|
||||
void prepare_logdir()
|
||||
{
|
||||
spdlog::drop_all();
|
||||
@ -65,3 +70,50 @@ bool ends_with(std::string const &value, std::string const &ending)
|
||||
}
|
||||
return std::equal(ending.rbegin(), ending.rend(), value.rbegin());
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
// Based on: https://stackoverflow.com/a/37416569/192001
|
||||
std::size_t count_files(const std::string &folder)
|
||||
{
|
||||
size_t counter = 0;
|
||||
WIN32_FIND_DATA ffd;
|
||||
|
||||
// Start iterating over the files in the folder directory.
|
||||
HANDLE hFind = ::FindFirstFileA((folder + "\\*").c_str(), &ffd);
|
||||
if (hFind != INVALID_HANDLE_VALUE)
|
||||
{
|
||||
do // Managed to locate and create an handle to that folder.
|
||||
{
|
||||
if (ffd.cFileName[0] != '.')
|
||||
counter++;
|
||||
} while (::FindNextFile(hFind, &ffd) != 0);
|
||||
::FindClose(hFind);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw std::runtime_error("Failed open folder " + folder);
|
||||
}
|
||||
|
||||
return counter;
|
||||
}
|
||||
#else
|
||||
// Based on: https://stackoverflow.com/a/2802255/192001
|
||||
std::size_t count_files(const std::string &folder)
|
||||
{
|
||||
size_t counter = 0;
|
||||
DIR *dp = opendir(folder.c_str());
|
||||
if (dp == nullptr)
|
||||
{
|
||||
throw std::runtime_error("Failed open folder " + folder);
|
||||
}
|
||||
|
||||
struct dirent *ep;
|
||||
while ((ep = readdir(dp)) != nullptr)
|
||||
{
|
||||
if (ep->d_name[0] != '.')
|
||||
counter++;
|
||||
}
|
||||
(void)closedir(dp);
|
||||
return counter;
|
||||
}
|
||||
#endif
|
||||
|
4
third_party/spdlog/tests/utils.h
vendored
4
third_party/spdlog/tests/utils.h
vendored
@ -5,6 +5,8 @@
|
||||
|
||||
std::size_t count_lines(const std::string &filename);
|
||||
|
||||
std::size_t count_files(const std::string &folder);
|
||||
|
||||
void prepare_logdir();
|
||||
|
||||
std::string file_contents(const std::string &filename);
|
||||
@ -13,4 +15,4 @@ std::size_t count_lines(const std::string &filename);
|
||||
|
||||
std::size_t get_filesize(const std::string &filename);
|
||||
|
||||
bool ends_with(std::string const &value, std::string const &ending);
|
||||
bool ends_with(std::string const &value, std::string const &ending);
|
Reference in New Issue
Block a user