mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-22 13:26:10 +01:00
report file/ line of section of unexpected exception is thrown
This commit is contained in:
parent
81e42ce139
commit
02e597c2cc
@ -109,3 +109,14 @@ TEST_CASE_NORETURN( "./failing/exceptions/custom/double", "Unexpected custom exc
|
||||
{
|
||||
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" );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -33,6 +33,8 @@ namespace Catch
|
||||
virtual bool sectionStarted
|
||||
( const std::string& name,
|
||||
const std::string& description,
|
||||
const std::string& filename,
|
||||
std::size_t line,
|
||||
std::size_t& successes,
|
||||
std::size_t& failures
|
||||
) = 0;
|
||||
|
@ -360,6 +360,8 @@ namespace Catch
|
||||
{
|
||||
do
|
||||
{
|
||||
m_currentResult.setFileAndLine( m_runningTest->getTestCaseInfo().getFilename(),
|
||||
m_runningTest->getTestCaseInfo().getLine() );
|
||||
runCurrentTest( redirectedCout, redirectedCerr );
|
||||
}
|
||||
while( m_runningTest->hasUntestedSections() );
|
||||
@ -460,13 +462,19 @@ namespace Catch
|
||||
(
|
||||
const std::string& name,
|
||||
const std::string& description,
|
||||
const std::string& filename,
|
||||
std::size_t line,
|
||||
std::size_t& successes,
|
||||
std::size_t& failures
|
||||
)
|
||||
{
|
||||
if( !m_runningTest->addSection( name ) )
|
||||
std::ostringstream oss;
|
||||
oss << filename << ":" << line;
|
||||
|
||||
if( !m_runningTest->addSection( oss.str() ) )
|
||||
return false;
|
||||
|
||||
m_currentResult.setFileAndLine( filename, line );
|
||||
m_reporter->StartSection( name, description );
|
||||
successes = m_successes;
|
||||
failures = m_failures;
|
||||
@ -553,8 +561,6 @@ namespace Catch
|
||||
m_runningTest->reset();
|
||||
StreamRedirect coutRedir( std::cout, redirectedCout );
|
||||
StreamRedirect cerrRedir( std::cerr, redirectedCerr );
|
||||
m_currentResult.setFileAndLine( m_runningTest->getTestCaseInfo().getFilename(),
|
||||
m_runningTest->getTestCaseInfo().getLine() );
|
||||
m_runningTest->getTestCaseInfo().invoke();
|
||||
m_runningTest->ranToCompletion();
|
||||
}
|
||||
|
@ -26,10 +26,12 @@ namespace Catch
|
||||
Section
|
||||
(
|
||||
const std::string& name,
|
||||
const std::string& description
|
||||
const std::string& description,
|
||||
const std::string& filename,
|
||||
std::size_t line
|
||||
)
|
||||
: 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:
|
||||
|
||||
std::string m_name;
|
||||
std::size_t m_successes;
|
||||
std::size_t m_failures;
|
||||
@ -58,6 +61,7 @@ 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
|
||||
|
Loading…
Reference in New Issue
Block a user