From 85b4d7c8d6e45ba32c65b1b75c6e48377c50506c Mon Sep 17 00:00:00 2001 From: "David P. Sicilia" Date: Sat, 1 Dec 2018 20:37:06 -0500 Subject: [PATCH 1/8] CMake: include(CTest) only when building tests. This is needed in order to support usage of this library as a subdirectory in a parent project. In that situation, prior to this change, the inclusion of CTest would unconditionally enable BUILD_TESTING which would then bleed into other parts of the project. Also added some comments explaining how this logic works. --- CMakeLists.txt | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1dc01f87..7fda48a8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,7 +5,6 @@ cmake_minimum_required(VERSION 3.1) project(spdlog VERSION 1.3.0 LANGUAGES CXX) -include(CTest) include(CMakeDependentOption) include(GNUInstallDirs) @@ -54,10 +53,22 @@ endif() option(SPDLOG_BUILD_EXAMPLES "Build examples" ${SPDLOG_MASTER_PROJECT}) option(SPDLOG_BUILD_BENCH "Build benchmarks" ${SPDLOG_MASTER_PROJECT}) +# Logic for enabling tests: If the user does not explicitly +# specify the value of the SPDLOG_BUILD_TESTING variable then the +# logic is simpler to reason about: that is, testing will be +# built if and only if BUILD_TESTING is ON and we are a Master +# Project. On the other hand, if the user overrides the value of +# SPDLOG_BUILD_TESTING then it can get a bit more tricky due to +# caching. + cmake_dependent_option(SPDLOG_BUILD_TESTING "Build spdlog tests" ${SPDLOG_MASTER_PROJECT} "BUILD_TESTING" OFF ) +if(SPDLOG_BUILD_TESTING) + # Include CTest conditionally since it will enable BUILD_TESTING. + include(CTest) +endif() target_include_directories( spdlog From f5dc16603ee97b77f9945e29b4f4864afdde2652 Mon Sep 17 00:00:00 2001 From: "David P. Sicilia" Date: Sat, 1 Dec 2018 20:57:45 -0500 Subject: [PATCH 2/8] Enable testing in the Travis config file. This is needed because ENABLE_TESTING is no longer enabled by default. --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 49ea5476..c578ce26 100644 --- a/.travis.yml +++ b/.travis.yml @@ -104,6 +104,7 @@ script: -DCMAKE_CXX_STANDARD=$CPP \ -DSPDLOG_BUILD_EXAMPLES=ON \ -DSPDLOG_BUILD_BENCH=OFF \ + -DBUILD_TESTING=ON \ -DSPDLOG_SANITIZE_ADDRESS=$ASAN \ -DSPDLOG_SANITIZE_THREAD=$TSAN - make VERBOSE=1 -j2 From 7275fb6f52e026b957c0dd09a7ab2c2d2fc34d12 Mon Sep 17 00:00:00 2001 From: gabime Date: Sun, 2 Dec 2018 12:25:46 +0200 Subject: [PATCH 3/8] simplify SPDLOG_BUILD_TESTS Cmake option --- .travis.yml | 2 +- CMakeLists.txt | 20 +++----------------- 2 files changed, 4 insertions(+), 18 deletions(-) diff --git a/.travis.yml b/.travis.yml index c578ce26..68d5b3c4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -104,7 +104,7 @@ script: -DCMAKE_CXX_STANDARD=$CPP \ -DSPDLOG_BUILD_EXAMPLES=ON \ -DSPDLOG_BUILD_BENCH=OFF \ - -DBUILD_TESTING=ON \ + -DBUILD_BUILD_TESTS=ON \ -DSPDLOG_SANITIZE_ADDRESS=$ASAN \ -DSPDLOG_SANITIZE_THREAD=$TSAN - make VERBOSE=1 -j2 diff --git a/CMakeLists.txt b/CMakeLists.txt index 7fda48a8..3a0531dd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -52,23 +52,8 @@ endif() option(SPDLOG_BUILD_EXAMPLES "Build examples" ${SPDLOG_MASTER_PROJECT}) option(SPDLOG_BUILD_BENCH "Build benchmarks" ${SPDLOG_MASTER_PROJECT}) +option(SPDLOG_BUILD_TESTS "Build tests" ${SPDLOG_MASTER_PROJECT}) -# Logic for enabling tests: If the user does not explicitly -# specify the value of the SPDLOG_BUILD_TESTING variable then the -# logic is simpler to reason about: that is, testing will be -# built if and only if BUILD_TESTING is ON and we are a Master -# Project. On the other hand, if the user overrides the value of -# SPDLOG_BUILD_TESTING then it can get a bit more tricky due to -# caching. - -cmake_dependent_option(SPDLOG_BUILD_TESTING - "Build spdlog tests" ${SPDLOG_MASTER_PROJECT} - "BUILD_TESTING" OFF -) -if(SPDLOG_BUILD_TESTING) - # Include CTest conditionally since it will enable BUILD_TESTING. - include(CTest) -endif() target_include_directories( spdlog @@ -83,7 +68,8 @@ if(SPDLOG_BUILD_EXAMPLES) add_subdirectory(example) endif() -if(SPDLOG_BUILD_TESTING) +if(SPDLOG_BUILD_TESTS) + include(CTest) add_subdirectory(tests) endif() From bbc859ca19eafa7bfca8372740bf368079b02082 Mon Sep 17 00:00:00 2001 From: Gabi Melman Date: Sun, 2 Dec 2018 15:25:03 +0200 Subject: [PATCH 4/8] Update .travis.yml --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 68d5b3c4..2a0a35b7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -104,7 +104,7 @@ script: -DCMAKE_CXX_STANDARD=$CPP \ -DSPDLOG_BUILD_EXAMPLES=ON \ -DSPDLOG_BUILD_BENCH=OFF \ - -DBUILD_BUILD_TESTS=ON \ + -DSPDLOG_BUILD_TESTS=ON \ -DSPDLOG_SANITIZE_ADDRESS=$ASAN \ -DSPDLOG_SANITIZE_THREAD=$TSAN - make VERBOSE=1 -j2 From 7442d720f451751074eb3df695df7f794ff21045 Mon Sep 17 00:00:00 2001 From: Gabi Melman Date: Sun, 2 Dec 2018 16:30:07 +0200 Subject: [PATCH 5/8] Update appveyor.yml --- appveyor.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index d7843cde..d7ce7a31 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -29,4 +29,7 @@ build_script: cmake .. -G %GENERATOR% -DCMAKE_BUILD_TYPE=%BUILD_TYPE% -DSPDLOG_BUILD_BENCH=OFF cmake --build . --config %BUILD_TYPE% -test: off + +test_script: +- cmd: cd build +- ctest -VV -C "%BUILD_TYPE%" From 5191948b64fd098a5bd31c9c2b680475a6b3e599 Mon Sep 17 00:00:00 2001 From: Gabi Melman Date: Sun, 2 Dec 2018 16:40:02 +0200 Subject: [PATCH 6/8] Update appveyor.yml --- appveyor.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index d7ce7a31..98ce69ba 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -31,5 +31,4 @@ build_script: cmake --build . --config %BUILD_TYPE% test_script: -- cmd: cd build - ctest -VV -C "%BUILD_TYPE%" From d8eb0558e918a01aa1ae1d96cdc7c5ec2b24c03c Mon Sep 17 00:00:00 2001 From: gabime Date: Sun, 2 Dec 2018 17:13:50 +0200 Subject: [PATCH 7/8] Fix test for mingw --- tests/test_misc.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_misc.cpp b/tests/test_misc.cpp index 9e097a45..342b3dac 100644 --- a/tests/test_misc.cpp +++ b/tests/test_misc.cpp @@ -86,7 +86,7 @@ TEST_CASE("periodic flush", "[periodic_flush]") auto test_sink = std::static_pointer_cast(logger->sinks()[0]); spdlog::flush_every(std::chrono::seconds(1)); - std::this_thread::sleep_for(std::chrono::milliseconds(1100)); + std::this_thread::sleep_for(std::chrono::milliseconds(1500)); REQUIRE(test_sink->flush_counter() == 1); spdlog::flush_every(std::chrono::seconds(0)); spdlog::drop_all(); From fcb661d0e9e38498ec50138f9eb2c27850a300c2 Mon Sep 17 00:00:00 2001 From: gabime Date: Sun, 2 Dec 2018 19:04:44 +0200 Subject: [PATCH 8/8] Fixed tests --- tests/test_misc.cpp | 2 +- tests/test_registry.cpp | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/test_misc.cpp b/tests/test_misc.cpp index 342b3dac..1b880835 100644 --- a/tests/test_misc.cpp +++ b/tests/test_misc.cpp @@ -86,7 +86,7 @@ TEST_CASE("periodic flush", "[periodic_flush]") auto test_sink = std::static_pointer_cast(logger->sinks()[0]); spdlog::flush_every(std::chrono::seconds(1)); - std::this_thread::sleep_for(std::chrono::milliseconds(1500)); + std::this_thread::sleep_for(std::chrono::milliseconds(1250)); REQUIRE(test_sink->flush_counter() == 1); spdlog::flush_every(std::chrono::seconds(0)); spdlog::drop_all(); diff --git a/tests/test_registry.cpp b/tests/test_registry.cpp index d306dba2..bd326ef0 100644 --- a/tests/test_registry.cpp +++ b/tests/test_registry.cpp @@ -110,4 +110,5 @@ TEST_CASE("disable automatic registration", "[registry]") REQUIRE(logger1->level() == log_level); REQUIRE(logger2->level() == log_level); spdlog::set_level(spdlog::level::info); + spdlog::set_automatic_registration(true); }