mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-22 21:36:11 +01:00
Improved reporting from self-test and basic reporter in general
This commit is contained in:
parent
3bad3d6956
commit
7d65a8c612
@ -20,6 +20,26 @@ namespace Catch
|
||||
{
|
||||
class BasicReporter : public IReporter
|
||||
{
|
||||
struct SpanInfo
|
||||
{
|
||||
SpanInfo()
|
||||
: emitted( false )
|
||||
{}
|
||||
|
||||
SpanInfo( const std::string& spanName )
|
||||
: name( spanName ),
|
||||
emitted( false )
|
||||
{}
|
||||
|
||||
SpanInfo( const SpanInfo& other )
|
||||
: name( other.name ),
|
||||
emitted( other.emitted )
|
||||
{}
|
||||
|
||||
std::string name;
|
||||
bool emitted;
|
||||
};
|
||||
|
||||
public:
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
BasicReporter
|
||||
@ -62,7 +82,7 @@ namespace Catch
|
||||
virtual void StartTesting
|
||||
()
|
||||
{
|
||||
m_config.stream() << "[Started testing]" << std::endl;
|
||||
m_testingSpan = SpanInfo();
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
@ -71,11 +91,14 @@ namespace Catch
|
||||
std::size_t succeeded,
|
||||
std::size_t failed
|
||||
)
|
||||
{
|
||||
if( m_testingSpan.emitted )
|
||||
{
|
||||
m_config.stream() << "[Testing completed. ";
|
||||
ReportCounts( succeeded, failed );
|
||||
m_config.stream() << "]" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
virtual void StartGroup
|
||||
@ -83,8 +106,7 @@ namespace Catch
|
||||
const std::string& groupName
|
||||
)
|
||||
{
|
||||
if( !groupName.empty() )
|
||||
m_config.stream() << "[Started group: '" << groupName << "']" << std::endl;
|
||||
m_groupSpan = groupName;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
@ -95,11 +117,12 @@ namespace Catch
|
||||
std::size_t failed
|
||||
)
|
||||
{
|
||||
if( !groupName.empty() )
|
||||
if( m_groupSpan.emitted && !groupName.empty() )
|
||||
{
|
||||
m_config.stream() << "[End of group: '" << groupName << "'. ";
|
||||
ReportCounts( succeeded, failed );
|
||||
m_config.stream() << "]\n" << std::endl;
|
||||
m_groupSpan = SpanInfo();
|
||||
}
|
||||
}
|
||||
|
||||
@ -109,8 +132,7 @@ namespace Catch
|
||||
const TestCaseInfo& testInfo
|
||||
)
|
||||
{
|
||||
m_config.stream() << std::endl << "[Running: " << testInfo.getName() << "]" << std::endl;
|
||||
m_firstSectionInTestCase = true;
|
||||
m_testSpan = testInfo.getName();
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
@ -120,12 +142,7 @@ namespace Catch
|
||||
const std::string /*description*/
|
||||
)
|
||||
{
|
||||
if( m_firstSectionInTestCase )
|
||||
{
|
||||
m_config.stream() << "\n";
|
||||
m_firstSectionInTestCase = false;
|
||||
}
|
||||
m_config.stream() << "[Started section: '" << sectionName << "']" << std::endl;
|
||||
m_sectionSpan = sectionName;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
@ -135,10 +152,14 @@ namespace Catch
|
||||
std::size_t succeeded,
|
||||
std::size_t failed
|
||||
)
|
||||
{
|
||||
if( m_sectionSpan.emitted && !m_sectionSpan.name.empty() )
|
||||
{
|
||||
m_config.stream() << "[End of section: '" << sectionName << "'. ";
|
||||
ReportCounts( succeeded, failed );
|
||||
m_config.stream() << "]\n" << std::endl;
|
||||
m_sectionSpan = SpanInfo();
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
@ -150,6 +171,8 @@ namespace Catch
|
||||
if( !m_config.includeSuccessfulResults() && resultInfo.getResultType() == ResultWas::Ok )
|
||||
return;
|
||||
|
||||
StartSpansLazily();
|
||||
|
||||
if( !resultInfo.getFilename().empty() )
|
||||
m_config.stream() << resultInfo.getFilename() << "(" << resultInfo.getLine() << "): ";
|
||||
|
||||
@ -199,6 +222,8 @@ namespace Catch
|
||||
const std::string& stdOut,
|
||||
const std::string& stdErr
|
||||
)
|
||||
{
|
||||
if( m_testSpan.emitted )
|
||||
{
|
||||
if( !stdOut.empty() )
|
||||
m_config.stream() << "[stdout: " << trim( stdOut ) << "]\n";
|
||||
@ -210,10 +235,51 @@ namespace Catch
|
||||
ReportCounts( succeeded, failed );
|
||||
m_config.stream() << "]" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
private: // helpers
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
void StartSpansLazily()
|
||||
{
|
||||
if( !m_testingSpan.emitted )
|
||||
{
|
||||
m_config.stream() << "[Started testing]" << std::endl;
|
||||
m_testingSpan.emitted = true;
|
||||
}
|
||||
|
||||
if( !m_groupSpan.emitted && !m_groupSpan.name.empty() )
|
||||
{
|
||||
m_config.stream() << "[Started group: '" << m_groupSpan.name << "']" << std::endl;
|
||||
m_groupSpan.emitted = true;
|
||||
}
|
||||
|
||||
if( !m_testSpan.emitted )
|
||||
{
|
||||
m_config.stream() << std::endl << "[Running: " << m_testSpan.name << "]" << std::endl;
|
||||
m_testSpan.emitted = true;
|
||||
}
|
||||
|
||||
if( !m_sectionSpan.emitted && !m_sectionSpan.name.empty() )
|
||||
{
|
||||
if( m_firstSectionInTestCase )
|
||||
{
|
||||
m_config.stream() << "\n";
|
||||
m_firstSectionInTestCase = false;
|
||||
}
|
||||
m_config.stream() << "[Started section: '" << m_sectionSpan.name << "']" << std::endl;
|
||||
m_sectionSpan.emitted = true;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
const IReporterConfig& m_config;
|
||||
bool m_firstSectionInTestCase;
|
||||
|
||||
SpanInfo m_testingSpan;
|
||||
SpanInfo m_groupSpan;
|
||||
SpanInfo m_sectionSpan;
|
||||
SpanInfo m_testSpan;
|
||||
};
|
||||
|
||||
INTERNAL_CATCH_REGISTER_REPORTER( "basic", BasicReporter );
|
||||
|
@ -39,10 +39,14 @@ namespace Catch
|
||||
config.setReporter( "basic" );
|
||||
|
||||
std::size_t result;
|
||||
|
||||
// Scoped because Runner doesn't report EndTesting until its destructor
|
||||
{
|
||||
Runner runner( config );
|
||||
result = runner.runMatching( rawTestSpec );
|
||||
m_successes = runner.getSuccessCount();
|
||||
m_failures = runner.getFailureCount();
|
||||
}
|
||||
m_output = oss.str();
|
||||
return result;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user