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
|
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:
|
public:
|
||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
BasicReporter
|
BasicReporter
|
||||||
@ -62,7 +82,7 @@ namespace Catch
|
|||||||
virtual void StartTesting
|
virtual void StartTesting
|
||||||
()
|
()
|
||||||
{
|
{
|
||||||
m_config.stream() << "[Started testing]" << std::endl;
|
m_testingSpan = SpanInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
@ -72,9 +92,12 @@ namespace Catch
|
|||||||
std::size_t failed
|
std::size_t failed
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
m_config.stream() << "[Testing completed. ";
|
if( m_testingSpan.emitted )
|
||||||
ReportCounts( succeeded, failed );
|
{
|
||||||
m_config.stream() << "]" << std::endl;
|
m_config.stream() << "[Testing completed. ";
|
||||||
|
ReportCounts( succeeded, failed );
|
||||||
|
m_config.stream() << "]" << std::endl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
@ -83,8 +106,7 @@ namespace Catch
|
|||||||
const std::string& groupName
|
const std::string& groupName
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
if( !groupName.empty() )
|
m_groupSpan = groupName;
|
||||||
m_config.stream() << "[Started group: '" << groupName << "']" << std::endl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
@ -95,11 +117,12 @@ namespace Catch
|
|||||||
std::size_t failed
|
std::size_t failed
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
if( !groupName.empty() )
|
if( m_groupSpan.emitted && !groupName.empty() )
|
||||||
{
|
{
|
||||||
m_config.stream() << "[End of group: '" << groupName << "'. ";
|
m_config.stream() << "[End of group: '" << groupName << "'. ";
|
||||||
ReportCounts( succeeded, failed );
|
ReportCounts( succeeded, failed );
|
||||||
m_config.stream() << "]\n" << std::endl;
|
m_config.stream() << "]\n" << std::endl;
|
||||||
|
m_groupSpan = SpanInfo();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -109,8 +132,7 @@ namespace Catch
|
|||||||
const TestCaseInfo& testInfo
|
const TestCaseInfo& testInfo
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
m_config.stream() << std::endl << "[Running: " << testInfo.getName() << "]" << std::endl;
|
m_testSpan = testInfo.getName();
|
||||||
m_firstSectionInTestCase = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
@ -120,12 +142,7 @@ namespace Catch
|
|||||||
const std::string /*description*/
|
const std::string /*description*/
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
if( m_firstSectionInTestCase )
|
m_sectionSpan = sectionName;
|
||||||
{
|
|
||||||
m_config.stream() << "\n";
|
|
||||||
m_firstSectionInTestCase = false;
|
|
||||||
}
|
|
||||||
m_config.stream() << "[Started section: '" << sectionName << "']" << std::endl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
@ -136,9 +153,13 @@ namespace Catch
|
|||||||
std::size_t failed
|
std::size_t failed
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
m_config.stream() << "[End of section: '" << sectionName << "'. ";
|
if( m_sectionSpan.emitted && !m_sectionSpan.name.empty() )
|
||||||
ReportCounts( succeeded, failed );
|
{
|
||||||
m_config.stream() << "]\n" << std::endl;
|
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 )
|
if( !m_config.includeSuccessfulResults() && resultInfo.getResultType() == ResultWas::Ok )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
StartSpansLazily();
|
||||||
|
|
||||||
if( !resultInfo.getFilename().empty() )
|
if( !resultInfo.getFilename().empty() )
|
||||||
m_config.stream() << resultInfo.getFilename() << "(" << resultInfo.getLine() << "): ";
|
m_config.stream() << resultInfo.getFilename() << "(" << resultInfo.getLine() << "): ";
|
||||||
|
|
||||||
@ -200,20 +223,63 @@ namespace Catch
|
|||||||
const std::string& stdErr
|
const std::string& stdErr
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
if( !stdOut.empty() )
|
if( m_testSpan.emitted )
|
||||||
m_config.stream() << "[stdout: " << trim( stdOut ) << "]\n";
|
{
|
||||||
|
if( !stdOut.empty() )
|
||||||
|
m_config.stream() << "[stdout: " << trim( stdOut ) << "]\n";
|
||||||
|
|
||||||
if( !stdErr.empty() )
|
if( !stdErr.empty() )
|
||||||
m_config.stream() << "[stderr: " << trim( stdErr ) << "]\n";
|
m_config.stream() << "[stderr: " << trim( stdErr ) << "]\n";
|
||||||
|
|
||||||
m_config.stream() << "[Finished: " << testInfo.getName() << " ";
|
m_config.stream() << "[Finished: " << testInfo.getName() << " ";
|
||||||
ReportCounts( succeeded, failed );
|
ReportCounts( succeeded, failed );
|
||||||
m_config.stream() << "]" << std::endl;
|
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:
|
private:
|
||||||
const IReporterConfig& m_config;
|
const IReporterConfig& m_config;
|
||||||
bool m_firstSectionInTestCase;
|
bool m_firstSectionInTestCase;
|
||||||
|
|
||||||
|
SpanInfo m_testingSpan;
|
||||||
|
SpanInfo m_groupSpan;
|
||||||
|
SpanInfo m_sectionSpan;
|
||||||
|
SpanInfo m_testSpan;
|
||||||
};
|
};
|
||||||
|
|
||||||
INTERNAL_CATCH_REGISTER_REPORTER( "basic", BasicReporter );
|
INTERNAL_CATCH_REGISTER_REPORTER( "basic", BasicReporter );
|
||||||
|
@ -39,10 +39,14 @@ namespace Catch
|
|||||||
config.setReporter( "basic" );
|
config.setReporter( "basic" );
|
||||||
|
|
||||||
std::size_t result;
|
std::size_t result;
|
||||||
Runner runner( config );
|
|
||||||
result = runner.runMatching( rawTestSpec );
|
// Scoped because Runner doesn't report EndTesting until its destructor
|
||||||
m_successes = runner.getSuccessCount();
|
{
|
||||||
m_failures = runner.getFailureCount();
|
Runner runner( config );
|
||||||
|
result = runner.runMatching( rawTestSpec );
|
||||||
|
m_successes = runner.getSuccessCount();
|
||||||
|
m_failures = runner.getFailureCount();
|
||||||
|
}
|
||||||
m_output = oss.str();
|
m_output = oss.str();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user