diff options
| author | Phil Nash | 2012-02-09 08:34:01 +0000 |
|---|---|---|
| committer | Phil Nash | 2012-02-09 08:34:01 +0000 |
| commit | 3fd7dc02185b1de34f6be50bc7fddb177333be0f (patch) | |
| tree | 5e3be0eeadd9921b767b76fabd919f0714314fcc /include | |
| parent | fd78e0f6df4b5d8774655e41f516e23008990d76 (diff) | |
| download | catch3-3fd7dc02185b1de34f6be50bc7fddb177333be0f.tar.gz | |
Prevent duplicate test names from being registered
If a test case with the same name as an already registered test case is registered an error is logged to cerr and the program exits (with error level 1)
Diffstat (limited to 'include')
| -rw-r--r-- | include/internal/catch_test_case_info.hpp | 9 | ||||
| -rw-r--r-- | include/internal/catch_test_case_registry_impl.hpp | 8 |
2 files changed, 10 insertions, 7 deletions
diff --git a/include/internal/catch_test_case_info.hpp b/include/internal/catch_test_case_info.hpp index e27a084d..782a3342 100644 --- a/include/internal/catch_test_case_info.hpp +++ b/include/internal/catch_test_case_info.hpp @@ -161,7 +161,7 @@ namespace Catch ) const { - return *m_test == *other.m_test && m_name == other.m_name && m_description == other.m_description; + return *m_test == *other.m_test && m_name == other.m_name; } /////////////////////////////////////////////////////////////////////// @@ -171,12 +171,7 @@ namespace Catch ) const { - if( m_name < other.m_name ) - return true; - if( m_name > other.m_name ) - return false; - - return *m_test < *other.m_test; + return m_name < other.m_name; } private: diff --git a/include/internal/catch_test_case_registry_impl.hpp b/include/internal/catch_test_case_registry_impl.hpp index ea30f234..876bdc8d 100644 --- a/include/internal/catch_test_case_registry_impl.hpp +++ b/include/internal/catch_test_case_registry_impl.hpp @@ -48,6 +48,14 @@ namespace Catch m_functions.insert( testInfo ); m_functionsInOrder.push_back( testInfo ); } + else + { + const TestCaseInfo& prev = *m_functions.find( testInfo ); + std::cerr << "error: TEST_CASE( \"" << testInfo.getName() << "\" ) already defined.\n" + << "\tFirst seen at " << prev.getFilename() << ":" << prev.getLine() << "\n" + << "\tRedefined at " << testInfo.getFilename() << ":" << testInfo.getLine() << std::endl; + exit(1); + } } /////////////////////////////////////////////////////////////////////////// |