Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
authorMartin Hořeňovský2021-05-18 00:02:46 +0200
committerMartin Hořeňovský2021-05-18 23:15:22 +0200
commit9137e591fa7d7fee2e8c1d3bfeb55068deb2c665 (patch)
tree983f925118ed17cffc9cc35d553bf9dae2814a11 /tests
parentf50a06affa77d4dbe0c94f684b3a6dfae04c2ebe (diff)
downloadcatch3-9137e591fa7d7fee2e8c1d3bfeb55068deb2c665.tar.gz
Cleanup and optimize stringifying of string-like types
More specifically, made the actual implementation of string-like type handling take argument as `Catch::StringRef`, instead of taking `std::string const&`. This means that string-like types that are not `std::string` no longer need to pay for an extra construction of `std::string` (including the potential allocation), before they can be stringified. The actual string stringification routine is now also better about reserving sufficient space.
Diffstat (limited to 'tests')
-rw-r--r--tests/SelfTest/Baselines/automake.sw.approved.txt3
-rw-r--r--tests/SelfTest/Baselines/compact.sw.approved.txt6
-rw-r--r--tests/SelfTest/Baselines/console.std.approved.txt4
-rw-r--r--tests/SelfTest/Baselines/console.sw.approved.txt52
-rw-r--r--tests/SelfTest/Baselines/junit.sw.approved.txt5
-rw-r--r--tests/SelfTest/Baselines/sonarqube.sw.approved.txt3
-rw-r--r--tests/SelfTest/Baselines/tap.sw.approved.txt14
-rw-r--r--tests/SelfTest/Baselines/teamcity.sw.approved.txt6
-rw-r--r--tests/SelfTest/Baselines/xml.sw.approved.txt65
-rw-r--r--tests/SelfTest/IntrospectiveTests/ToString.tests.cpp38
10 files changed, 185 insertions, 11 deletions
diff --git a/tests/SelfTest/Baselines/automake.sw.approved.txt b/tests/SelfTest/Baselines/automake.sw.approved.txt
index 588ab112..7cf2f2c8 100644
--- a/tests/SelfTest/Baselines/automake.sw.approved.txt
+++ b/tests/SelfTest/Baselines/automake.sw.approved.txt
@@ -205,6 +205,9 @@ Message from section two
:test-result: PASS String matchers
:test-result: PASS StringRef
:test-result: PASS StringRef at compilation time
+:test-result: PASS Stringifying char arrays with statically known sizes - char
+:test-result: PASS Stringifying char arrays with statically known sizes - signed char
+:test-result: PASS Stringifying char arrays with statically known sizes - unsigned char
:test-result: PASS Stringifying std::chrono::duration helpers
:test-result: PASS Stringifying std::chrono::duration with weird ratios
:test-result: PASS Stringifying std::chrono::time_point<system_clock>
diff --git a/tests/SelfTest/Baselines/compact.sw.approved.txt b/tests/SelfTest/Baselines/compact.sw.approved.txt
index c846bbb3..41e6dc96 100644
--- a/tests/SelfTest/Baselines/compact.sw.approved.txt
+++ b/tests/SelfTest/Baselines/compact.sw.approved.txt
@@ -1532,6 +1532,12 @@ String.tests.cpp:<line number>: passed: with 1 message: '!(sr1.empty())'
String.tests.cpp:<line number>: passed: with 1 message: 'sr1.size() == 3'
String.tests.cpp:<line number>: passed: with 1 message: 'sr2.empty()'
String.tests.cpp:<line number>: passed: with 1 message: 'sr2.size() == 0'
+ToString.tests.cpp:<line number>: passed: ::Catch::Detail::stringify( with_null_terminator ) == R"("abc")"s for: ""abc"" == ""abc""
+ToString.tests.cpp:<line number>: passed: ::Catch::Detail::stringify( no_null_terminator ) == R"("abc")"s for: ""abc"" == ""abc""
+ToString.tests.cpp:<line number>: passed: ::Catch::Detail::stringify( with_null_terminator ) == R"("abc")"s for: ""abc"" == ""abc""
+ToString.tests.cpp:<line number>: passed: ::Catch::Detail::stringify( no_null_terminator ) == R"("abc")"s for: ""abc"" == ""abc""
+ToString.tests.cpp:<line number>: passed: ::Catch::Detail::stringify( with_null_terminator ) == R"("abc")"s for: ""abc"" == ""abc""
+ToString.tests.cpp:<line number>: passed: ::Catch::Detail::stringify( no_null_terminator ) == R"("abc")"s for: ""abc"" == ""abc""
ToStringChrono.tests.cpp:<line number>: passed: minute == seconds for: 1 m == 60 s
ToStringChrono.tests.cpp:<line number>: passed: hour != seconds for: 1 h != 60 s
ToStringChrono.tests.cpp:<line number>: passed: micro != milli for: 1 us != 1 ms
diff --git a/tests/SelfTest/Baselines/console.std.approved.txt b/tests/SelfTest/Baselines/console.std.approved.txt
index 316fedd1..1d928cf9 100644
--- a/tests/SelfTest/Baselines/console.std.approved.txt
+++ b/tests/SelfTest/Baselines/console.std.approved.txt
@@ -1386,6 +1386,6 @@ due to unexpected exception with message:
Why would you throw a std::string?
===============================================================================
-test cases: 360 | 284 passed | 70 failed | 6 failed as expected
-assertions: 2084 | 1932 passed | 129 failed | 23 failed as expected
+test cases: 363 | 287 passed | 70 failed | 6 failed as expected
+assertions: 2090 | 1938 passed | 129 failed | 23 failed as expected
diff --git a/tests/SelfTest/Baselines/console.sw.approved.txt b/tests/SelfTest/Baselines/console.sw.approved.txt
index 9570aecb..98394d06 100644
--- a/tests/SelfTest/Baselines/console.sw.approved.txt
+++ b/tests/SelfTest/Baselines/console.sw.approved.txt
@@ -10866,6 +10866,54 @@ with message:
sr2.size() == 0
-------------------------------------------------------------------------------
+Stringifying char arrays with statically known sizes - char
+-------------------------------------------------------------------------------
+ToString.tests.cpp:<line number>
+...............................................................................
+
+ToString.tests.cpp:<line number>: PASSED:
+ CHECK( ::Catch::Detail::stringify( with_null_terminator ) == R"("abc")"s )
+with expansion:
+ ""abc"" == ""abc""
+
+ToString.tests.cpp:<line number>: PASSED:
+ CHECK( ::Catch::Detail::stringify( no_null_terminator ) == R"("abc")"s )
+with expansion:
+ ""abc"" == ""abc""
+
+-------------------------------------------------------------------------------
+Stringifying char arrays with statically known sizes - signed char
+-------------------------------------------------------------------------------
+ToString.tests.cpp:<line number>
+...............................................................................
+
+ToString.tests.cpp:<line number>: PASSED:
+ CHECK( ::Catch::Detail::stringify( with_null_terminator ) == R"("abc")"s )
+with expansion:
+ ""abc"" == ""abc""
+
+ToString.tests.cpp:<line number>: PASSED:
+ CHECK( ::Catch::Detail::stringify( no_null_terminator ) == R"("abc")"s )
+with expansion:
+ ""abc"" == ""abc""
+
+-------------------------------------------------------------------------------
+Stringifying char arrays with statically known sizes - unsigned char
+-------------------------------------------------------------------------------
+ToString.tests.cpp:<line number>
+...............................................................................
+
+ToString.tests.cpp:<line number>: PASSED:
+ CHECK( ::Catch::Detail::stringify( with_null_terminator ) == R"("abc")"s )
+with expansion:
+ ""abc"" == ""abc""
+
+ToString.tests.cpp:<line number>: PASSED:
+ CHECK( ::Catch::Detail::stringify( no_null_terminator ) == R"("abc")"s )
+with expansion:
+ ""abc"" == ""abc""
+
+-------------------------------------------------------------------------------
Stringifying std::chrono::duration helpers
-------------------------------------------------------------------------------
ToStringChrono.tests.cpp:<line number>
@@ -16782,6 +16830,6 @@ Misc.tests.cpp:<line number>
Misc.tests.cpp:<line number>: PASSED:
===============================================================================
-test cases: 360 | 268 passed | 86 failed | 6 failed as expected
-assertions: 2101 | 1932 passed | 146 failed | 23 failed as expected
+test cases: 363 | 271 passed | 86 failed | 6 failed as expected
+assertions: 2107 | 1938 passed | 146 failed | 23 failed as expected
diff --git a/tests/SelfTest/Baselines/junit.sw.approved.txt b/tests/SelfTest/Baselines/junit.sw.approved.txt
index dada5c30..7c3e2f1f 100644
--- a/tests/SelfTest/Baselines/junit.sw.approved.txt
+++ b/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="130" tests="2102" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
+ <testsuite name="<exe-name>" errors="17" failures="130" tests="2108" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
<properties>
<property name="filters" value="~[!nonportable]~[!benchmark]~[approvals] *"/>
<property name="random-seed" value="1"/>
@@ -1194,6 +1194,9 @@ Matchers.tests.cpp:<line number>
<testcase classname="<exe-name>.global" name="StringRef/StringRef + StringRef" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="StringRef at compilation time/Simple constructors" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="StringRef at compilation time/UDL construction" time="{duration}" status="run"/>
+ <testcase classname="<exe-name>.global" name="Stringifying char arrays with statically known sizes - char" time="{duration}" status="run"/>
+ <testcase classname="<exe-name>.global" name="Stringifying char arrays with statically known sizes - signed char" time="{duration}" status="run"/>
+ <testcase classname="<exe-name>.global" name="Stringifying char arrays with statically known sizes - unsigned char" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="Stringifying std::chrono::duration helpers" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="Stringifying std::chrono::duration with weird ratios" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="Stringifying std::chrono::time_point&lt;system_clock>" time="{duration}" status="run"/>
diff --git a/tests/SelfTest/Baselines/sonarqube.sw.approved.txt b/tests/SelfTest/Baselines/sonarqube.sw.approved.txt
index 8c1873f2..10d00b02 100644
--- a/tests/SelfTest/Baselines/sonarqube.sw.approved.txt
+++ b/tests/SelfTest/Baselines/sonarqube.sw.approved.txt
@@ -222,6 +222,9 @@
<file path="tests/<exe-name>/IntrospectiveTests/ToString.tests.cpp">
<testCase name="Directly creating an EnumInfo" duration="{duration}"/>
<testCase name="Range type with sentinel" duration="{duration}"/>
+ <testCase name="Stringifying char arrays with statically known sizes - char" duration="{duration}"/>
+ <testCase name="Stringifying char arrays with statically known sizes - signed char" duration="{duration}"/>
+ <testCase name="Stringifying char arrays with statically known sizes - unsigned char" duration="{duration}"/>
<testCase name="parseEnums/No enums" duration="{duration}"/>
<testCase name="parseEnums/One enum value" duration="{duration}"/>
<testCase name="parseEnums/Multiple enum values" duration="{duration}"/>
diff --git a/tests/SelfTest/Baselines/tap.sw.approved.txt b/tests/SelfTest/Baselines/tap.sw.approved.txt
index a615c103..1977fa8f 100644
--- a/tests/SelfTest/Baselines/tap.sw.approved.txt
+++ b/tests/SelfTest/Baselines/tap.sw.approved.txt
@@ -2743,6 +2743,18 @@ ok {test-number} - with 1 message: 'sr1.size() == 3'
ok {test-number} - with 1 message: 'sr2.empty()'
# StringRef at compilation time
ok {test-number} - with 1 message: 'sr2.size() == 0'
+# Stringifying char arrays with statically known sizes - char
+ok {test-number} - ::Catch::Detail::stringify( with_null_terminator ) == R"("abc")"s for: ""abc"" == ""abc""
+# Stringifying char arrays with statically known sizes - char
+ok {test-number} - ::Catch::Detail::stringify( no_null_terminator ) == R"("abc")"s for: ""abc"" == ""abc""
+# Stringifying char arrays with statically known sizes - signed char
+ok {test-number} - ::Catch::Detail::stringify( with_null_terminator ) == R"("abc")"s for: ""abc"" == ""abc""
+# Stringifying char arrays with statically known sizes - signed char
+ok {test-number} - ::Catch::Detail::stringify( no_null_terminator ) == R"("abc")"s for: ""abc"" == ""abc""
+# Stringifying char arrays with statically known sizes - unsigned char
+ok {test-number} - ::Catch::Detail::stringify( with_null_terminator ) == R"("abc")"s for: ""abc"" == ""abc""
+# Stringifying char arrays with statically known sizes - unsigned char
+ok {test-number} - ::Catch::Detail::stringify( no_null_terminator ) == R"("abc")"s for: ""abc"" == ""abc""
# Stringifying std::chrono::duration helpers
ok {test-number} - minute == seconds for: 1 m == 60 s
# Stringifying std::chrono::duration helpers
@@ -4204,5 +4216,5 @@ ok {test-number} - q3 == 23. for: 23.0 == 23.0
ok {test-number} -
# xmlentitycheck
ok {test-number} -
-1..2101
+1..2107
diff --git a/tests/SelfTest/Baselines/teamcity.sw.approved.txt b/tests/SelfTest/Baselines/teamcity.sw.approved.txt
index 1eaa89ee..e0794baf 100644
--- a/tests/SelfTest/Baselines/teamcity.sw.approved.txt
+++ b/tests/SelfTest/Baselines/teamcity.sw.approved.txt
@@ -510,6 +510,12 @@ Matchers.tests.cpp:<line number>|nexpression failed|n CHECK_THAT( testStringFor
##teamcity[testFinished name='StringRef' duration="{duration}"]
##teamcity[testStarted name='StringRef at compilation time']
##teamcity[testFinished name='StringRef at compilation time' duration="{duration}"]
+##teamcity[testStarted name='Stringifying char arrays with statically known sizes - char']
+##teamcity[testFinished name='Stringifying char arrays with statically known sizes - char' duration="{duration}"]
+##teamcity[testStarted name='Stringifying char arrays with statically known sizes - signed char']
+##teamcity[testFinished name='Stringifying char arrays with statically known sizes - signed char' duration="{duration}"]
+##teamcity[testStarted name='Stringifying char arrays with statically known sizes - unsigned char']
+##teamcity[testFinished name='Stringifying char arrays with statically known sizes - unsigned char' duration="{duration}"]
##teamcity[testStarted name='Stringifying std::chrono::duration helpers']
##teamcity[testFinished name='Stringifying std::chrono::duration helpers' duration="{duration}"]
##teamcity[testStarted name='Stringifying std::chrono::duration with weird ratios']
diff --git a/tests/SelfTest/Baselines/xml.sw.approved.txt b/tests/SelfTest/Baselines/xml.sw.approved.txt
index c0807418..ebfca6dc 100644
--- a/tests/SelfTest/Baselines/xml.sw.approved.txt
+++ b/tests/SelfTest/Baselines/xml.sw.approved.txt
@@ -12900,6 +12900,63 @@ Message from section two
</Section>
<OverallResult success="true"/>
</TestCase>
+ <TestCase name="Stringifying char arrays with statically known sizes - char" tags="[toString]" filename="tests/<exe-name>/IntrospectiveTests/ToString.tests.cpp" >
+ <Expression success="true" type="CHECK" filename="tests/<exe-name>/IntrospectiveTests/ToString.tests.cpp" >
+ <Original>
+ ::Catch::Detail::stringify( with_null_terminator ) == R"("abc")"s
+ </Original>
+ <Expanded>
+ ""abc"" == ""abc""
+ </Expanded>
+ </Expression>
+ <Expression success="true" type="CHECK" filename="tests/<exe-name>/IntrospectiveTests/ToString.tests.cpp" >
+ <Original>
+ ::Catch::Detail::stringify( no_null_terminator ) == R"("abc")"s
+ </Original>
+ <Expanded>
+ ""abc"" == ""abc""
+ </Expanded>
+ </Expression>
+ <OverallResult success="true"/>
+ </TestCase>
+ <TestCase name="Stringifying char arrays with statically known sizes - signed char" tags="[toString]" filename="tests/<exe-name>/IntrospectiveTests/ToString.tests.cpp" >
+ <Expression success="true" type="CHECK" filename="tests/<exe-name>/IntrospectiveTests/ToString.tests.cpp" >
+ <Original>
+ ::Catch::Detail::stringify( with_null_terminator ) == R"("abc")"s
+ </Original>
+ <Expanded>
+ ""abc"" == ""abc""
+ </Expanded>
+ </Expression>
+ <Expression success="true" type="CHECK" filename="tests/<exe-name>/IntrospectiveTests/ToString.tests.cpp" >
+ <Original>
+ ::Catch::Detail::stringify( no_null_terminator ) == R"("abc")"s
+ </Original>
+ <Expanded>
+ ""abc"" == ""abc""
+ </Expanded>
+ </Expression>
+ <OverallResult success="true"/>
+ </TestCase>
+ <TestCase name="Stringifying char arrays with statically known sizes - unsigned char" tags="[toString]" filename="tests/<exe-name>/IntrospectiveTests/ToString.tests.cpp" >
+ <Expression success="true" type="CHECK" filename="tests/<exe-name>/IntrospectiveTests/ToString.tests.cpp" >
+ <Original>
+ ::Catch::Detail::stringify( with_null_terminator ) == R"("abc")"s
+ </Original>
+ <Expanded>
+ ""abc"" == ""abc""
+ </Expanded>
+ </Expression>
+ <Expression success="true" type="CHECK" filename="tests/<exe-name>/IntrospectiveTests/ToString.tests.cpp" >
+ <Original>
+ ::Catch::Detail::stringify( no_null_terminator ) == R"("abc")"s
+ </Original>
+ <Expanded>
+ ""abc"" == ""abc""
+ </Expanded>
+ </Expression>
+ <OverallResult success="true"/>
+ </TestCase>
<TestCase name="Stringifying std::chrono::duration helpers" tags="[chrono][toString]" filename="tests/<exe-name>/UsageTests/ToStringChrono.tests.cpp" >
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/UsageTests/ToStringChrono.tests.cpp" >
<Original>
@@ -19745,9 +19802,9 @@ loose text artifact
</Section>
<OverallResult success="true"/>
</TestCase>
- <OverallResults successes="1932" failures="147" expectedFailures="23"/>
- <OverallResultsCases successes="268" failures="86" expectedFailures="6"/>
+ <OverallResults successes="1938" failures="147" expectedFailures="23"/>
+ <OverallResultsCases successes="271" failures="86" expectedFailures="6"/>
</Group>
- <OverallResults successes="1932" failures="146" expectedFailures="23"/>
- <OverallResultsCases successes="268" failures="86" expectedFailures="6"/>
+ <OverallResults successes="1938" failures="146" expectedFailures="23"/>
+ <OverallResultsCases successes="271" failures="86" expectedFailures="6"/>
</Catch>
diff --git a/tests/SelfTest/IntrospectiveTests/ToString.tests.cpp b/tests/SelfTest/IntrospectiveTests/ToString.tests.cpp
index 47dfdd37..c0415dc3 100644
--- a/tests/SelfTest/IntrospectiveTests/ToString.tests.cpp
+++ b/tests/SelfTest/IntrospectiveTests/ToString.tests.cpp
@@ -1,6 +1,7 @@
#include <catch2/internal/catch_enum_values_registry.hpp>
#include <catch2/matchers/catch_matchers_vector.hpp>
#include <catch2/catch_test_macros.hpp>
+#include <catch2/catch_template_test_macros.hpp>
enum class EnumClass3 { Value1, Value2, Value3, Value4 };
@@ -50,4 +51,39 @@ TEST_CASE( "Directly creating an EnumInfo" ) {
TEST_CASE("Range type with sentinel") {
CHECK( Catch::Detail::stringify(UsesSentinel{}) == "{ }" );
-} \ No newline at end of file
+}
+
+TEST_CASE("convertIntoString stringification helper", "[toString][approvals]") {
+ using namespace std::string_literals;
+ using Catch::Detail::convertIntoString;
+ using namespace Catch;
+
+ SECTION("No escaping") {
+ CHECK(convertIntoString(""_sr, false) == R"("")"s);
+ CHECK(convertIntoString("abcd"_sr, false) == R"("abcd")"s);
+ CHECK(convertIntoString("ab\ncd"_sr, false) == "\"ab\ncd\""s);
+ CHECK(convertIntoString("ab\r\ncd"_sr, false) == "\"ab\r\ncd\""s);
+ CHECK(convertIntoString("ab\"cd"_sr, false) == R"("ab"cd")"s);
+ }
+ SECTION("Escaping invisibles") {
+ CHECK(convertIntoString(""_sr, true) == R"("")"s);
+ CHECK(convertIntoString("ab\ncd"_sr, true) == R"("ab\ncd")"s);
+ CHECK(convertIntoString("ab\r\ncd"_sr, true) == R"("ab\r\ncd")"s);
+ CHECK(convertIntoString("ab\tcd"_sr, true) == R"("ab\tcd")"s);
+ CHECK(convertIntoString("ab\fcd"_sr, true) == R"("ab\fcd")"s);
+ CHECK(convertIntoString("ab\"cd"_sr, true) == R"("ab"cd")"s);
+ }
+}
+
+TEMPLATE_TEST_CASE( "Stringifying char arrays with statically known sizes",
+ "[toString]",
+ char,
+ signed char,
+ unsigned char ) {
+ using namespace std::string_literals;
+ TestType with_null_terminator[10] = "abc";
+ CHECK( ::Catch::Detail::stringify( with_null_terminator ) == R"("abc")"s );
+
+ TestType no_null_terminator[3] = { 'a', 'b', 'c' };
+ CHECK( ::Catch::Detail::stringify( no_null_terminator ) == R"("abc")"s );
+}