Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
* Fix doctest#508

* Missed warning suppression
  • Loading branch information
Saalvage authored Apr 30, 2022
1 parent f592f38 commit 4e11100
Show file tree
Hide file tree
Showing 15 changed files with 94 additions and 29 deletions.
26 changes: 17 additions & 9 deletions doctest/doctest.h
Original file line number Diff line number Diff line change
Expand Up @@ -1036,6 +1036,14 @@ struct StringMaker : public detail::StringMakerBase<
detail::has_insertion_operator<T>::value || detail::types::is_pointer<T>::value || detail::types::is_array<T>::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 <typename T>
String toString() {
#if DOCTEST_MSVC >= 0 && DOCTEST_CLANG == 0 && DOCTEST_GCC == 0
Expand Down Expand Up @@ -1086,7 +1094,7 @@ DOCTEST_INTERFACE String toString(long long unsigned in);
template <typename T, typename detail::types::enable_if<detail::types::is_enum<T>::value, bool>::type = true>
String toString(const DOCTEST_REF_WRAP(T) value) {
typedef typename detail::types::underlying_type<T>::type UT;
return toString(static_cast<UT>(value));
return (DOCTEST_STRINGIFY(static_cast<UT>(value)));
}

namespace detail {
Expand All @@ -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 << "]";
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -1789,7 +1797,7 @@ DOCTEST_CLANG_SUPPRESS_WARNING_POP
// the preferred way of chaining parameters for stringification
template <typename T>
MessageBuilder& operator,(const T& in) {
*m_stream << toString(in);
*m_stream << (DOCTEST_STRINGIFY(in));
return *this;
}

Expand Down Expand Up @@ -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)
}

Expand Down
2 changes: 1 addition & 1 deletion doctest/parts/doctest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
24 changes: 16 additions & 8 deletions doctest/parts/doctest_fwd.h
Original file line number Diff line number Diff line change
Expand Up @@ -1033,6 +1033,14 @@ struct StringMaker : public detail::StringMakerBase<
detail::has_insertion_operator<T>::value || detail::types::is_pointer<T>::value || detail::types::is_array<T>::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 <typename T>
String toString() {
#if DOCTEST_MSVC >= 0 && DOCTEST_CLANG == 0 && DOCTEST_GCC == 0
Expand Down Expand Up @@ -1083,7 +1091,7 @@ DOCTEST_INTERFACE String toString(long long unsigned in);
template <typename T, typename detail::types::enable_if<detail::types::is_enum<T>::value, bool>::type = true>
String toString(const DOCTEST_REF_WRAP(T) value) {
typedef typename detail::types::underlying_type<T>::type UT;
return toString(static_cast<UT>(value));
return (DOCTEST_STRINGIFY(static_cast<UT>(value)));
}

namespace detail {
Expand All @@ -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 << "]";
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -1786,7 +1794,7 @@ DOCTEST_CLANG_SUPPRESS_WARNING_POP
// the preferred way of chaining parameters for stringification
template <typename T>
MessageBuilder& operator,(const T& in) {
*m_stream << toString(in);
*m_stream << (DOCTEST_STRINGIFY(in));
return *this;
}

Expand Down
1 change: 1 addition & 0 deletions examples/all_features/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions examples/all_features/double_stringification.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#define DOCTEST_CONFIG_DOUBLE_STRINGIFY
#include <doctest_fwd.h>

DOCTEST_MAKE_STD_HEADERS_CLEAN_FROM_WARNINGS_ON_WALL_BEGIN
#include <string>
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);
}
Original file line number Diff line number Diff line change
@@ -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.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
<testsuite name="all_features" errors="0" failures="0" tests="3">
<testcase classname="double_stringification.cpp" name="toString std::string ret type" status="run"/>
</testsuite>
</testsuites>
Program code.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<doctest binary="all_features">
<Options order_by="file" rand_seed="324" first="0" last="4294967295" abort_after="0" subcase_filter_levels="2147483647" case_sensitive="false" no_throw="false" no_skip="false"/>
<TestSuite>
<TestCase name="toString std::string ret type" filename="double_stringification.cpp" line="0">
<OverallResultsAsserts successes="3" failures="0" test_case_success="true"/>
</TestCase>
</TestSuite>
<OverallResultsAsserts successes="3" failures="0"/>
<OverallResultsTestCases successes="1" failures="0"/>
</doctest>
Program code.
2 changes: 1 addition & 1 deletion examples/all_features/test_output/filter_2.txt
Original file line number Diff line number Diff line change
@@ -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.
3 changes: 2 additions & 1 deletion examples/all_features/test_output/filter_2_xml.txt
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@
<TestCase name="test case should fail even though the last subcase passes" filename="subcases.cpp" line="0" skipped="true"/>
<TestCase name="third party asserts can report failures to doctest" filename="logging.cpp" line="0" skipped="true"/>
<TestCase name="threads..." filename="concurrency.cpp" line="0" skipped="true"/>
<TestCase name="toString std::string ret type" filename="double_stringification.cpp" line="0" skipped="true"/>
</TestSuite>
<TestSuite name="skipped test cases">
<TestCase name="unskipped" filename="test_cases_and_suites.cpp" line="0" description="this test has overridden its skip decorator" skipped="true"/>
Expand All @@ -146,6 +147,6 @@
<TestCase name="without a funny name:" filename="subcases.cpp" line="0" skipped="true"/>
</TestSuite>
<OverallResultsAsserts successes="0" failures="0"/>
<OverallResultsTestCases successes="0" failures="0" skipped="102"/>
<OverallResultsTestCases successes="0" failures="0" skipped="103"/>
</doctest>
Program code.
4 changes: 2 additions & 2 deletions examples/all_features/test_output/no_multi_lane_atomics.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
4 changes: 2 additions & 2 deletions examples/all_features/test_output/no_multithreading.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
4 changes: 2 additions & 2 deletions examples/all_features/test_output/stringification.cpp.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
<testsuite name="all_features" errors="2" failures="13" tests="18">
<testsuite name="all_features" errors="2" failures="13" tests="21">
<testcase classname="double_stringification.cpp" name="toString std::string ret type" status="run"/>
<testcase classname="stringification.cpp" name="operator&lt;&lt;" status="run"/>
<testcase classname="stringification.cpp" name="no headers" status="run">
<failure message="1as == nullptr" type="CHECK">
Expand Down
7 changes: 5 additions & 2 deletions examples/all_features/test_output/stringification.cpp_xml.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
<doctest binary="all_features">
<Options order_by="file" rand_seed="324" first="0" last="4294967295" abort_after="0" subcase_filter_levels="2147483647" case_sensitive="false" no_throw="false" no_skip="false"/>
<TestSuite>
<TestCase name="toString std::string ret type" filename="double_stringification.cpp" line="0">
<OverallResultsAsserts successes="3" failures="0" test_case_success="true"/>
</TestCase>
<TestCase name="operator&lt;&lt;" filename="stringification.cpp" line="0">
<Message type="WARNING" filename="stringification.cpp" line="0">
<Text>
Expand Down Expand Up @@ -204,7 +207,7 @@
<OverallResultsAsserts successes="0" failures="0" test_case_success="false"/>
</TestCase>
</TestSuite>
<OverallResultsAsserts successes="5" failures="13"/>
<OverallResultsTestCases successes="1" failures="3"/>
<OverallResultsAsserts successes="8" failures="13"/>
<OverallResultsTestCases successes="2" failures="3"/>
</doctest>
Program code.

0 comments on commit 4e11100

Please sign in to comment.