mirror of
https://github.com/catchorg/Catch2.git
synced 2025-08-01 12:55:40 +02:00
Ability to register line# for testing
Factored file/ line storage and formatting into common class. Used in a static registry so failure messages can be asserted to have the file/ line in.
This commit is contained in:
@@ -80,11 +80,36 @@ namespace Catch
|
||||
std::for_each( container.begin(), container.end(), function );
|
||||
}
|
||||
|
||||
struct SourceLineInfo
|
||||
{
|
||||
SourceLineInfo
|
||||
(
|
||||
const std::string& file,
|
||||
std::size_t line
|
||||
)
|
||||
: file( file ),
|
||||
line( line )
|
||||
{}
|
||||
|
||||
std::string file;
|
||||
std::size_t line;
|
||||
};
|
||||
|
||||
inline std::ostream& operator << ( std::ostream& os, const SourceLineInfo& info )
|
||||
{
|
||||
#ifndef __GNUG__
|
||||
os << info.file << "(" << info.line << "): ";
|
||||
#else
|
||||
os << info.file << ":" << info.line << ": ";
|
||||
#endif
|
||||
return os;
|
||||
}
|
||||
|
||||
ATTRIBUTE_NORETURN
|
||||
inline void throwLogicError( const std::string& message, const std::string& file, long line )
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << "Internal Catch error: '" << message << "' at: " << file << "(" << line << ")";
|
||||
oss << "Internal Catch error: '" << message << "' at: " << SourceLineInfo( file, line );
|
||||
throw std::logic_error( oss.str() );
|
||||
}
|
||||
}
|
||||
|
@@ -487,7 +487,7 @@ namespace Catch
|
||||
)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << name << "@" << filename << ":" << line;
|
||||
oss << name << "@" << SourceLineInfo( filename, line );
|
||||
|
||||
if( !m_runningTest->addSection( oss.str() ) )
|
||||
return false;
|
||||
|
@@ -52,8 +52,8 @@ namespace Catch
|
||||
{
|
||||
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;
|
||||
<< "\tFirst seen at " << SourceLineInfo( prev.getFilename(), prev.getLine() ) << "\n"
|
||||
<< "\tRedefined at " << SourceLineInfo( testInfo.getFilename(), testInfo.getLine() ) << std::endl;
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user