From 39e27684ea5481d3599a87b1749cbf3db6c25d86 Mon Sep 17 00:00:00 2001 From: Florian Albrechtskirchinger Date: Tue, 21 Jun 2022 16:57:47 +0200 Subject: [PATCH] Use DOCTEST_* compiler macros and suppress pragmas warning (#3550) Use DOCTEST_* macros in place of predefined compiler macros for compiler detection and version checks. The suppression of warning -Wrange-loop-construct in unit-items.cpp causes GCC<11 to warn about pragmas. Suppressed by adding a version check. --- tests/src/unit-items.cpp | 4 +++- tests/src/unit-iterators2.cpp | 4 ++-- tests/src/unit-regression1.cpp | 2 +- tests/src/unit-regression2.cpp | 2 +- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/tests/src/unit-items.cpp b/tests/src/unit-items.cpp index 64d92b59e..36c93e0d4 100644 --- a/tests/src/unit-items.cpp +++ b/tests/src/unit-items.cpp @@ -34,7 +34,9 @@ using nlohmann::json; // This test suite uses range for loops where values are copied. This is inefficient in usual code, but required to achieve 100% coverage. DOCTEST_GCC_SUPPRESS_WARNING_PUSH -DOCTEST_GCC_SUPPRESS_WARNING("-Wrange-loop-construct") +#if DOCTEST_GCC >= DOCTEST_COMPILER(11, 0, 0) + DOCTEST_GCC_SUPPRESS_WARNING("-Wrange-loop-construct") +#endif DOCTEST_CLANG_SUPPRESS_WARNING_PUSH DOCTEST_CLANG_SUPPRESS_WARNING("-Wrange-loop-construct") diff --git a/tests/src/unit-iterators2.cpp b/tests/src/unit-iterators2.cpp index b9c418c16..6b1d17ea8 100644 --- a/tests/src/unit-iterators2.cpp +++ b/tests/src/unit-iterators2.cpp @@ -916,7 +916,7 @@ TEST_CASE("iterators 2") } // libstdc++ algorithms don't work with Clang 15 (04/2022) -#if !defined(__clang__) || (defined(__clang__) && defined(__GLIBCXX__)) +#if !DOCTEST_CLANG || (DOCTEST_CLANG && defined(__GLIBCXX__)) SECTION("algorithms") { SECTION("copy") @@ -955,7 +955,7 @@ TEST_CASE("iterators 2") // libstdc++ views don't work with Clang 15 (04/2022) // libc++ hides limited ranges implementation behind guard macro -#if !(defined(__clang__) && (defined(__GLIBCXX__) || defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES))) +#if !(DOCTEST_CLANG && (defined(__GLIBCXX__) || defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES))) SECTION("views") { SECTION("reverse") diff --git a/tests/src/unit-regression1.cpp b/tests/src/unit-regression1.cpp index e6dfaa1c5..5a6e31e73 100644 --- a/tests/src/unit-regression1.cpp +++ b/tests/src/unit-regression1.cpp @@ -1520,7 +1520,7 @@ TEST_CASE("regression tests, exceptions dependent") ///////////////////////////////////////////////////////////////////// // the code below fails with Clang on Windows, so we need to exclude it there -#if defined(__clang__) && (defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__)) +#if DOCTEST_CLANG && (defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__)) #else template class array {}; template class object {}; diff --git a/tests/src/unit-regression2.cpp b/tests/src/unit-regression2.cpp index 3ee234eee..a41177174 100644 --- a/tests/src/unit-regression2.cpp +++ b/tests/src/unit-regression2.cpp @@ -803,7 +803,7 @@ TEST_CASE("regression tests 2") const auto j_path = j.get(); CHECK(j_path == text_path); -#if defined(__clang__) || ((defined(__GNUC__) && !defined(__INTEL_COMPILER)) && (__GNUC__ > 8 || (__GNUC__ == 8 && __GNUC_MINOR__ >= 4))) +#if DOCTEST_CLANG || DOCTEST_GCC >= DOCTEST_COMPILER(8, 4, 0) // only known to work on Clang and GCC >=8.4 CHECK_THROWS_WITH_AS(nlohmann::detail::std_fs::path(json(1)), "[json.exception.type_error.302] type must be string, but is number", json::type_error); #endif