mirror of
https://github.com/gabime/spdlog.git
synced 2025-10-02 03:19:02 +08:00
Address code review comments: revert perfect forwarding on places that didn't need it, remove negative compilation unit test.
This commit is contained in:
@@ -68,29 +68,3 @@ endif()
|
||||
if(SPDLOG_BUILD_TESTS_HO OR SPDLOG_BUILD_ALL)
|
||||
spdlog_prepare_test(spdlog-utests-ho spdlog::spdlog_header_only)
|
||||
endif()
|
||||
|
||||
# Set up compilation failure test case (only available if compiler supports relaxed constexpr and c++ standard is > 11)
|
||||
set(HAVE_CXX_RELAXED_CONSTEXPR)
|
||||
if(CMAKE_CXX_STANDARD GREATER 11) # If we're in c++11 mode we don't have relaxed constexpr, even if our compiler is new enough.
|
||||
list(FIND CMAKE_CXX_COMPILE_FEATURES "cxx_relaxed_constexpr" HAVE_CXX_RELAXED_CONSTEXPR)
|
||||
endif()
|
||||
if(HAVE_CXX_RELAXED_CONSTEXPR AND (SPDLOG_BUILD_FAILING_TESTS OR SPDLOG_BUILD_ALL))
|
||||
message(STATUS "Enabling negative compilation unit test target")
|
||||
set(SPDLOG_FAIL_COMPILATION_TARGET spdlog_fail_compilation_utests)
|
||||
add_executable(${SPDLOG_FAIL_COMPILATION_TARGET}
|
||||
test_compilation_failures.cpp
|
||||
main.cpp)
|
||||
spdlog_enable_warnings(${SPDLOG_FAIL_COMPILATION_TARGET})
|
||||
target_link_libraries(${SPDLOG_FAIL_COMPILATION_TARGET} PRIVATE spdlog::spdlog)
|
||||
set_target_properties(${SPDLOG_FAIL_COMPILATION_TARGET} PROPERTIES
|
||||
EXCLUDE_FROM_ALL TRUE
|
||||
EXCLUDE_FROM_DEFAULT_BUILD TRUE)
|
||||
add_test(NAME ${SPDLOG_FAIL_COMPILATION_TARGET}
|
||||
COMMAND ${CMAKE_COMMAND} --build . --target ${SPDLOG_FAIL_COMPILATION_TARGET} --config $<CONFIG>
|
||||
WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
|
||||
set_tests_properties(${SPDLOG_FAIL_COMPILATION_TARGET} PROPERTIES PASS_REGULAR_EXPRESSION "invalid type specifier")
|
||||
|
||||
add_custom_target(${SPDLOG_FAIL_COMPILATION_TARGET}_run_target
|
||||
COMMAND ${CMAKE_CTEST_COMMAND} -R ${SPDLOG_FAIL_COMPILATION_TARGET} --output-on-failure
|
||||
COMMENT "Running tests that fail to compile.")
|
||||
endif()
|
||||
|
@@ -1,14 +0,0 @@
|
||||
#include "includes.h"
|
||||
|
||||
TEST_CASE("{fmt} FMT_STRING functionality preserved (negative test)", "[fmt][fail][fail compilation]")
|
||||
{
|
||||
std::ostringstream oss;
|
||||
auto oss_sink = std::make_shared<spdlog::sinks::ostream_sink_mt>(oss);
|
||||
|
||||
spdlog::set_default_logger(std::make_shared<spdlog::logger>("oss", oss_sink));
|
||||
spdlog::default_logger()->set_level(spdlog::level::trace);
|
||||
|
||||
spdlog::info(FMT_STRING("The best part of {{fmt}} is the compile time checking: {:d}"), "I shouldn't compile");
|
||||
// This should never be able to compile, so running is a failure.
|
||||
FAIL("This test case isn't meant to compile, let alone run.");
|
||||
}
|
@@ -3,7 +3,7 @@
|
||||
#include "spdlog/fmt/bin_to_hex.h"
|
||||
|
||||
template<class T>
|
||||
std::string log_info(T &&what, spdlog::level::level_enum logger_level = spdlog::level::info)
|
||||
std::string log_info(const T &what, spdlog::level::level_enum logger_level = spdlog::level::info)
|
||||
{
|
||||
|
||||
std::ostringstream oss;
|
||||
@@ -12,7 +12,7 @@ std::string log_info(T &&what, spdlog::level::level_enum logger_level = spdlog::
|
||||
spdlog::logger oss_logger("oss", oss_sink);
|
||||
oss_logger.set_level(logger_level);
|
||||
oss_logger.set_pattern("%v");
|
||||
oss_logger.info(std::forward<T>(what));
|
||||
oss_logger.info(what);
|
||||
|
||||
return oss.str().substr(0, oss.str().length() - strlen(spdlog::details::os::default_eol));
|
||||
}
|
||||
@@ -269,34 +269,3 @@ TEST_CASE("default logger API", "[default logger]")
|
||||
spdlog::drop_all();
|
||||
spdlog::set_pattern("%v");
|
||||
}
|
||||
|
||||
TEST_CASE("{fmt} FMT_STRING functionality preserved (positive test)", "[fmt]")
|
||||
{
|
||||
std::ostringstream oss;
|
||||
auto oss_sink = std::make_shared<spdlog::sinks::ostream_sink_mt>(oss);
|
||||
|
||||
spdlog::set_default_logger(std::make_shared<spdlog::logger>("oss", oss_sink));
|
||||
spdlog::default_logger()->set_level(spdlog::level::trace);
|
||||
spdlog::set_pattern("%v");
|
||||
|
||||
const std::string expected_output_all(
|
||||
std::string("The best part of {fmt} is the compile time checking: 42") + std::string(spdlog::details::os::default_eol));
|
||||
spdlog::trace(FMT_STRING("The best part of {{fmt}} is the compile time checking: {:d}"), 42);
|
||||
REQUIRE(oss.str() == expected_output_all);
|
||||
oss.str("");
|
||||
spdlog::debug(FMT_STRING("The best part of {{fmt}} is the compile time checking: {:d}"), 42);
|
||||
REQUIRE(oss.str() == expected_output_all);
|
||||
oss.str("");
|
||||
spdlog::info(FMT_STRING("The best part of {{fmt}} is the compile time checking: {:d}"), 42);
|
||||
REQUIRE(oss.str() == expected_output_all);
|
||||
oss.str("");
|
||||
spdlog::warn(FMT_STRING("The best part of {{fmt}} is the compile time checking: {:d}"), 42);
|
||||
REQUIRE(oss.str() == expected_output_all);
|
||||
oss.str("");
|
||||
spdlog::error(FMT_STRING("The best part of {{fmt}} is the compile time checking: {:d}"), 42);
|
||||
REQUIRE(oss.str() == expected_output_all);
|
||||
oss.str("");
|
||||
spdlog::critical(FMT_STRING("The best part of {{fmt}} is the compile time checking: {:d}"), 42);
|
||||
REQUIRE(oss.str() == expected_output_all);
|
||||
oss.str("");
|
||||
}
|
||||
|
Reference in New Issue
Block a user