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:
Phil Nash
2012-02-15 08:20:06 +00:00
parent 8d24143827
commit 7b449f7abe
11 changed files with 418 additions and 40 deletions

View File

@@ -15,6 +15,8 @@
#include <string>
#include <stdexcept>
#include "catch_self_test.hpp"
namespace
{
ATTRIBUTE_NORETURN
@@ -114,9 +116,32 @@ TEST_CASE( "./failing/exceptions/in-section", "Exceptions thrown from sections r
{
SECTION( "the section", "" )
{
SECTION( "the section2", "" )
CATCH_REGISTER_LINE_INFO( "the section2" ) SECTION( "the section2", "" )
{
throw std::domain_error( "Exception from section" );
}
}
}
TEST_CASE( "./succeeding/exceptions/error messages", "The error messages produced by exceptions caught by Catch matched the expected form" )
{
Catch::EmbeddedRunner runner;
SECTION( "custom, unexpected", "" )
{
runner.runMatching( "./failing/exceptions/custom" );
INFO( runner.getOutput() );
CHECK( runner.getOutput().find( "Unexpected exception" ) != std::string::npos );
CHECK( runner.getOutput().find( "custom exception" ) != std::string::npos );
}
SECTION( "in section", "" )
{
runner.runMatching( "./failing/exceptions/in-section" );
INFO( runner.getOutput() );
CHECK( runner.getOutput().find( "Unexpected exception" ) != std::string::npos );
CHECK( runner.getOutput().find( "Exception from section" ) != std::string::npos );
CHECK( runner.getOutput().find( CATCH_GET_LINE_INFO( "the section2" ) ) != std::string::npos );
}
}