From 4e1110012fe6031012f6e9a7f36cb33557c68dd7 Mon Sep 17 00:00:00 2001 From: Stefan <29021710+Saalvage@users.noreply.github.com> Date: Sat, 30 Apr 2022 18:22:49 +0200 Subject: Fix #508 (#640) * Fix #508 * Missed warning suppression --- doctest/doctest.h | 26 ++++++++++++++-------- doctest/parts/doctest.cpp | 2 +- doctest/parts/doctest_fwd.h | 24 +++++++++++++------- examples/all_features/CMakeLists.txt | 1 + examples/all_features/double_stringification.cpp | 18 +++++++++++++++ .../test_output/double_stringification.cpp.txt | 6 +++++ .../double_stringification.cpp_junit.txt | 7 ++++++ .../test_output/double_stringification.cpp_xml.txt | 12 ++++++++++ examples/all_features/test_output/filter_2.txt | 2 +- examples/all_features/test_output/filter_2_xml.txt | 3 ++- .../test_output/no_multi_lane_atomics.txt | 4 ++-- .../all_features/test_output/no_multithreading.txt | 4 ++-- .../test_output/stringification.cpp.txt | 4 ++-- .../test_output/stringification.cpp_junit.txt | 3 ++- .../test_output/stringification.cpp_xml.txt | 7 ++++-- 15 files changed, 94 insertions(+), 29 deletions(-) create mode 100644 examples/all_features/double_stringification.cpp create mode 100644 examples/all_features/test_output/double_stringification.cpp.txt create mode 100644 examples/all_features/test_output/double_stringification.cpp_junit.txt create mode 100644 examples/all_features/test_output/double_stringification.cpp_xml.txt diff --git a/doctest/doctest.h b/doctest/doctest.h index b4a109b6..f6c51081 100644 --- a/doctest/doctest.h +++ b/doctest/doctest.h @@ -1036,6 +1036,14 @@ struct StringMaker : public detail::StringMakerBase< detail::has_insertion_operator::value || detail::types::is_pointer::value || detail::types::is_array::value> {}; +#ifndef DOCTEST_STRINGIFY +#ifdef DOCTEST_CONFIG_DOUBLE_STRINGIFY +#define DOCTEST_STRINGIFY(...) toString(toString(__VA_ARGS__)) +#else +#define DOCTEST_STRINGIFY(...) toString(__VA_ARGS__) +#endif +#endif + template String toString() { #if DOCTEST_MSVC >= 0 && DOCTEST_CLANG == 0 && DOCTEST_GCC == 0 @@ -1086,7 +1094,7 @@ DOCTEST_INTERFACE String toString(long long unsigned in); template ::value, bool>::type = true> String toString(const DOCTEST_REF_WRAP(T) value) { typedef typename detail::types::underlying_type::type UT; - return toString(static_cast(value)); + return (DOCTEST_STRINGIFY(static_cast(value))); } namespace detail { @@ -1108,7 +1116,7 @@ namespace detail { *stream << "["; for (size_t i = 0; i < N; i++) { if (i != 0) { *stream << ", "; } - *stream << toString(in[i]); + *stream << (DOCTEST_STRINGIFY(in[i])); } *stream << "]"; } @@ -1279,7 +1287,7 @@ namespace detail { String stringifyBinaryExpr(const DOCTEST_REF_WRAP(L) lhs, const char* op, const DOCTEST_REF_WRAP(R) rhs) { // NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks) - return toString(lhs) + op + toString(rhs); + return (DOCTEST_STRINGIFY(lhs)) + op + (DOCTEST_STRINGIFY(rhs)); } #if DOCTEST_CLANG && DOCTEST_CLANG < DOCTEST_COMPILER(3, 6, 0) @@ -1446,7 +1454,7 @@ DOCTEST_MSVC_SUPPRESS_WARNING_POP res = !res; if(!res || getContextOptions()->success) - return Result(res, toString(lhs)); + return Result(res, (DOCTEST_STRINGIFY(lhs))); return Result(res); } @@ -1630,7 +1638,7 @@ DOCTEST_CLANG_SUPPRESS_WARNING_POP m_failed = !m_failed; if(m_failed || getContextOptions()->success) - m_decomp = toString(val); + m_decomp = (DOCTEST_STRINGIFY(val)); return !m_failed; } @@ -1709,8 +1717,8 @@ DOCTEST_CLANG_SUPPRESS_WARNING_POP // IF THE DEBUGGER BREAKS HERE - GO 1 LEVEL UP IN THE CALLSTACK FOR THE FAILING ASSERT // THIS IS THE EFFECT OF HAVING 'DOCTEST_CONFIG_SUPER_FAST_ASSERTS' DEFINED // ################################################################################### - DOCTEST_ASSERT_OUT_OF_TESTS(toString(val)); - DOCTEST_ASSERT_IN_TESTS(toString(val)); + DOCTEST_ASSERT_OUT_OF_TESTS((DOCTEST_STRINGIFY(val))); + DOCTEST_ASSERT_IN_TESTS((DOCTEST_STRINGIFY(val))); return !failed; } @@ -1789,7 +1797,7 @@ DOCTEST_CLANG_SUPPRESS_WARNING_POP // the preferred way of chaining parameters for stringification template MessageBuilder& operator,(const T& in) { - *m_stream << toString(in); + *m_stream << (DOCTEST_STRINGIFY(in)); return *this; } @@ -6620,7 +6628,7 @@ void Context::setOption(const char* option, bool value) { // allows the user to override procedurally the int options from the command line void Context::setOption(const char* option, int value) { - setOption(option, toString(value).c_str()); + setOption(option, (DOCTEST_STRINGIFY(value)).c_str()); // NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks) } diff --git a/doctest/parts/doctest.cpp b/doctest/parts/doctest.cpp index 1115912a..1c914411 100644 --- a/doctest/parts/doctest.cpp +++ b/doctest/parts/doctest.cpp @@ -3633,7 +3633,7 @@ void Context::setOption(const char* option, bool value) { // allows the user to override procedurally the int options from the command line void Context::setOption(const char* option, int value) { - setOption(option, toString(value).c_str()); + setOption(option, (DOCTEST_STRINGIFY(value)).c_str()); // NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks) } diff --git a/doctest/parts/doctest_fwd.h b/doctest/parts/doctest_fwd.h index 3e663b73..8a5a6783 100644 --- a/doctest/parts/doctest_fwd.h +++ b/doctest/parts/doctest_fwd.h @@ -1033,6 +1033,14 @@ struct StringMaker : public detail::StringMakerBase< detail::has_insertion_operator::value || detail::types::is_pointer::value || detail::types::is_array::value> {}; +#ifndef DOCTEST_STRINGIFY +#ifdef DOCTEST_CONFIG_DOUBLE_STRINGIFY +#define DOCTEST_STRINGIFY(...) toString(toString(__VA_ARGS__)) +#else +#define DOCTEST_STRINGIFY(...) toString(__VA_ARGS__) +#endif +#endif + template String toString() { #if DOCTEST_MSVC >= 0 && DOCTEST_CLANG == 0 && DOCTEST_GCC == 0 @@ -1083,7 +1091,7 @@ DOCTEST_INTERFACE String toString(long long unsigned in); template ::value, bool>::type = true> String toString(const DOCTEST_REF_WRAP(T) value) { typedef typename detail::types::underlying_type::type UT; - return toString(static_cast(value)); + return (DOCTEST_STRINGIFY(static_cast(value))); } namespace detail { @@ -1105,7 +1113,7 @@ namespace detail { *stream << "["; for (size_t i = 0; i < N; i++) { if (i != 0) { *stream << ", "; } - *stream << toString(in[i]); + *stream << (DOCTEST_STRINGIFY(in[i])); } *stream << "]"; } @@ -1276,7 +1284,7 @@ namespace detail { String stringifyBinaryExpr(const DOCTEST_REF_WRAP(L) lhs, const char* op, const DOCTEST_REF_WRAP(R) rhs) { // NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks) - return toString(lhs) + op + toString(rhs); + return (DOCTEST_STRINGIFY(lhs)) + op + (DOCTEST_STRINGIFY(rhs)); } #if DOCTEST_CLANG && DOCTEST_CLANG < DOCTEST_COMPILER(3, 6, 0) @@ -1443,7 +1451,7 @@ DOCTEST_MSVC_SUPPRESS_WARNING_POP res = !res; if(!res || getContextOptions()->success) - return Result(res, toString(lhs)); + return Result(res, (DOCTEST_STRINGIFY(lhs))); return Result(res); } @@ -1627,7 +1635,7 @@ DOCTEST_CLANG_SUPPRESS_WARNING_POP m_failed = !m_failed; if(m_failed || getContextOptions()->success) - m_decomp = toString(val); + m_decomp = (DOCTEST_STRINGIFY(val)); return !m_failed; } @@ -1706,8 +1714,8 @@ DOCTEST_CLANG_SUPPRESS_WARNING_POP // IF THE DEBUGGER BREAKS HERE - GO 1 LEVEL UP IN THE CALLSTACK FOR THE FAILING ASSERT // THIS IS THE EFFECT OF HAVING 'DOCTEST_CONFIG_SUPER_FAST_ASSERTS' DEFINED // ################################################################################### - DOCTEST_ASSERT_OUT_OF_TESTS(toString(val)); - DOCTEST_ASSERT_IN_TESTS(toString(val)); + DOCTEST_ASSERT_OUT_OF_TESTS((DOCTEST_STRINGIFY(val))); + DOCTEST_ASSERT_IN_TESTS((DOCTEST_STRINGIFY(val))); return !failed; } @@ -1786,7 +1794,7 @@ DOCTEST_CLANG_SUPPRESS_WARNING_POP // the preferred way of chaining parameters for stringification template MessageBuilder& operator,(const T& in) { - *m_stream << toString(in); + *m_stream << (DOCTEST_STRINGIFY(in)); return *this; } diff --git a/examples/all_features/CMakeLists.txt b/examples/all_features/CMakeLists.txt index 80105c98..86dfc9e5 100644 --- a/examples/all_features/CMakeLists.txt +++ b/examples/all_features/CMakeLists.txt @@ -9,6 +9,7 @@ set(files_with_output alternative_macros.cpp assertion_macros.cpp stringification.cpp + double_stringification.cpp reporters_and_listeners.cpp subcases.cpp logging.cpp diff --git a/examples/all_features/double_stringification.cpp b/examples/all_features/double_stringification.cpp new file mode 100644 index 00000000..5a1ebb53 --- /dev/null +++ b/examples/all_features/double_stringification.cpp @@ -0,0 +1,18 @@ +#define DOCTEST_CONFIG_DOUBLE_STRINGIFY +#include + +DOCTEST_MAKE_STD_HEADERS_CLEAN_FROM_WARNINGS_ON_WALL_BEGIN +#include +DOCTEST_MAKE_STD_HEADERS_CLEAN_FROM_WARNINGS_ON_WALL_END + +namespace App { + struct Foo { }; + static std::string toString(Foo*) { return "Foo"; } +} + +TEST_CASE("toString std::string ret type") { + App::Foo foo; + CHECK(&foo != nullptr); + CHECK_NE(&foo, nullptr); + CHECK(&foo); +} diff --git a/examples/all_features/test_output/double_stringification.cpp.txt b/examples/all_features/test_output/double_stringification.cpp.txt new file mode 100644 index 00000000..75be56a8 --- /dev/null +++ b/examples/all_features/test_output/double_stringification.cpp.txt @@ -0,0 +1,6 @@ +[doctest] run with "--help" for options +=============================================================================== +[doctest] test cases: 1 | 1 passed | 0 failed | +[doctest] assertions: 3 | 3 passed | 0 failed | +[doctest] Status: SUCCESS! +Program code. diff --git a/examples/all_features/test_output/double_stringification.cpp_junit.txt b/examples/all_features/test_output/double_stringification.cpp_junit.txt new file mode 100644 index 00000000..982ca2e8 --- /dev/null +++ b/examples/all_features/test_output/double_stringification.cpp_junit.txt @@ -0,0 +1,7 @@ + + + + + + +Program code. diff --git a/examples/all_features/test_output/double_stringification.cpp_xml.txt b/examples/all_features/test_output/double_stringification.cpp_xml.txt new file mode 100644 index 00000000..9403b1c1 --- /dev/null +++ b/examples/all_features/test_output/double_stringification.cpp_xml.txt @@ -0,0 +1,12 @@ + + + + + + + + + + + +Program code. diff --git a/examples/all_features/test_output/filter_2.txt b/examples/all_features/test_output/filter_2.txt index 51219ab7..dd726cdf 100644 --- a/examples/all_features/test_output/filter_2.txt +++ b/examples/all_features/test_output/filter_2.txt @@ -1,6 +1,6 @@ [doctest] run with "--help" for options =============================================================================== -[doctest] test cases: 0 | 0 passed | 0 failed | 102 skipped +[doctest] test cases: 0 | 0 passed | 0 failed | 103 skipped [doctest] assertions: 0 | 0 passed | 0 failed | [doctest] Status: SUCCESS! Program code. diff --git a/examples/all_features/test_output/filter_2_xml.txt b/examples/all_features/test_output/filter_2_xml.txt index 211dddef..fd8a050a 100644 --- a/examples/all_features/test_output/filter_2_xml.txt +++ b/examples/all_features/test_output/filter_2_xml.txt @@ -129,6 +129,7 @@ + @@ -146,6 +147,6 @@ - + Program code. diff --git a/examples/all_features/test_output/no_multi_lane_atomics.txt b/examples/all_features/test_output/no_multi_lane_atomics.txt index 51ce44d0..8500e165 100644 --- a/examples/all_features/test_output/no_multi_lane_atomics.txt +++ b/examples/all_features/test_output/no_multi_lane_atomics.txt @@ -922,7 +922,7 @@ TEST CASE: without a funny name: subcases.cpp(0): MESSAGE: Nooo =============================================================================== -[doctest] test cases: 82 | 31 passed | 51 failed | -[doctest] assertions: 224 | 105 passed | 119 failed | +[doctest] test cases: 83 | 32 passed | 51 failed | +[doctest] assertions: 227 | 108 passed | 119 failed | [doctest] Status: FAILURE! Program code. diff --git a/examples/all_features/test_output/no_multithreading.txt b/examples/all_features/test_output/no_multithreading.txt index 51ce44d0..8500e165 100644 --- a/examples/all_features/test_output/no_multithreading.txt +++ b/examples/all_features/test_output/no_multithreading.txt @@ -922,7 +922,7 @@ TEST CASE: without a funny name: subcases.cpp(0): MESSAGE: Nooo =============================================================================== -[doctest] test cases: 82 | 31 passed | 51 failed | -[doctest] assertions: 224 | 105 passed | 119 failed | +[doctest] test cases: 83 | 32 passed | 51 failed | +[doctest] assertions: 227 | 108 passed | 119 failed | [doctest] Status: FAILURE! Program code. diff --git a/examples/all_features/test_output/stringification.cpp.txt b/examples/all_features/test_output/stringification.cpp.txt index 9f4cece4..4fe9a9a5 100644 --- a/examples/all_features/test_output/stringification.cpp.txt +++ b/examples/all_features/test_output/stringification.cpp.txt @@ -90,7 +90,7 @@ TEST CASE: a test case that registers an exception translator for int and then stringification.cpp(0): ERROR: test case THREW exception: 5 =============================================================================== -[doctest] test cases: 4 | 1 passed | 3 failed | -[doctest] assertions: 18 | 5 passed | 13 failed | +[doctest] test cases: 5 | 2 passed | 3 failed | +[doctest] assertions: 21 | 8 passed | 13 failed | [doctest] Status: FAILURE! Program code. diff --git a/examples/all_features/test_output/stringification.cpp_junit.txt b/examples/all_features/test_output/stringification.cpp_junit.txt index 93cc0769..3044abdf 100644 --- a/examples/all_features/test_output/stringification.cpp_junit.txt +++ b/examples/all_features/test_output/stringification.cpp_junit.txt @@ -1,6 +1,7 @@ - + + diff --git a/examples/all_features/test_output/stringification.cpp_xml.txt b/examples/all_features/test_output/stringification.cpp_xml.txt index e4de969a..cf7cf011 100644 --- a/examples/all_features/test_output/stringification.cpp_xml.txt +++ b/examples/all_features/test_output/stringification.cpp_xml.txt @@ -2,6 +2,9 @@ + + + @@ -204,7 +207,7 @@ - - + + Program code. -- cgit v1.2.3