report file/ line of section of unexpected exception is thrown

This commit is contained in:
Phil Nash 2011-04-21 19:43:55 +01:00
parent 81e42ce139
commit 02e597c2cc
4 changed files with 30 additions and 7 deletions

View File

@ -109,3 +109,14 @@ TEST_CASE_NORETURN( "./failing/exceptions/custom/double", "Unexpected custom exc
{ {
throw double( 3.14 ); throw double( 3.14 );
} }
TEST_CASE( "./failing/exceptions/in-section", "Exceptions thrown from sections report file/ line or section" )
{
SECTION( "the section", "" )
{
SECTION( "the section2", "" )
{
throw std::domain_error( "Exception from section" );
}
}
}

View File

@ -33,6 +33,8 @@ namespace Catch
virtual bool sectionStarted virtual bool sectionStarted
( const std::string& name, ( const std::string& name,
const std::string& description, const std::string& description,
const std::string& filename,
std::size_t line,
std::size_t& successes, std::size_t& successes,
std::size_t& failures std::size_t& failures
) = 0; ) = 0;

View File

@ -360,6 +360,8 @@ namespace Catch
{ {
do do
{ {
m_currentResult.setFileAndLine( m_runningTest->getTestCaseInfo().getFilename(),
m_runningTest->getTestCaseInfo().getLine() );
runCurrentTest( redirectedCout, redirectedCerr ); runCurrentTest( redirectedCout, redirectedCerr );
} }
while( m_runningTest->hasUntestedSections() ); while( m_runningTest->hasUntestedSections() );
@ -459,14 +461,20 @@ namespace Catch
virtual bool sectionStarted virtual bool sectionStarted
( (
const std::string& name, const std::string& name,
const std::string& description, const std::string& description,
const std::string& filename,
std::size_t line,
std::size_t& successes, std::size_t& successes,
std::size_t& failures std::size_t& failures
) )
{ {
if( !m_runningTest->addSection( name ) ) std::ostringstream oss;
oss << filename << ":" << line;
if( !m_runningTest->addSection( oss.str() ) )
return false; return false;
m_currentResult.setFileAndLine( filename, line );
m_reporter->StartSection( name, description ); m_reporter->StartSection( name, description );
successes = m_successes; successes = m_successes;
failures = m_failures; failures = m_failures;
@ -553,8 +561,6 @@ namespace Catch
m_runningTest->reset(); m_runningTest->reset();
StreamRedirect coutRedir( std::cout, redirectedCout ); StreamRedirect coutRedir( std::cout, redirectedCout );
StreamRedirect cerrRedir( std::cerr, redirectedCerr ); StreamRedirect cerrRedir( std::cerr, redirectedCerr );
m_currentResult.setFileAndLine( m_runningTest->getTestCaseInfo().getFilename(),
m_runningTest->getTestCaseInfo().getLine() );
m_runningTest->getTestCaseInfo().invoke(); m_runningTest->getTestCaseInfo().invoke();
m_runningTest->ranToCompletion(); m_runningTest->ranToCompletion();
} }

View File

@ -26,10 +26,12 @@ namespace Catch
Section Section
( (
const std::string& name, const std::string& name,
const std::string& description const std::string& description,
const std::string& filename,
std::size_t line
) )
: m_name( name ), : m_name( name ),
m_sectionIncluded( Hub::getResultCapture().sectionStarted( name, description, m_successes, m_failures ) ) m_sectionIncluded( Hub::getResultCapture().sectionStarted( name, description, filename, line, m_successes, m_failures ) )
{ {
} }
@ -50,6 +52,7 @@ namespace Catch
} }
private: private:
std::string m_name; std::string m_name;
std::size_t m_successes; std::size_t m_successes;
std::size_t m_failures; std::size_t m_failures;
@ -58,6 +61,7 @@ namespace Catch
} // end namespace Catch } // end namespace Catch
#define INTERNAL_CATCH_SECTION( name, desc ) if( Catch::Section INTERNAL_CATCH_UNIQUE_NAME( catch_internal_Section ) = Catch::Section( name, desc ) ) #define INTERNAL_CATCH_SECTION( name, desc ) \
if( Catch::Section INTERNAL_CATCH_UNIQUE_NAME( catch_internal_Section ) = Catch::Section( name, desc, __FILE__, __LINE__ ) )
#endif // TWOBLUECUBES_CATCH_SECTION_HPP_INCLUDED #endif // TWOBLUECUBES_CATCH_SECTION_HPP_INCLUDED