Tidied up some loose ends with reporting test cases and sections (now handles them as a single block).

This should fixes an issue where sections not being printed when they should be (and reverses a workaround where they were being printed too much)
This commit is contained in:
Phil Nash 2013-03-06 20:40:16 +01:00
parent 90b2bfec3d
commit b7ff995e89
3 changed files with 359 additions and 1492 deletions

View File

@ -17,7 +17,7 @@ namespace Catch {
struct ConsoleReporter : StreamingReporterBase {
ConsoleReporter( ReporterConfig const& _config )
: StreamingReporterBase( _config ),
m_printedCurrentSection( false ),
m_headerPrinted( false ),
m_atLeastOneTestCasePrinted( false )
{}
@ -50,7 +50,7 @@ namespace Catch {
}
virtual void sectionStarting( SectionInfo const& _sectionInfo ) {
m_printedCurrentSection = false;
m_headerPrinted = false;
StreamingReporterBase::sectionStarting( _sectionInfo );
}
virtual void sectionEnded( SectionStats const& _sectionStats ) {
@ -59,7 +59,7 @@ namespace Catch {
TextColour colour( TextColour::ResultError );
stream << "\nNo assertions in section, '" << _sectionStats.sectionInfo.name << "'\n" << std::endl;
}
m_printedCurrentSection = false;
m_headerPrinted = false;
StreamingReporterBase::sectionEnded( _sectionStats );
}
@ -71,6 +71,7 @@ namespace Catch {
stream << "\nNo assertions in test case, '" << _testCaseStats.testInfo.name << "'\n" << std::endl;
}
StreamingReporterBase::testCaseEnded( _testCaseStats );
m_headerPrinted = false;
}
virtual void testGroupEnded( TestGroupStats const& _testGroupStats ) {
if( !unusedGroupInfo ) {
@ -250,11 +251,11 @@ namespace Catch {
lazyPrintRunInfo();
if( unusedGroupInfo )
lazyPrintGroupInfo();
if( unusedTestCaseInfo )
lazyPrintTestCaseInfo();
if( currentSectionInfo && !m_printedCurrentSection )
lazyPrintSectionInfo();
if( !m_headerPrinted ) {
printTestCaseAndSectionHeader();
m_headerPrinted = true;
}
m_atLeastOneTestCasePrinted = true;
}
void lazyPrintRunInfo() {
@ -271,42 +272,42 @@ namespace Catch {
}
void lazyPrintGroupInfo() {
if( !unusedGroupInfo->name.empty() && unusedGroupInfo->groupsCounts > 1 ) {
printHeader( "Group: " + unusedGroupInfo->name );
printClosedHeader( "Group: " + unusedGroupInfo->name );
unusedGroupInfo.reset();
}
}
void lazyPrintTestCaseInfo() {
if( !currentSectionInfo ) {
printHeader( unusedTestCaseInfo->name );
printClosedHeader( unusedTestCaseInfo->name );
stream << std::endl;
// unusedTestCaseInfo.reset();
}
}
void lazyPrintSectionInfo() {
std::vector<ThreadedSectionInfo*> sections;
for( ThreadedSectionInfo* section = currentSectionInfo.get();
section;
section = section->parent )
sections.push_back( section );
// Sections
if( !sections.empty() ) {
printHeader( unusedTestCaseInfo->name, false );
void printTestCaseAndSectionHeader() {
printOpenHeader( unusedTestCaseInfo->name );
if( currentSectionInfo ) {
std::vector<ThreadedSectionInfo*> sections;
for( ThreadedSectionInfo* section = currentSectionInfo.get();
section;
section = section->parent )
sections.push_back( section );
typedef std::vector<ThreadedSectionInfo*>::const_reverse_iterator It;
for( It it = sections.rbegin(), itEnd = sections.rend(); it != itEnd; ++it )
stream << " " << (*it)->name << "\n";
stream << getDots() << "\n" << std::endl;
// Sections
if( !sections.empty() ) {
typedef std::vector<ThreadedSectionInfo*>::const_reverse_iterator It;
for( It it = sections.rbegin(), itEnd = sections.rend(); it != itEnd; ++it )
stream << " " << (*it)->name << "\n";
}
}
m_printedCurrentSection = true;
stream << getDots() << "\n" << std::endl;
}
void printHeader( std::string const& _name, bool closed = true ) {
void printClosedHeader( std::string const& _name ) {
printOpenHeader( _name );
stream << getDots() << "\n";
}
void printOpenHeader( std::string const& _name ) {
stream << getDashes() << "\n"
<< _name << "\n";
if( closed )
stream << getDots() << "\n";
}
void printTotals( const Totals& totals ) {
@ -376,7 +377,7 @@ namespace Catch {
}
private:
bool m_printedCurrentSection;
bool m_headerPrinted;
bool m_atLeastOneTestCasePrinted;
};

File diff suppressed because it is too large Load Diff

View File

@ -314,3 +314,62 @@ TEST_CASE( "./succeeding/SafeBool", "Objects that evaluated in boolean contexts
CHECK( !False );
CHECK_FALSE( False );
}
TEST_CASE( "Assertions then sections", "" )
{
// This was causing a failure due to the way the console reporter was handling
// the current section
REQUIRE( Catch::isTrue( true ) );
SECTION( "A section", "" )
{
REQUIRE( Catch::isTrue( true ) );
SECTION( "Another section", "" )
{
REQUIRE( Catch::isTrue( true ) );
}
SECTION( "Another other section", "" )
{
REQUIRE( Catch::isTrue( true ) );
}
}
}
inline void sort( std::vector<int>& v ) {
std::sort( v.begin(), v.end() );
}
TEST_CASE( "sort", "" ) {
std::vector<int> v;
v.push_back( 3 );
v.push_back( 2 );
v.push_back( 4 );
std::vector<int> sorted;
sorted.push_back( 2 );
sorted.push_back( 3 );
sorted.push_back( 4 );
sort( v );
REQUIRE( v == sorted );
SECTION( "already sorted", "" ) {
sort( v );
REQUIRE( v == sorted );
}
SECTION( "reverse sorted", "" ) {
std::reverse( v.begin(), v.end() );
REQUIRE( v != sorted );
sort( v );
REQUIRE( v == sorted );
}
}