Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StringMaker for vector<bool>::reference and vector<bool>::const_reference #2391

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/catch2/catch_tostring.hpp
Expand Up @@ -272,6 +272,32 @@ namespace Catch {
}
};

template<>
struct StringMaker<std::vector<bool>::reference> {
static std::string convert(std::vector<bool>::reference b) {
return StringMaker<bool>::convert(b);
}
};

// For libstdc++ and MSVC's STL, std::vector<bool>::const_reference is just
// an alias for bool. For libc++, however, std::vector<bool>::const_reference
// is a distinct type. The following code will conditionally specialize
// StringMaker for std::vector<bool>::const_reference if and only if it's a
// distinct type.
struct Dummy {
operator bool() const { return false; }
};
using VectorBoolConstRef = std::conditional_t<
std::is_same<std::vector<bool>::const_reference, bool>::value,
Dummy,
std::vector<bool>::const_reference>;
template <>
struct StringMaker<VectorBoolConstRef> {
static std::string convert( VectorBoolConstRef b ) {
return StringMaker<bool>::convert(b);
}
};

template<>
struct StringMaker<char> {
static std::string convert(char c);
Expand Down
2 changes: 2 additions & 0 deletions tests/SelfTest/Baselines/automake.sw.approved.txt
Expand Up @@ -384,6 +384,8 @@ loose text artifact
:test-result: PASS unique_ptr reimplementation: basic functionality
:test-result: PASS vec<vec<string,alloc>> -> toString
:test-result: PASS vector<bool> -> toString
:test-result: PASS vector<bool>::const_reference -> toString
:test-result: PASS vector<bool>::reference -> toString
:test-result: PASS vector<int,allocator> -> toString
:test-result: PASS vector<int> -> toString
:test-result: PASS vector<string> -> toString
Expand Down
2 changes: 2 additions & 0 deletions tests/SelfTest/Baselines/automake.sw.multi.approved.txt
Expand Up @@ -376,6 +376,8 @@
:test-result: PASS unique_ptr reimplementation: basic functionality
:test-result: PASS vec<vec<string,alloc>> -> toString
:test-result: PASS vector<bool> -> toString
:test-result: PASS vector<bool>::const_reference -> toString
:test-result: PASS vector<bool>::reference -> toString
:test-result: PASS vector<int,allocator> -> toString
:test-result: PASS vector<int> -> toString
:test-result: PASS vector<string> -> toString
Expand Down
4 changes: 4 additions & 0 deletions tests/SelfTest/Baselines/compact.sw.approved.txt
Expand Up @@ -2471,6 +2471,10 @@ ToStringVector.tests.cpp:<line number>: passed: ::Catch::Detail::stringify(v) ==
ToStringVector.tests.cpp:<line number>: passed: ::Catch::Detail::stringify(bools) == "{ }" for: "{ }" == "{ }"
ToStringVector.tests.cpp:<line number>: passed: ::Catch::Detail::stringify(bools) == "{ true }" for: "{ true }" == "{ true }"
ToStringVector.tests.cpp:<line number>: passed: ::Catch::Detail::stringify(bools) == "{ true, false }" for: "{ true, false }" == "{ true, false }"
ToStringVector.tests.cpp:<line number>: passed: ::Catch::Detail::stringify( bools[0] ) == "false" for: "false" == "false"
ToStringVector.tests.cpp:<line number>: passed: ::Catch::Detail::stringify( bools[1] ) == "true" for: "true" == "true"
ToStringVector.tests.cpp:<line number>: passed: ::Catch::Detail::stringify( bools[0] ) == "false" for: "false" == "false"
ToStringVector.tests.cpp:<line number>: passed: ::Catch::Detail::stringify( bools[1] ) == "true" for: "true" == "true"
ToStringVector.tests.cpp:<line number>: passed: ::Catch::Detail::stringify(vv) == "{ }" for: "{ }" == "{ }"
ToStringVector.tests.cpp:<line number>: passed: ::Catch::Detail::stringify(vv) == "{ 42 }" for: "{ 42 }" == "{ 42 }"
ToStringVector.tests.cpp:<line number>: passed: ::Catch::Detail::stringify(vv) == "{ 42, 250 }" for: "{ 42, 250 }" == "{ 42, 250 }"
Expand Down
4 changes: 4 additions & 0 deletions tests/SelfTest/Baselines/compact.sw.multi.approved.txt
Expand Up @@ -2463,6 +2463,10 @@ ToStringVector.tests.cpp:<line number>: passed: ::Catch::Detail::stringify(v) ==
ToStringVector.tests.cpp:<line number>: passed: ::Catch::Detail::stringify(bools) == "{ }" for: "{ }" == "{ }"
ToStringVector.tests.cpp:<line number>: passed: ::Catch::Detail::stringify(bools) == "{ true }" for: "{ true }" == "{ true }"
ToStringVector.tests.cpp:<line number>: passed: ::Catch::Detail::stringify(bools) == "{ true, false }" for: "{ true, false }" == "{ true, false }"
ToStringVector.tests.cpp:<line number>: passed: ::Catch::Detail::stringify( bools[0] ) == "false" for: "false" == "false"
ToStringVector.tests.cpp:<line number>: passed: ::Catch::Detail::stringify( bools[1] ) == "true" for: "true" == "true"
ToStringVector.tests.cpp:<line number>: passed: ::Catch::Detail::stringify( bools[0] ) == "false" for: "false" == "false"
ToStringVector.tests.cpp:<line number>: passed: ::Catch::Detail::stringify( bools[1] ) == "true" for: "true" == "true"
ToStringVector.tests.cpp:<line number>: passed: ::Catch::Detail::stringify(vv) == "{ }" for: "{ }" == "{ }"
ToStringVector.tests.cpp:<line number>: passed: ::Catch::Detail::stringify(vv) == "{ 42 }" for: "{ 42 }" == "{ 42 }"
ToStringVector.tests.cpp:<line number>: passed: ::Catch::Detail::stringify(vv) == "{ 42, 250 }" for: "{ 42, 250 }" == "{ 42, 250 }"
Expand Down
4 changes: 2 additions & 2 deletions tests/SelfTest/Baselines/console.std.approved.txt
Expand Up @@ -1395,6 +1395,6 @@ due to unexpected exception with message:
Why would you throw a std::string?

===============================================================================
test cases: 385 | 309 passed | 69 failed | 7 failed as expected
assertions: 2216 | 2061 passed | 128 failed | 27 failed as expected
test cases: 387 | 311 passed | 69 failed | 7 failed as expected
assertions: 2220 | 2065 passed | 128 failed | 27 failed as expected

36 changes: 34 additions & 2 deletions tests/SelfTest/Baselines/console.sw.approved.txt
Expand Up @@ -17543,6 +17543,38 @@ ToStringVector.tests.cpp:<line number>: PASSED:
with expansion:
"{ true, false }" == "{ true, false }"

-------------------------------------------------------------------------------
vector<bool>::const_reference -> toString
-------------------------------------------------------------------------------
ToStringVector.tests.cpp:<line number>
...............................................................................

ToStringVector.tests.cpp:<line number>: PASSED:
REQUIRE( ::Catch::Detail::stringify( bools[0] ) == "false" )
with expansion:
"false" == "false"

ToStringVector.tests.cpp:<line number>: PASSED:
REQUIRE( ::Catch::Detail::stringify( bools[1] ) == "true" )
with expansion:
"true" == "true"

-------------------------------------------------------------------------------
vector<bool>::reference -> toString
-------------------------------------------------------------------------------
ToStringVector.tests.cpp:<line number>
...............................................................................

ToStringVector.tests.cpp:<line number>: PASSED:
REQUIRE( ::Catch::Detail::stringify( bools[0] ) == "false" )
with expansion:
"false" == "false"

ToStringVector.tests.cpp:<line number>: PASSED:
REQUIRE( ::Catch::Detail::stringify( bools[1] ) == "true" )
with expansion:
"true" == "true"

-------------------------------------------------------------------------------
vector<int,allocator> -> toString
-------------------------------------------------------------------------------
Expand Down Expand Up @@ -17811,6 +17843,6 @@ Misc.tests.cpp:<line number>
Misc.tests.cpp:<line number>: PASSED:

===============================================================================
test cases: 385 | 295 passed | 83 failed | 7 failed as expected
assertions: 2231 | 2061 passed | 143 failed | 27 failed as expected
test cases: 387 | 297 passed | 83 failed | 7 failed as expected
assertions: 2235 | 2065 passed | 143 failed | 27 failed as expected

36 changes: 34 additions & 2 deletions tests/SelfTest/Baselines/console.sw.multi.approved.txt
Expand Up @@ -17535,6 +17535,38 @@ ToStringVector.tests.cpp:<line number>: PASSED:
with expansion:
"{ true, false }" == "{ true, false }"

-------------------------------------------------------------------------------
vector<bool>::const_reference -> toString
-------------------------------------------------------------------------------
ToStringVector.tests.cpp:<line number>
...............................................................................

ToStringVector.tests.cpp:<line number>: PASSED:
REQUIRE( ::Catch::Detail::stringify( bools[0] ) == "false" )
with expansion:
"false" == "false"

ToStringVector.tests.cpp:<line number>: PASSED:
REQUIRE( ::Catch::Detail::stringify( bools[1] ) == "true" )
with expansion:
"true" == "true"

-------------------------------------------------------------------------------
vector<bool>::reference -> toString
-------------------------------------------------------------------------------
ToStringVector.tests.cpp:<line number>
...............................................................................

ToStringVector.tests.cpp:<line number>: PASSED:
REQUIRE( ::Catch::Detail::stringify( bools[0] ) == "false" )
with expansion:
"false" == "false"

ToStringVector.tests.cpp:<line number>: PASSED:
REQUIRE( ::Catch::Detail::stringify( bools[1] ) == "true" )
with expansion:
"true" == "true"

-------------------------------------------------------------------------------
vector<int,allocator> -> toString
-------------------------------------------------------------------------------
Expand Down Expand Up @@ -17803,6 +17835,6 @@ Misc.tests.cpp:<line number>
Misc.tests.cpp:<line number>: PASSED:

===============================================================================
test cases: 385 | 295 passed | 83 failed | 7 failed as expected
assertions: 2231 | 2061 passed | 143 failed | 27 failed as expected
test cases: 387 | 297 passed | 83 failed | 7 failed as expected
assertions: 2235 | 2065 passed | 143 failed | 27 failed as expected

4 changes: 3 additions & 1 deletion tests/SelfTest/Baselines/junit.sw.approved.txt
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuitesloose text artifact
>
<testsuite name="<exe-name>" errors="17" failures="126" tests="2231" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
<testsuite name="<exe-name>" errors="17" failures="126" tests="2235" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
<properties>
<property name="random-seed" value="1"/>
<property name="filters" value="~[!nonportable]~[!benchmark]~[approvals] *"/>
Expand Down Expand Up @@ -1882,6 +1882,8 @@ Exception.tests.cpp:<line number>
<testcase classname="<exe-name>.global" name="unique_ptr reimplementation: basic functionality/free swap" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="vec&lt;vec&lt;string,alloc>> -> toString" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="vector&lt;bool> -> toString" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="vector&lt;bool>::const_reference -> toString" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="vector&lt;bool>::reference -> toString" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="vector&lt;int,allocator> -> toString" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="vector&lt;int> -> toString" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="vector&lt;string> -> toString" time="{duration}" status="run"/>
Expand Down
4 changes: 3 additions & 1 deletion tests/SelfTest/Baselines/junit.sw.multi.approved.txt
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
<testsuite name="<exe-name>" errors="17" failures="126" tests="2231" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
<testsuite name="<exe-name>" errors="17" failures="126" tests="2235" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
<properties>
<property name="random-seed" value="1"/>
<property name="filters" value="~[!nonportable]~[!benchmark]~[approvals] *"/>
Expand Down Expand Up @@ -1881,6 +1881,8 @@ Exception.tests.cpp:<line number>
<testcase classname="<exe-name>.global" name="unique_ptr reimplementation: basic functionality/free swap" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="vec&lt;vec&lt;string,alloc>> -> toString" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="vector&lt;bool> -> toString" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="vector&lt;bool>::const_reference -> toString" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="vector&lt;bool>::reference -> toString" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="vector&lt;int,allocator> -> toString" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="vector&lt;int> -> toString" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="vector&lt;string> -> toString" time="{duration}" status="run"/>
Expand Down
2 changes: 2 additions & 0 deletions tests/SelfTest/Baselines/sonarqube.sw.approved.txt
Expand Up @@ -1859,6 +1859,8 @@ Misc.tests.cpp:<line number>
<testCase name="array&lt;int, N> -> toString" duration="{duration}"/>
<testCase name="vec&lt;vec&lt;string,alloc>> -> toString" duration="{duration}"/>
<testCase name="vector&lt;bool> -> toString" duration="{duration}"/>
<testCase name="vector&lt;bool>::const_reference -> toString" duration="{duration}"/>
<testCase name="vector&lt;bool>::reference -> toString" duration="{duration}"/>
<testCase name="vector&lt;int,allocator> -> toString" duration="{duration}"/>
<testCase name="vector&lt;int> -> toString" duration="{duration}"/>
<testCase name="vector&lt;string> -> toString" duration="{duration}"/>
Expand Down
2 changes: 2 additions & 0 deletions tests/SelfTest/Baselines/sonarqube.sw.multi.approved.txt
Expand Up @@ -1858,6 +1858,8 @@ Misc.tests.cpp:<line number>
<testCase name="array&lt;int, N> -> toString" duration="{duration}"/>
<testCase name="vec&lt;vec&lt;string,alloc>> -> toString" duration="{duration}"/>
<testCase name="vector&lt;bool> -> toString" duration="{duration}"/>
<testCase name="vector&lt;bool>::const_reference -> toString" duration="{duration}"/>
<testCase name="vector&lt;bool>::reference -> toString" duration="{duration}"/>
<testCase name="vector&lt;int,allocator> -> toString" duration="{duration}"/>
<testCase name="vector&lt;int> -> toString" duration="{duration}"/>
<testCase name="vector&lt;string> -> toString" duration="{duration}"/>
Expand Down
10 changes: 9 additions & 1 deletion tests/SelfTest/Baselines/tap.sw.approved.txt
Expand Up @@ -4398,6 +4398,14 @@ ok {test-number} - ::Catch::Detail::stringify(bools) == "{ }" for: "{ }" == "{
ok {test-number} - ::Catch::Detail::stringify(bools) == "{ true }" for: "{ true }" == "{ true }"
# vector<bool> -> toString
ok {test-number} - ::Catch::Detail::stringify(bools) == "{ true, false }" for: "{ true, false }" == "{ true, false }"
# vector<bool>::const_reference -> toString
ok {test-number} - ::Catch::Detail::stringify( bools[0] ) == "false" for: "false" == "false"
# vector<bool>::const_reference -> toString
ok {test-number} - ::Catch::Detail::stringify( bools[1] ) == "true" for: "true" == "true"
# vector<bool>::reference -> toString
ok {test-number} - ::Catch::Detail::stringify( bools[0] ) == "false" for: "false" == "false"
# vector<bool>::reference -> toString
ok {test-number} - ::Catch::Detail::stringify( bools[1] ) == "true" for: "true" == "true"
# vector<int,allocator> -> toString
ok {test-number} - ::Catch::Detail::stringify(vv) == "{ }" for: "{ }" == "{ }"
# vector<int,allocator> -> toString
Expand Down Expand Up @@ -4464,5 +4472,5 @@ ok {test-number} - q3 == 23. for: 23.0 == 23.0
ok {test-number} -
# xmlentitycheck
ok {test-number} -
1..2231
1..2235

10 changes: 9 additions & 1 deletion tests/SelfTest/Baselines/tap.sw.multi.approved.txt
Expand Up @@ -4390,6 +4390,14 @@ ok {test-number} - ::Catch::Detail::stringify(bools) == "{ }" for: "{ }" == "{
ok {test-number} - ::Catch::Detail::stringify(bools) == "{ true }" for: "{ true }" == "{ true }"
# vector<bool> -> toString
ok {test-number} - ::Catch::Detail::stringify(bools) == "{ true, false }" for: "{ true, false }" == "{ true, false }"
# vector<bool>::const_reference -> toString
ok {test-number} - ::Catch::Detail::stringify( bools[0] ) == "false" for: "false" == "false"
# vector<bool>::const_reference -> toString
ok {test-number} - ::Catch::Detail::stringify( bools[1] ) == "true" for: "true" == "true"
# vector<bool>::reference -> toString
ok {test-number} - ::Catch::Detail::stringify( bools[0] ) == "false" for: "false" == "false"
# vector<bool>::reference -> toString
ok {test-number} - ::Catch::Detail::stringify( bools[1] ) == "true" for: "true" == "true"
# vector<int,allocator> -> toString
ok {test-number} - ::Catch::Detail::stringify(vv) == "{ }" for: "{ }" == "{ }"
# vector<int,allocator> -> toString
Expand Down Expand Up @@ -4456,5 +4464,5 @@ ok {test-number} - q3 == 23. for: 23.0 == 23.0
ok {test-number} -
# xmlentitycheck
ok {test-number} -
1..2231
1..2235

4 changes: 4 additions & 0 deletions tests/SelfTest/Baselines/teamcity.sw.approved.txt
Expand Up @@ -916,6 +916,10 @@ Exception.tests.cpp:<line number>|nunexpected exception with message:|n "Why wo
##teamcity[testFinished name='vec<vec<string,alloc>> -> toString' duration="{duration}"]
##teamcity[testStarted name='vector<bool> -> toString']
##teamcity[testFinished name='vector<bool> -> toString' duration="{duration}"]
##teamcity[testStarted name='vector<bool>::const_reference -> toString']
##teamcity[testFinished name='vector<bool>::const_reference -> toString' duration="{duration}"]
##teamcity[testStarted name='vector<bool>::reference -> toString']
##teamcity[testFinished name='vector<bool>::reference -> toString' duration="{duration}"]
##teamcity[testStarted name='vector<int,allocator> -> toString']
##teamcity[testFinished name='vector<int,allocator> -> toString' duration="{duration}"]
##teamcity[testStarted name='vector<int> -> toString']
Expand Down
4 changes: 4 additions & 0 deletions tests/SelfTest/Baselines/teamcity.sw.multi.approved.txt
Expand Up @@ -915,6 +915,10 @@ Exception.tests.cpp:<line number>|nunexpected exception with message:|n "Why wo
##teamcity[testFinished name='vec<vec<string,alloc>> -> toString' duration="{duration}"]
##teamcity[testStarted name='vector<bool> -> toString']
##teamcity[testFinished name='vector<bool> -> toString' duration="{duration}"]
##teamcity[testStarted name='vector<bool>::const_reference -> toString']
##teamcity[testFinished name='vector<bool>::const_reference -> toString' duration="{duration}"]
##teamcity[testStarted name='vector<bool>::reference -> toString']
##teamcity[testFinished name='vector<bool>::reference -> toString' duration="{duration}"]
##teamcity[testStarted name='vector<int,allocator> -> toString']
##teamcity[testFinished name='vector<int,allocator> -> toString' duration="{duration}"]
##teamcity[testStarted name='vector<int> -> toString']
Expand Down
42 changes: 40 additions & 2 deletions tests/SelfTest/Baselines/xml.sw.approved.txt
Expand Up @@ -20639,6 +20639,44 @@ loose text artifact
</Expression>
<OverallResult success="true"/>
</TestCase>
<TestCase name="vector&lt;bool>::const_reference -> toString" tags="[containers][toString][vector]" filename="tests/<exe-name>/UsageTests/ToStringVector.tests.cpp" >
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/UsageTests/ToStringVector.tests.cpp" >
<Original>
::Catch::Detail::stringify( bools[0] ) == "false"
</Original>
<Expanded>
"false" == "false"
</Expanded>
</Expression>
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/UsageTests/ToStringVector.tests.cpp" >
<Original>
::Catch::Detail::stringify( bools[1] ) == "true"
</Original>
<Expanded>
"true" == "true"
</Expanded>
</Expression>
<OverallResult success="true"/>
</TestCase>
<TestCase name="vector&lt;bool>::reference -> toString" tags="[containers][toString][vector]" filename="tests/<exe-name>/UsageTests/ToStringVector.tests.cpp" >
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/UsageTests/ToStringVector.tests.cpp" >
<Original>
::Catch::Detail::stringify( bools[0] ) == "false"
</Original>
<Expanded>
"false" == "false"
</Expanded>
</Expression>
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/UsageTests/ToStringVector.tests.cpp" >
<Original>
::Catch::Detail::stringify( bools[1] ) == "true"
</Original>
<Expanded>
"true" == "true"
</Expanded>
</Expression>
<OverallResult success="true"/>
</TestCase>
<TestCase name="vector&lt;int,allocator> -> toString" tags="[toString][vector,allocator]" filename="tests/<exe-name>/UsageTests/ToStringVector.tests.cpp" >
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/UsageTests/ToStringVector.tests.cpp" >
<Original>
Expand Down Expand Up @@ -20931,6 +20969,6 @@ loose text artifact
</Section>
<OverallResult success="true"/>
</TestCase>
<OverallResults successes="2061" failures="143" expectedFailures="27"/>
<OverallResultsCases successes="295" failures="83" expectedFailures="7"/>
<OverallResults successes="2065" failures="143" expectedFailures="27"/>
<OverallResultsCases successes="297" failures="83" expectedFailures="7"/>
</Catch2TestRun>