mirror of
https://github.com/catchorg/Catch2.git
synced 2024-12-23 03:43:28 +01:00
Use StringRef for className in TestCaseInfo
This commit is contained in:
parent
21b99d6f58
commit
f02c2678a1
@ -108,13 +108,13 @@ namespace Catch {
|
||||
}
|
||||
|
||||
Detail::unique_ptr<TestCaseInfo>
|
||||
makeTestCaseInfo(std::string const& _className,
|
||||
makeTestCaseInfo(StringRef _className,
|
||||
NameAndTags const& nameAndTags,
|
||||
SourceLineInfo const& _lineInfo ) {
|
||||
return Detail::make_unique<TestCaseInfo>(_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 ),
|
||||
|
@ -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<TestCaseInfo> makeTestCaseInfo( std::string const& className,
|
||||
NameAndTags const& nameAndTags,
|
||||
SourceLineInfo const& lineInfo );
|
||||
Detail::unique_ptr<TestCaseInfo>
|
||||
makeTestCaseInfo( StringRef className,
|
||||
NameAndTags const& nameAndTags,
|
||||
SourceLineInfo const& lineInfo );
|
||||
}
|
||||
|
||||
#ifdef __clang__
|
||||
|
@ -13,21 +13,36 @@
|
||||
#include <catch2/internal/catch_string_manip.hpp>
|
||||
#include <catch2/internal/catch_move_and_forward.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <iterator>
|
||||
|
||||
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
|
||||
|
||||
|
@ -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<std::string>( stats.testInfo->className );
|
||||
|
||||
if( className.empty() ) {
|
||||
className = fileNameTag(stats.testInfo->tags);
|
||||
if ( className.empty() )
|
||||
if ( className.empty() ) {
|
||||
className = "global";
|
||||
}
|
||||
}
|
||||
|
||||
if ( !m_config->name().empty() )
|
||||
|
@ -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
|
||||
|
@ -1537,16 +1537,6 @@ 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'
|
||||
String.tests.cpp:<line number>: passed: sr1.compare(sr2) < 0 for: -1 < 0
|
||||
String.tests.cpp:<line number>: passed: sr2.compare(sr1) > 0 for: 1 > 0
|
||||
String.tests.cpp:<line number>: passed: sr1.compare(sr3) == 0 for: 0 == 0
|
||||
String.tests.cpp:<line number>: passed: sr3.compare(sr1) == 0 for: 0 == 0
|
||||
String.tests.cpp:<line number>: passed: sr1.compare(sr2) < 0 for: -1 < 0
|
||||
String.tests.cpp:<line number>: passed: sr2.compare(sr1) > 0 for: 1 > 0
|
||||
String.tests.cpp:<line number>: passed: sr1.compare(sr3) > 0 for: 3 > 0
|
||||
String.tests.cpp:<line number>: passed: sr2.compare(sr3) > 0 for: 3 > 0
|
||||
String.tests.cpp:<line number>: passed: sr3.compare(sr1) < 0 for: -3 < 0
|
||||
String.tests.cpp:<line number>: passed: sr3.compare(sr2) < 0 for: -3 < 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""
|
||||
|
@ -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
|
||||
|
||||
|
@ -10906,70 +10906,6 @@ String.tests.cpp:<line number>: PASSED:
|
||||
with message:
|
||||
sr2.size() == 0
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
StringRef::compare
|
||||
Same length on both sides
|
||||
-------------------------------------------------------------------------------
|
||||
String.tests.cpp:<line number>
|
||||
...............................................................................
|
||||
|
||||
String.tests.cpp:<line number>: PASSED:
|
||||
REQUIRE( sr1.compare(sr2) < 0 )
|
||||
with expansion:
|
||||
-1 < 0
|
||||
|
||||
String.tests.cpp:<line number>: PASSED:
|
||||
REQUIRE( sr2.compare(sr1) > 0 )
|
||||
with expansion:
|
||||
1 > 0
|
||||
|
||||
String.tests.cpp:<line number>: PASSED:
|
||||
REQUIRE( sr1.compare(sr3) == 0 )
|
||||
with expansion:
|
||||
0 == 0
|
||||
|
||||
String.tests.cpp:<line number>: PASSED:
|
||||
REQUIRE( sr3.compare(sr1) == 0 )
|
||||
with expansion:
|
||||
0 == 0
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
StringRef::compare
|
||||
Different lengths
|
||||
-------------------------------------------------------------------------------
|
||||
String.tests.cpp:<line number>
|
||||
...............................................................................
|
||||
|
||||
String.tests.cpp:<line number>: PASSED:
|
||||
REQUIRE( sr1.compare(sr2) < 0 )
|
||||
with expansion:
|
||||
-1 < 0
|
||||
|
||||
String.tests.cpp:<line number>: PASSED:
|
||||
REQUIRE( sr2.compare(sr1) > 0 )
|
||||
with expansion:
|
||||
1 > 0
|
||||
|
||||
String.tests.cpp:<line number>: PASSED:
|
||||
REQUIRE( sr1.compare(sr3) > 0 )
|
||||
with expansion:
|
||||
3 > 0
|
||||
|
||||
String.tests.cpp:<line number>: PASSED:
|
||||
REQUIRE( sr2.compare(sr3) > 0 )
|
||||
with expansion:
|
||||
3 > 0
|
||||
|
||||
String.tests.cpp:<line number>: PASSED:
|
||||
REQUIRE( sr3.compare(sr1) < 0 )
|
||||
with expansion:
|
||||
-3 < 0
|
||||
|
||||
String.tests.cpp:<line number>: 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:<line number>
|
||||
Misc.tests.cpp:<line number>: 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
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<testsuitesloose text artifact
|
||||
>
|
||||
<testsuite name="<exe-name>" errors="17" failures="129" tests="2133" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
|
||||
<testsuite name="<exe-name>" errors="17" failures="129" tests="2123" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
|
||||
<properties>
|
||||
<property name="filters" value="~[!nonportable]~[!benchmark]~[approvals] *"/>
|
||||
<property name="random-seed" value="1"/>
|
||||
@ -1196,8 +1196,6 @@ 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="StringRef::compare/Same length on both sides" time="{duration}" status="run"/>
|
||||
<testcase classname="<exe-name>.global" name="StringRef::compare/Different lengths" 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"/>
|
||||
|
@ -204,8 +204,6 @@
|
||||
<testCase name="StringRef/StringRef + StringRef" duration="{duration}"/>
|
||||
<testCase name="StringRef at compilation time/Simple constructors" duration="{duration}"/>
|
||||
<testCase name="StringRef at compilation time/UDL construction" duration="{duration}"/>
|
||||
<testCase name="StringRef::compare/Same length on both sides" duration="{duration}"/>
|
||||
<testCase name="StringRef::compare/Different lengths" duration="{duration}"/>
|
||||
</file>
|
||||
<file path="tests/<exe-name>/IntrospectiveTests/StringManip.tests.cpp">
|
||||
<testCase name="Trim strings" duration="{duration}"/>
|
||||
|
@ -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
|
||||
|
||||
|
@ -514,8 +514,6 @@ 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='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']
|
||||
|
@ -12945,95 +12945,6 @@ Message from section two
|
||||
</Section>
|
||||
<OverallResult success="true"/>
|
||||
</TestCase>
|
||||
<TestCase name="StringRef::compare" tags="[StringRef][Strings]" filename="tests/<exe-name>/IntrospectiveTests/String.tests.cpp" >
|
||||
<Section name="Same length on both sides" filename="tests/<exe-name>/IntrospectiveTests/String.tests.cpp" >
|
||||
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/IntrospectiveTests/String.tests.cpp" >
|
||||
<Original>
|
||||
sr1.compare(sr2) < 0
|
||||
</Original>
|
||||
<Expanded>
|
||||
-1 < 0
|
||||
</Expanded>
|
||||
</Expression>
|
||||
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/IntrospectiveTests/String.tests.cpp" >
|
||||
<Original>
|
||||
sr2.compare(sr1) > 0
|
||||
</Original>
|
||||
<Expanded>
|
||||
1 > 0
|
||||
</Expanded>
|
||||
</Expression>
|
||||
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/IntrospectiveTests/String.tests.cpp" >
|
||||
<Original>
|
||||
sr1.compare(sr3) == 0
|
||||
</Original>
|
||||
<Expanded>
|
||||
0 == 0
|
||||
</Expanded>
|
||||
</Expression>
|
||||
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/IntrospectiveTests/String.tests.cpp" >
|
||||
<Original>
|
||||
sr3.compare(sr1) == 0
|
||||
</Original>
|
||||
<Expanded>
|
||||
0 == 0
|
||||
</Expanded>
|
||||
</Expression>
|
||||
<OverallResults successes="4" failures="0" expectedFailures="0"/>
|
||||
</Section>
|
||||
<Section name="Different lengths" filename="tests/<exe-name>/IntrospectiveTests/String.tests.cpp" >
|
||||
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/IntrospectiveTests/String.tests.cpp" >
|
||||
<Original>
|
||||
sr1.compare(sr2) < 0
|
||||
</Original>
|
||||
<Expanded>
|
||||
-1 < 0
|
||||
</Expanded>
|
||||
</Expression>
|
||||
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/IntrospectiveTests/String.tests.cpp" >
|
||||
<Original>
|
||||
sr2.compare(sr1) > 0
|
||||
</Original>
|
||||
<Expanded>
|
||||
1 > 0
|
||||
</Expanded>
|
||||
</Expression>
|
||||
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/IntrospectiveTests/String.tests.cpp" >
|
||||
<Original>
|
||||
sr1.compare(sr3) > 0
|
||||
</Original>
|
||||
<Expanded>
|
||||
3 > 0
|
||||
</Expanded>
|
||||
</Expression>
|
||||
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/IntrospectiveTests/String.tests.cpp" >
|
||||
<Original>
|
||||
sr2.compare(sr3) > 0
|
||||
</Original>
|
||||
<Expanded>
|
||||
3 > 0
|
||||
</Expanded>
|
||||
</Expression>
|
||||
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/IntrospectiveTests/String.tests.cpp" >
|
||||
<Original>
|
||||
sr3.compare(sr1) < 0
|
||||
</Original>
|
||||
<Expanded>
|
||||
-3 < 0
|
||||
</Expanded>
|
||||
</Expression>
|
||||
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/IntrospectiveTests/String.tests.cpp" >
|
||||
<Original>
|
||||
sr3.compare(sr2) < 0
|
||||
</Original>
|
||||
<Expanded>
|
||||
-3 < 0
|
||||
</Expanded>
|
||||
</Expression>
|
||||
<OverallResults successes="6" failures="0" expectedFailures="0"/>
|
||||
</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>
|
||||
@ -20042,6 +19953,6 @@ loose text artifact
|
||||
</Section>
|
||||
<OverallResult success="true"/>
|
||||
</TestCase>
|
||||
<OverallResults successes="1964" failures="146" expectedFailures="23"/>
|
||||
<OverallResultsCases successes="278" failures="86" expectedFailures="6"/>
|
||||
<OverallResults successes="1954" failures="146" expectedFailures="23"/>
|
||||
<OverallResultsCases successes="277" failures="86" expectedFailures="6"/>
|
||||
</Catch2TestRun>
|
||||
|
@ -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") {
|
||||
|
Loading…
Reference in New Issue
Block a user