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

summaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorPhil Nash2012-02-15 08:20:06 +0000
committerPhil Nash2012-02-15 08:20:06 +0000
commit7b449f7abe1e398ce28441293b609fd891c8df2f (patch)
treea0631a780c740f83b1f8e200877288134aa0cc64 /include
parent8d241438279e21f2c61ba61d705f05e9499904aa (diff)
downloadcatch3-7b449f7abe1e398ce28441293b609fd891c8df2f.tar.gz
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.
Diffstat (limited to 'include')
-rw-r--r--include/internal/catch_common.h27
-rw-r--r--include/internal/catch_runner_impl.hpp2
-rw-r--r--include/internal/catch_test_case_registry_impl.hpp4
-rw-r--r--include/reporters/catch_reporter_basic.hpp6
-rw-r--r--include/reporters/catch_reporter_junit.hpp2
5 files changed, 31 insertions, 10 deletions
diff --git a/include/internal/catch_common.h b/include/internal/catch_common.h
index ea2c53f0..48ce4a5b 100644
--- a/include/internal/catch_common.h
+++ b/include/internal/catch_common.h
@@ -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() );
}
}
diff --git a/include/internal/catch_runner_impl.hpp b/include/internal/catch_runner_impl.hpp
index 17ef47fe..00bd0a4f 100644
--- a/include/internal/catch_runner_impl.hpp
+++ b/include/internal/catch_runner_impl.hpp
@@ -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;
diff --git a/include/internal/catch_test_case_registry_impl.hpp b/include/internal/catch_test_case_registry_impl.hpp
index 876bdc8d..666e5963 100644
--- a/include/internal/catch_test_case_registry_impl.hpp
+++ b/include/internal/catch_test_case_registry_impl.hpp
@@ -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);
}
}
diff --git a/include/reporters/catch_reporter_basic.hpp b/include/reporters/catch_reporter_basic.hpp
index 1a370464..c55f4f01 100644
--- a/include/reporters/catch_reporter_basic.hpp
+++ b/include/reporters/catch_reporter_basic.hpp
@@ -174,11 +174,7 @@ namespace Catch
StartSpansLazily();
if( !resultInfo.getFilename().empty() )
-#ifndef __GNUG__
- m_config.stream() << resultInfo.getFilename() << "(" << resultInfo.getLine() << "): ";
-#else
- m_config.stream() << resultInfo.getFilename() << ":" << resultInfo.getLine() << ": ";
-#endif
+ m_config.stream() << SourceLineInfo( resultInfo.getFilename(), resultInfo.getLine() );
if( resultInfo.hasExpression() )
{
diff --git a/include/reporters/catch_reporter_junit.hpp b/include/reporters/catch_reporter_junit.hpp
index b281fed0..8be63a94 100644
--- a/include/reporters/catch_reporter_junit.hpp
+++ b/include/reporters/catch_reporter_junit.hpp
@@ -129,7 +129,7 @@ namespace Catch
{
oss << resultInfo.getMessage() << " at ";
}
- oss << resultInfo.getFilename() << ":" << resultInfo.getLine();
+ oss << SourceLineInfo( resultInfo.getFilename(), resultInfo.getLine() );
stats.m_content = oss.str();
stats.m_message = resultInfo.getExpandedExpression();
stats.m_resultType = resultInfo.getTestMacroName();