diff --git a/test/src/unit-cbor.cpp b/test/src/unit-cbor.cpp index 3d7be8c1..43073bd0 100644 --- a/test/src/unit-cbor.cpp +++ b/test/src/unit-cbor.cpp @@ -28,6 +28,7 @@ SOFTWARE. */ #include "doctest_compatibility.h" +DOCTEST_GCC_SUPPRESS_WARNING("-Wfloat-equal") #include using nlohmann::json; @@ -876,9 +877,7 @@ TEST_CASE("CBOR") { json j = json::from_cbor(std::vector({0xf9, 0x7c, 0x00})); json::number_float_t d = j; - DOCTEST_GCC_SUPPRESS_WARNING_WITH_PUSH("-Wfloat-equal") CHECK(d == std::numeric_limits::infinity()); - DOCTEST_GCC_SUPPRESS_WARNING_POP CHECK(j.dump() == "null"); } @@ -897,9 +896,7 @@ TEST_CASE("CBOR") { json j = json::from_cbor(std::vector({0xf9, 0x3c, 0x00})); json::number_float_t d = j; - DOCTEST_GCC_SUPPRESS_WARNING_WITH_PUSH("-Wfloat-equal") CHECK(d == 1); - DOCTEST_GCC_SUPPRESS_WARNING_POP } SECTION("-2 (1 10000 0000000000)") diff --git a/test/src/unit-constructor1.cpp b/test/src/unit-constructor1.cpp index 115df7b7..f7b6c775 100644 --- a/test/src/unit-constructor1.cpp +++ b/test/src/unit-constructor1.cpp @@ -28,6 +28,7 @@ SOFTWARE. */ #include "doctest_compatibility.h" +DOCTEST_GCC_SUPPRESS_WARNING("-Wfloat-equal") #define private public #include @@ -351,9 +352,7 @@ TEST_CASE("constructors") CHECK(jva.size() == va.size()); for (size_t i = 0; i < jva.size(); ++i) { - DOCTEST_GCC_SUPPRESS_WARNING_WITH_PUSH("-Wfloat-equal") CHECK(va[i] == jva[i]); - DOCTEST_GCC_SUPPRESS_WARNING_POP } } diff --git a/test/src/unit-conversions.cpp b/test/src/unit-conversions.cpp index 53ac1200..1476b6e6 100644 --- a/test/src/unit-conversions.cpp +++ b/test/src/unit-conversions.cpp @@ -28,7 +28,6 @@ SOFTWARE. */ #include "doctest_compatibility.h" -DOCTEST_GCC_SUPPRESS_WARNING_WITH_PUSH("-Wsign-promo") #define private public #include diff --git a/test/src/unit-readme.cpp b/test/src/unit-readme.cpp index 8a64d680..4af68449 100644 --- a/test/src/unit-readme.cpp +++ b/test/src/unit-readme.cpp @@ -28,6 +28,7 @@ SOFTWARE. */ #include "doctest_compatibility.h" +DOCTEST_GCC_SUPPRESS_WARNING("-Wfloat-equal") #include using nlohmann::json; @@ -269,9 +270,7 @@ TEST_CASE("README" * doctest::skip()) int i = 42; json jn = i; double f = jn; - DOCTEST_GCC_SUPPRESS_WARNING_WITH_PUSH("-Wfloat-equal") CHECK(f == 42); - DOCTEST_GCC_SUPPRESS_WARNING_POP // etc. diff --git a/test/src/unit-reference_access.cpp b/test/src/unit-reference_access.cpp index f0c64422..a9a0f6e5 100644 --- a/test/src/unit-reference_access.cpp +++ b/test/src/unit-reference_access.cpp @@ -28,6 +28,7 @@ SOFTWARE. */ #include "doctest_compatibility.h" +DOCTEST_GCC_SUPPRESS_WARNING("-Wfloat-equal") #include using nlohmann::json; @@ -287,9 +288,7 @@ TEST_CASE("reference access") // check if references are returned correctly test_type& p1 = value.get_ref(); CHECK(&p1 == value.get_ptr()); - DOCTEST_GCC_SUPPRESS_WARNING_WITH_PUSH("-Wfloat-equal") CHECK(p1 == value.get()); - DOCTEST_GCC_SUPPRESS_WARNING_POP const test_type& p2 = value.get_ref(); CHECK(&p2 == value.get_ptr()); diff --git a/test/src/unit-regression.cpp b/test/src/unit-regression.cpp index bb3cc756..6b7d90aa 100644 --- a/test/src/unit-regression.cpp +++ b/test/src/unit-regression.cpp @@ -28,7 +28,7 @@ SOFTWARE. */ #include "doctest_compatibility.h" -DOCTEST_GCC_SUPPRESS_WARNING_WITH_PUSH("-Wsign-promo") +DOCTEST_GCC_SUPPRESS_WARNING("-Wfloat-equal") // for some reason including this after the json header leads to linker errors with VS 2017... #include @@ -315,9 +315,7 @@ TEST_CASE("regression tests") // unsigned integer parsing - expected to overflow and be stored as a float j = custom_json::parse("4294967296"); // 2^32 CHECK(static_cast(j.type()) == static_cast(custom_json::value_t::number_float)); - DOCTEST_GCC_SUPPRESS_WARNING_WITH_PUSH("-Wfloat-equal") CHECK(j.get() == 4294967296.0f); - DOCTEST_GCC_SUPPRESS_WARNING_POP // integer object creation - expected to wrap and still be stored as an integer j = -2147483649LL; // -2^31-1 @@ -482,9 +480,7 @@ TEST_CASE("regression tests") json j; j = json::parse("-0.0"); - DOCTEST_GCC_SUPPRESS_WARNING_WITH_PUSH("-Wfloat-equal") CHECK(j.get() == -0.0); - DOCTEST_GCC_SUPPRESS_WARNING_POP j = json::parse("2.22507385850720113605740979670913197593481954635164564e-308"); CHECK(j.get() == 2.2250738585072009e-308); @@ -522,9 +518,7 @@ TEST_CASE("regression tests") // long double nlohmann::basic_json j_long_double = 1.23e45L; - DOCTEST_GCC_SUPPRESS_WARNING_WITH_PUSH("-Wfloat-equal") CHECK(j_long_double.get() == 1.23e45L); - DOCTEST_GCC_SUPPRESS_WARNING_POP } SECTION("issue #228 - double values are serialized with commas as decimal points") diff --git a/test/thirdparty/doctest/doctest.h b/test/thirdparty/doctest/doctest.h index 4a2c90fa..dbbcd3f5 100644 --- a/test/thirdparty/doctest/doctest.h +++ b/test/thirdparty/doctest/doctest.h @@ -161,6 +161,7 @@ DOCTEST_GCC_SUPPRESS_WARNING("-Winline") DOCTEST_GCC_SUPPRESS_WARNING("-Wunused-local-typedefs") DOCTEST_GCC_SUPPRESS_WARNING("-Wuseless-cast") DOCTEST_GCC_SUPPRESS_WARNING("-Wnoexcept") +DOCTEST_GCC_SUPPRESS_WARNING("-Wsign-promo") DOCTEST_MSVC_SUPPRESS_WARNING_PUSH DOCTEST_MSVC_SUPPRESS_WARNING(4616) // invalid compiler warning @@ -994,6 +995,10 @@ namespace detail { }; DOCTEST_INTERFACE bool checkIfShouldThrow(assertType::Enum at); + +#ifndef DOCTEST_CONFIG_NO_EXCEPTIONS + [[noreturn]] +#endif // DOCTEST_CONFIG_NO_EXCEPTIONS DOCTEST_INTERFACE void throwException(); struct DOCTEST_INTERFACE Subcase @@ -1598,7 +1603,7 @@ namespace detail { DOCTEST_DELETE_COPIES(ContextScope); - ~ContextScope(); + ~ContextScope() override; void stringify(std::ostream* s) const override; }; @@ -1839,6 +1844,15 @@ int registerReporter(const char* name, int priority) { } catch(...) { _DOCTEST_RB.translateException(); } #endif // DOCTEST_CONFIG_NO_TRY_CATCH_IN_ASSERTS +#ifdef DOCTEST_CONFIG_VOID_CAST_EXPRESSIONS +#define DOCTEST_CAST_TO_VOID(x) \ + DOCTEST_GCC_SUPPRESS_WARNING_WITH_PUSH("-Wuseless-cast") \ + static_cast(x); \ + DOCTEST_GCC_SUPPRESS_WARNING_POP +#else // DOCTEST_CONFIG_VOID_CAST_EXPRESSIONS +#define DOCTEST_CAST_TO_VOID(x) x; +#endif // DOCTEST_CONFIG_VOID_CAST_EXPRESSIONS + // registers the test by initializing a dummy var with a function #define DOCTEST_REGISTER_FUNCTION(global_prefix, f, decorators) \ global_prefix DOCTEST_GLOBAL_NO_WARNINGS(DOCTEST_ANONYMOUS(_DOCTEST_ANON_VAR_)) = \ @@ -2108,15 +2122,13 @@ constexpr T to_lvalue = x; #define DOCTEST_REQUIRE_FALSE_MESSAGE(cond, msg) do { DOCTEST_INFO(msg); DOCTEST_ASSERT_IMPLEMENT_2(DT_REQUIRE_FALSE, cond); } while((void)0, 0) // clang-format on -#define DOCTEST_ASSERT_THROWS(expr, assert_type) DOCTEST_ASSERT_THROWS_WITH(expr, assert_type, "") - #define DOCTEST_ASSERT_THROWS_AS(expr, assert_type, ...) \ do { \ if(!doctest::getContextOptions()->no_throw) { \ doctest::detail::ResultBuilder _DOCTEST_RB(doctest::assertType::assert_type, __FILE__, \ __LINE__, #expr, #__VA_ARGS__); \ try { \ - expr; \ + DOCTEST_CAST_TO_VOID(expr) \ } catch(const doctest::detail::remove_const< \ doctest::detail::remove_reference<__VA_ARGS__>::type>::type&) { \ _DOCTEST_RB.translateException(); \ @@ -2132,7 +2144,7 @@ constexpr T to_lvalue = x; doctest::detail::ResultBuilder _DOCTEST_RB(doctest::assertType::assert_type, __FILE__, \ __LINE__, #expr, __VA_ARGS__); \ try { \ - expr; \ + DOCTEST_CAST_TO_VOID(expr) \ } catch(...) { _DOCTEST_RB.translateException(); } \ DOCTEST_ASSERT_LOG_AND_REACT(_DOCTEST_RB); \ } \ @@ -2143,15 +2155,15 @@ constexpr T to_lvalue = x; doctest::detail::ResultBuilder _DOCTEST_RB(doctest::assertType::assert_type, __FILE__, \ __LINE__, #expr); \ try { \ - expr; \ + DOCTEST_CAST_TO_VOID(expr) \ } catch(...) { _DOCTEST_RB.translateException(); } \ DOCTEST_ASSERT_LOG_AND_REACT(_DOCTEST_RB); \ } while((void)0, 0) // clang-format off -#define DOCTEST_WARN_THROWS(expr) DOCTEST_ASSERT_THROWS(expr, DT_WARN_THROWS) -#define DOCTEST_CHECK_THROWS(expr) DOCTEST_ASSERT_THROWS(expr, DT_CHECK_THROWS) -#define DOCTEST_REQUIRE_THROWS(expr) DOCTEST_ASSERT_THROWS(expr, DT_REQUIRE_THROWS) +#define DOCTEST_WARN_THROWS(expr) DOCTEST_ASSERT_THROWS_WITH(expr, DT_WARN_THROWS, "") +#define DOCTEST_CHECK_THROWS(expr) DOCTEST_ASSERT_THROWS_WITH(expr, DT_CHECK_THROWS, "") +#define DOCTEST_REQUIRE_THROWS(expr) DOCTEST_ASSERT_THROWS_WITH(expr, DT_REQUIRE_THROWS, "") #define DOCTEST_WARN_THROWS_AS(expr, ...) DOCTEST_ASSERT_THROWS_AS(expr, DT_WARN_THROWS_AS, __VA_ARGS__) #define DOCTEST_CHECK_THROWS_AS(expr, ...) DOCTEST_ASSERT_THROWS_AS(expr, DT_CHECK_THROWS_AS, __VA_ARGS__) @@ -3504,11 +3516,11 @@ namespace detail { return false; } - void throwException() { #ifndef DOCTEST_CONFIG_NO_EXCEPTIONS - throw TestFailureException(); + [[noreturn]] void throwException() { throw TestFailureException(); } +#else // DOCTEST_CONFIG_NO_EXCEPTIONS + void throwException() {} #endif // DOCTEST_CONFIG_NO_EXCEPTIONS - } } // namespace detail namespace { @@ -4868,12 +4880,16 @@ namespace { } void test_case_exception(const TestCaseException& e) override { + std::lock_guard lock(mutex); + xml.scopedElement("Exception") .writeAttribute("crash", e.is_crash) .writeText(e.error_string.c_str()); } void subcase_start(const SubcaseSignature& in) override { + std::lock_guard lock(mutex); + xml.startElement("SubCase") .writeAttribute("name", in.m_name) .writeAttribute("filename", skipPathFromFilename(in.m_file)) @@ -5319,11 +5335,13 @@ namespace { } void subcase_start(const SubcaseSignature& subc) override { + std::lock_guard lock(mutex); subcasesStack.push_back(subc); hasLoggedCurrentTestStart = false; } void subcase_end() override { + std::lock_guard lock(mutex); subcasesStack.pop_back(); hasLoggedCurrentTestStart = false; } diff --git a/test/thirdparty/doctest/doctest_compatibility.h b/test/thirdparty/doctest/doctest_compatibility.h index b63b0b0a..6194e26b 100644 --- a/test/thirdparty/doctest/doctest_compatibility.h +++ b/test/thirdparty/doctest/doctest_compatibility.h @@ -1,6 +1,7 @@ #ifndef DOCTEST_COMPATIBILITY #define DOCTEST_COMPATIBILITY +#define DOCTEST_CONFIG_VOID_CAST_EXPRESSIONS #define DOCTEST_THREAD_LOCAL // enable single-threaded builds on XCode 6/7 - https://github.com/onqtam/doctest/issues/172 #include "doctest.h" @@ -25,29 +26,6 @@ #define CHECK_THROWS_WITH_STD_STR(expr, str) \ CHECK_THROWS_WITH_STD_STR_IMPL(expr, str, DOCTEST_ANONYMOUS(DOCTEST_STD_STRING_)) -#undef CHECK_THROWS -#undef CHECK_THROWS_AS -#undef CHECK_THROWS_WITH -#undef CHECK_NOTHROW - -#undef REQUIRE_THROWS -#undef REQUIRE_THROWS_AS -#undef REQUIRE_THROWS_WITH -#undef REQUIRE_NOTHROW - -// doctest allows multiple statements in these macros (even blocks of code) but json -// tests rely on passing single function/constructor calls which have a [[nodiscard]] -// attribute so here we static_cast to void - just like Catch does -#define CHECK_THROWS(expr) DOCTEST_CHECK_THROWS(static_cast(expr)) -#define CHECK_THROWS_AS(expr, e) DOCTEST_CHECK_THROWS_AS(static_cast(expr), e) -#define CHECK_THROWS_WITH(expr, e) DOCTEST_CHECK_THROWS_WITH(static_cast(expr), e) -#define CHECK_NOTHROW(expr) DOCTEST_CHECK_NOTHROW(static_cast(expr)) - -#define REQUIRE_THROWS(expr) DOCTEST_REQUIRE_THROWS(static_cast(expr)) -#define REQUIRE_THROWS_AS(expr, e) DOCTEST_REQUIRE_THROWS_AS(static_cast(expr), e) -#define REQUIRE_THROWS_WITH(expr, e) DOCTEST_REQUIRE_THROWS_WITH(static_cast(expr), e) -#define REQUIRE_NOTHROW(expr) DOCTEST_REQUIRE_NOTHROW(static_cast(expr)) - // included here because for some tests in the json repository private is defined as // public and if no STL header is included before that then in the json include when STL // stuff is included the MSVC STL complains (errors) that C++ keywords are being redefined