diff --git a/src/catch2/catch_test_case_info.cpp b/src/catch2/catch_test_case_info.cpp index 7dab6ae4..7dd88c2d 100644 --- a/src/catch2/catch_test_case_info.cpp +++ b/src/catch2/catch_test_case_info.cpp @@ -108,13 +108,13 @@ namespace Catch { } Detail::unique_ptr - makeTestCaseInfo(std::string const& _className, + makeTestCaseInfo(StringRef _className, NameAndTags const& nameAndTags, SourceLineInfo const& _lineInfo ) { return Detail::make_unique(_className, nameAndTags, _lineInfo); } - TestCaseInfo::TestCaseInfo(std::string const& _className, + TestCaseInfo::TestCaseInfo(StringRef _className, NameAndTags const& _nameAndTags, SourceLineInfo const& _lineInfo): name( _nameAndTags.name.empty() ? makeDefaultName() : _nameAndTags.name ), diff --git a/src/catch2/catch_test_case_info.hpp b/src/catch2/catch_test_case_info.hpp index 8048bd3a..cae3b45a 100644 --- a/src/catch2/catch_test_case_info.hpp +++ b/src/catch2/catch_test_case_info.hpp @@ -57,7 +57,7 @@ namespace Catch { */ struct TestCaseInfo : Detail::NonCopyable { - TestCaseInfo(std::string const& _className, + TestCaseInfo(StringRef _className, NameAndTags const& _tags, SourceLineInfo const& _lineInfo); @@ -77,7 +77,7 @@ namespace Catch { std::string tagsAsString() const; std::string name; - std::string className; + StringRef className; private: std::string backingTags, backingLCaseTags; // Internally we copy tags to the backing storage and then add @@ -109,9 +109,10 @@ namespace Catch { TestCaseInfo const& getTestCaseInfo() const; }; - Detail::unique_ptr makeTestCaseInfo( std::string const& className, - NameAndTags const& nameAndTags, - SourceLineInfo const& lineInfo ); + Detail::unique_ptr + makeTestCaseInfo( StringRef className, + NameAndTags const& nameAndTags, + SourceLineInfo const& lineInfo ); } #ifdef __clang__ diff --git a/src/catch2/internal/catch_test_registry.cpp b/src/catch2/internal/catch_test_registry.cpp index d33ba27a..c9e9fe4f 100644 --- a/src/catch2/internal/catch_test_registry.cpp +++ b/src/catch2/internal/catch_test_registry.cpp @@ -13,21 +13,36 @@ #include #include +#include +#include + namespace Catch { namespace { - std::string extractClassName( StringRef classOrQualifiedMethodName ) { - std::string className( classOrQualifiedMethodName ); - if ( startsWith( className, '&' ) ) { - std::size_t lastColons = className.rfind( "::" ); - std::size_t penultimateColons = - className.rfind( "::", lastColons - 1 ); - if ( penultimateColons == std::string::npos ) - penultimateColons = 1; - className = className.substr( penultimateColons, - lastColons - penultimateColons ); + StringRef extractClassName( StringRef classOrMethodName ) { + if ( !startsWith( classOrMethodName, '&' ) ) { + return classOrMethodName; } - return className; + + // Remove the leading '&' to avoid having to special case it later + const auto methodName = + classOrMethodName.substr( 1, classOrMethodName.size() ); + + auto reverseStart = std::make_reverse_iterator( methodName.end() ); + auto reverseEnd = std::make_reverse_iterator( methodName.begin() ); + + // We make a simplifying assumption that ":" is only present + // in the input as part of "::" from C++ typenames (this is + // relatively safe assumption because the input is generated + // as stringification of type through preprocessor). + auto lastColons = std::find( reverseStart, reverseEnd, ':' ) + 1; + auto secondLastColons = + std::find( lastColons + 1, reverseEnd, ':' ); + + auto const startIdx = reverseEnd - secondLastColons; + auto const classNameSize = secondLastColons - lastColons - 1; + + return methodName.substr( startIdx, classNameSize ); } } // namespace diff --git a/src/catch2/reporters/catch_reporter_junit.cpp b/src/catch2/reporters/catch_reporter_junit.cpp index f7420b7a..442795ea 100644 --- a/src/catch2/reporters/catch_reporter_junit.cpp +++ b/src/catch2/reporters/catch_reporter_junit.cpp @@ -145,12 +145,14 @@ namespace Catch { assert( testCaseNode.children.size() == 1 ); SectionNode const& rootSection = *testCaseNode.children.front(); - std::string className = stats.testInfo->className; + std::string className = + static_cast( stats.testInfo->className ); if( className.empty() ) { className = fileNameTag(stats.testInfo->tags); - if ( className.empty() ) + if ( className.empty() ) { className = "global"; + } } if ( !m_config->name().empty() ) diff --git a/tests/SelfTest/Baselines/automake.sw.approved.txt b/tests/SelfTest/Baselines/automake.sw.approved.txt index 54d94cc2..7b401531 100644 --- a/tests/SelfTest/Baselines/automake.sw.approved.txt +++ b/tests/SelfTest/Baselines/automake.sw.approved.txt @@ -207,7 +207,6 @@ Message from section two :test-result: PASS String matchers :test-result: PASS StringRef :test-result: PASS StringRef at compilation time -:test-result: PASS StringRef::compare :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 diff --git a/tests/SelfTest/Baselines/compact.sw.approved.txt b/tests/SelfTest/Baselines/compact.sw.approved.txt index 8b3df2ac..1813ff3c 100644 --- a/tests/SelfTest/Baselines/compact.sw.approved.txt +++ b/tests/SelfTest/Baselines/compact.sw.approved.txt @@ -1537,16 +1537,6 @@ String.tests.cpp:: passed: with 1 message: '!(sr1.empty())' String.tests.cpp:: passed: with 1 message: 'sr1.size() == 3' String.tests.cpp:: passed: with 1 message: 'sr2.empty()' String.tests.cpp:: passed: with 1 message: 'sr2.size() == 0' -String.tests.cpp:: passed: sr1.compare(sr2) < 0 for: -1 < 0 -String.tests.cpp:: passed: sr2.compare(sr1) > 0 for: 1 > 0 -String.tests.cpp:: passed: sr1.compare(sr3) == 0 for: 0 == 0 -String.tests.cpp:: passed: sr3.compare(sr1) == 0 for: 0 == 0 -String.tests.cpp:: passed: sr1.compare(sr2) < 0 for: -1 < 0 -String.tests.cpp:: passed: sr2.compare(sr1) > 0 for: 1 > 0 -String.tests.cpp:: passed: sr1.compare(sr3) > 0 for: 3 > 0 -String.tests.cpp:: passed: sr2.compare(sr3) > 0 for: 3 > 0 -String.tests.cpp:: passed: sr3.compare(sr1) < 0 for: -3 < 0 -String.tests.cpp:: passed: sr3.compare(sr2) < 0 for: -3 < 0 ToString.tests.cpp:: passed: ::Catch::Detail::stringify( with_null_terminator ) == R"("abc")"s for: ""abc"" == ""abc"" ToString.tests.cpp:: passed: ::Catch::Detail::stringify( no_null_terminator ) == R"("abc")"s for: ""abc"" == ""abc"" ToString.tests.cpp:: passed: ::Catch::Detail::stringify( with_null_terminator ) == R"("abc")"s for: ""abc"" == ""abc"" diff --git a/tests/SelfTest/Baselines/console.std.approved.txt b/tests/SelfTest/Baselines/console.std.approved.txt index a8a8fcb4..13b39435 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: 370 | 294 passed | 70 failed | 6 failed as expected -assertions: 2116 | 1964 passed | 129 failed | 23 failed as expected +test cases: 369 | 293 passed | 70 failed | 6 failed as expected +assertions: 2106 | 1954 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 12ca8ad7..ba1d14c9 100644 --- a/tests/SelfTest/Baselines/console.sw.approved.txt +++ b/tests/SelfTest/Baselines/console.sw.approved.txt @@ -10906,70 +10906,6 @@ String.tests.cpp:: PASSED: with message: sr2.size() == 0 -------------------------------------------------------------------------------- -StringRef::compare - Same length on both sides -------------------------------------------------------------------------------- -String.tests.cpp: -............................................................................... - -String.tests.cpp:: PASSED: - REQUIRE( sr1.compare(sr2) < 0 ) -with expansion: - -1 < 0 - -String.tests.cpp:: PASSED: - REQUIRE( sr2.compare(sr1) > 0 ) -with expansion: - 1 > 0 - -String.tests.cpp:: PASSED: - REQUIRE( sr1.compare(sr3) == 0 ) -with expansion: - 0 == 0 - -String.tests.cpp:: PASSED: - REQUIRE( sr3.compare(sr1) == 0 ) -with expansion: - 0 == 0 - -------------------------------------------------------------------------------- -StringRef::compare - Different lengths -------------------------------------------------------------------------------- -String.tests.cpp: -............................................................................... - -String.tests.cpp:: PASSED: - REQUIRE( sr1.compare(sr2) < 0 ) -with expansion: - -1 < 0 - -String.tests.cpp:: PASSED: - REQUIRE( sr2.compare(sr1) > 0 ) -with expansion: - 1 > 0 - -String.tests.cpp:: PASSED: - REQUIRE( sr1.compare(sr3) > 0 ) -with expansion: - 3 > 0 - -String.tests.cpp:: PASSED: - REQUIRE( sr2.compare(sr3) > 0 ) -with expansion: - 3 > 0 - -String.tests.cpp:: PASSED: - REQUIRE( sr3.compare(sr1) < 0 ) -with expansion: - -3 < 0 - -String.tests.cpp:: PASSED: - REQUIRE( sr3.compare(sr2) < 0 ) -with expansion: - -3 < 0 - ------------------------------------------------------------------------------- Stringifying char arrays with statically known sizes - char ------------------------------------------------------------------------------- @@ -17018,6 +16954,6 @@ Misc.tests.cpp: Misc.tests.cpp:: PASSED: =============================================================================== -test cases: 370 | 278 passed | 86 failed | 6 failed as expected -assertions: 2133 | 1964 passed | 146 failed | 23 failed as expected +test cases: 369 | 277 passed | 86 failed | 6 failed as expected +assertions: 2123 | 1954 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 57225235..f6285201 100644 --- a/tests/SelfTest/Baselines/junit.sw.approved.txt +++ b/tests/SelfTest/Baselines/junit.sw.approved.txt @@ -1,7 +1,7 @@ - + @@ -1196,8 +1196,6 @@ Matchers.tests.cpp: - - diff --git a/tests/SelfTest/Baselines/sonarqube.sw.approved.txt b/tests/SelfTest/Baselines/sonarqube.sw.approved.txt index 6c43b6b3..c95948c3 100644 --- a/tests/SelfTest/Baselines/sonarqube.sw.approved.txt +++ b/tests/SelfTest/Baselines/sonarqube.sw.approved.txt @@ -204,8 +204,6 @@ - - diff --git a/tests/SelfTest/Baselines/tap.sw.approved.txt b/tests/SelfTest/Baselines/tap.sw.approved.txt index 6583d673..a82febac 100644 --- a/tests/SelfTest/Baselines/tap.sw.approved.txt +++ b/tests/SelfTest/Baselines/tap.sw.approved.txt @@ -2753,26 +2753,6 @@ 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' -# StringRef::compare -ok {test-number} - sr1.compare(sr2) < 0 for: -1 < 0 -# StringRef::compare -ok {test-number} - sr2.compare(sr1) > 0 for: 1 > 0 -# StringRef::compare -ok {test-number} - sr1.compare(sr3) == 0 for: 0 == 0 -# StringRef::compare -ok {test-number} - sr3.compare(sr1) == 0 for: 0 == 0 -# StringRef::compare -ok {test-number} - sr1.compare(sr2) < 0 for: -1 < 0 -# StringRef::compare -ok {test-number} - sr2.compare(sr1) > 0 for: 1 > 0 -# StringRef::compare -ok {test-number} - sr1.compare(sr3) > 0 for: 3 > 0 -# StringRef::compare -ok {test-number} - sr2.compare(sr3) > 0 for: 3 > 0 -# StringRef::compare -ok {test-number} - sr3.compare(sr1) < 0 for: -3 < 0 -# StringRef::compare -ok {test-number} - sr3.compare(sr2) < 0 for: -3 < 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 @@ -4268,5 +4248,5 @@ ok {test-number} - q3 == 23. for: 23.0 == 23.0 ok {test-number} - # xmlentitycheck ok {test-number} - -1..2133 +1..2123 diff --git a/tests/SelfTest/Baselines/teamcity.sw.approved.txt b/tests/SelfTest/Baselines/teamcity.sw.approved.txt index d61c69df..3867ec4a 100644 --- a/tests/SelfTest/Baselines/teamcity.sw.approved.txt +++ b/tests/SelfTest/Baselines/teamcity.sw.approved.txt @@ -514,8 +514,6 @@ Matchers.tests.cpp:|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='StringRef::compare'] -##teamcity[testFinished name='StringRef::compare' 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'] diff --git a/tests/SelfTest/Baselines/xml.sw.approved.txt b/tests/SelfTest/Baselines/xml.sw.approved.txt index a20b2ffb..917010be 100644 --- a/tests/SelfTest/Baselines/xml.sw.approved.txt +++ b/tests/SelfTest/Baselines/xml.sw.approved.txt @@ -12945,95 +12945,6 @@ Message from section two - -
- - - sr1.compare(sr2) < 0 - - - -1 < 0 - - - - - sr2.compare(sr1) > 0 - - - 1 > 0 - - - - - sr1.compare(sr3) == 0 - - - 0 == 0 - - - - - sr3.compare(sr1) == 0 - - - 0 == 0 - - - -
-
- - - sr1.compare(sr2) < 0 - - - -1 < 0 - - - - - sr2.compare(sr1) > 0 - - - 1 > 0 - - - - - sr1.compare(sr3) > 0 - - - 3 > 0 - - - - - sr2.compare(sr3) > 0 - - - 3 > 0 - - - - - sr3.compare(sr1) < 0 - - - -3 < 0 - - - - - sr3.compare(sr2) < 0 - - - -3 < 0 - - - -
- -
@@ -20042,6 +19953,6 @@ loose text artifact - - + + diff --git a/tests/SelfTest/IntrospectiveTests/String.tests.cpp b/tests/SelfTest/IntrospectiveTests/String.tests.cpp index c44b7230..9fd8a780 100644 --- a/tests/SelfTest/IntrospectiveTests/String.tests.cpp +++ b/tests/SelfTest/IntrospectiveTests/String.tests.cpp @@ -166,7 +166,7 @@ TEST_CASE("StringRef at compilation time", "[Strings][StringRef][constexpr]") { } } -TEST_CASE("StringRef::compare", "[Strings][StringRef]") { +TEST_CASE("StringRef::compare", "[Strings][StringRef][approvals]") { using Catch::StringRef; SECTION("Same length on both sides") {