diff options
| author | Martin Hořeňovský | 2021-09-25 21:37:03 +0200 |
|---|---|---|
| committer | Martin Hořeňovský | 2021-09-25 21:37:03 +0200 |
| commit | fb4153e05e430921574d79d868ebc44dd9528629 (patch) | |
| tree | 80084812f69e65567cdc29de6388b81b72debcfe /src/catch2/internal | |
| parent | e8e28ba40151dff22992c95d367cc75967bc07d4 (diff) | |
| download | catch3-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/internal')
| -rw-r--r-- | src/catch2/internal/catch_test_case_registry_impl.cpp | 46 |
1 files changed, 35 insertions, 11 deletions
diff --git a/src/catch2/internal/catch_test_case_registry_impl.cpp b/src/catch2/internal/catch_test_case_registry_impl.cpp index 318156c4..dd1744a7 100644 --- a/src/catch2/internal/catch_test_case_registry_impl.cpp +++ b/src/catch2/internal/catch_test_case_registry_impl.cpp @@ -54,20 +54,36 @@ namespace { case TestRunOrder::LexicographicallySorted: { std::vector<TestCaseHandle> sorted = unsortedTestCases; - std::sort(sorted.begin(), sorted.end()); + std::sort( + sorted.begin(), + sorted.end(), + []( TestCaseHandle const& lhs, TestCaseHandle const& rhs ) { + return lhs.getTestCaseInfo() < rhs.getTestCaseInfo(); + } + ); return sorted; } case TestRunOrder::Randomized: { seedRng(config); + using TestWithHash = std::pair<TestHasher::hash_t, TestCaseHandle>; + TestHasher h{ config.rngSeed() }; - std::vector<std::pair<TestHasher::hash_t, TestCaseHandle>> indexed_tests; + std::vector<TestWithHash> indexed_tests; indexed_tests.reserve(unsortedTestCases.size()); for (auto const& handle : unsortedTestCases) { indexed_tests.emplace_back(h(handle.getTestCaseInfo()), handle); } - std::sort(indexed_tests.begin(), indexed_tests.end()); + std::sort( indexed_tests.begin(), + indexed_tests.end(), + []( TestWithHash const& lhs, TestWithHash const& rhs ) { + if ( lhs.first == rhs.first ) { + return lhs.second.getTestCaseInfo() < + rhs.second.getTestCaseInfo(); + } + return lhs.first < rhs.first; + } ); std::vector<TestCaseHandle> randomized; randomized.reserve(indexed_tests.size()); @@ -91,14 +107,22 @@ namespace { return testSpec.matches( testCase.getTestCaseInfo() ) && isThrowSafe( testCase, config ); } - void enforceNoDuplicateTestCases( std::vector<TestCaseHandle> const& functions ) { - std::set<TestCaseHandle> seenFunctions; - for( auto const& function : functions ) { - auto prev = seenFunctions.insert( function ); - CATCH_ENFORCE( prev.second, - "error: TEST_CASE( \"" << function.getTestCaseInfo().name << "\" ) already defined.\n" - << "\tFirst seen at " << prev.first->getTestCaseInfo().lineInfo << "\n" - << "\tRedefined at " << function.getTestCaseInfo().lineInfo ); + void + enforceNoDuplicateTestCases( std::vector<TestCaseHandle> const& tests ) { + auto testInfoCmp = []( TestCaseInfo const* lhs, + TestCaseInfo const* rhs ) { + return *lhs < *rhs; + }; + std::set<TestCaseInfo const*, decltype(testInfoCmp)> seenTests(testInfoCmp); + for ( auto const& test : tests ) { + const auto infoPtr = &test.getTestCaseInfo(); + const auto prev = seenTests.insert( infoPtr ); + CATCH_ENFORCE( + prev.second, + "error: test case \"" << infoPtr->name << "\", with tags \"" + << infoPtr->tagsAsString() << "\" already defined.\n" + << "\tFirst seen at " << ( *prev.first )->lineInfo << "\n" + << "\tRedefined at " << infoPtr->lineInfo ); } } |