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)
This commit is contained in:
1 parent
fd78e0f6df
commit
3fd7dc0218
3 files changed
+22
-7
No files matched your search
@@ -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:
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Reference in new issue
Block a user