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

summaryrefslogtreecommitdiffhomepage
path: root/src/catch2/catch_test_case_info.cpp
diff options
context:
space:
mode:
authorMartin Hořeňovský2021-09-25 21:37:03 +0200
committerMartin Hořeňovský2021-09-25 21:37:03 +0200
commitfb4153e05e430921574d79d868ebc44dd9528629 (patch)
tree80084812f69e65567cdc29de6388b81b72debcfe /src/catch2/catch_test_case_info.cpp
parente8e28ba40151dff22992c95d367cc75967bc07d4 (diff)
downloadcatch3-fb4153e05e430921574d79d868ebc44dd9528629.tar.gz
Multiple tests can have same name as long as their tags differ
This change also changes it so that test case macros using a class name can have same name **and** tags as long as the used class name differs. Closes #1915 Closes #1999
Diffstat (limited to 'src/catch2/catch_test_case_info.cpp')
-rw-r--r--src/catch2/catch_test_case_info.cpp26
1 files changed, 17 insertions, 9 deletions
diff --git a/src/catch2/catch_test_case_info.cpp b/src/catch2/catch_test_case_info.cpp
index 6a60f928..7dab6ae4 100644
--- a/src/catch2/catch_test_case_info.cpp
+++ b/src/catch2/catch_test_case_info.cpp
@@ -101,6 +101,10 @@ namespace Catch {
const size_t extras = 3 + 3;
return extractFilenamePart(filepath).size() + extras;
}
+ } // end unnamed namespace
+
+ bool operator<( Tag const& lhs, Tag const& rhs ) {
+ return lhs.original < rhs.original;
}
Detail::unique_ptr<TestCaseInfo>
@@ -228,15 +232,19 @@ namespace Catch {
StringRef(backingLCaseTags.c_str() + backingStart, backingEnd - backingStart));
}
-
- bool TestCaseHandle::operator == ( TestCaseHandle const& rhs ) const {
- return m_invoker == rhs.m_invoker
- && m_info->name == rhs.m_info->name
- && m_info->className == rhs.m_info->className;
- }
-
- bool TestCaseHandle::operator < ( TestCaseHandle const& rhs ) const {
- return m_info->name < rhs.m_info->name;
+ bool operator<( TestCaseInfo const& lhs, TestCaseInfo const& rhs ) {
+ // We want to avoid redoing the string comparisons multiple times,
+ // so we store the result of a three-way comparison before using
+ // it in the actual comparison logic.
+ const auto cmpName = lhs.name.compare( rhs.name );
+ if ( cmpName != 0 ) {
+ return cmpName < 0;
+ }
+ const auto cmpClassName = lhs.className.compare( rhs.className );
+ if ( cmpClassName != 0 ) {
+ return cmpClassName < 0;
+ }
+ return lhs.tags < rhs.tags;
}
TestCaseInfo const& TestCaseHandle::getTestCaseInfo() const {