mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-26 23:36:11 +01:00
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:
parent
90b2bfec3d
commit
b7ff995e89
@ -17,7 +17,7 @@ namespace Catch {
|
|||||||
struct ConsoleReporter : StreamingReporterBase {
|
struct ConsoleReporter : StreamingReporterBase {
|
||||||
ConsoleReporter( ReporterConfig const& _config )
|
ConsoleReporter( ReporterConfig const& _config )
|
||||||
: StreamingReporterBase( _config ),
|
: StreamingReporterBase( _config ),
|
||||||
m_printedCurrentSection( false ),
|
m_headerPrinted( false ),
|
||||||
m_atLeastOneTestCasePrinted( false )
|
m_atLeastOneTestCasePrinted( false )
|
||||||
{}
|
{}
|
||||||
|
|
||||||
@ -50,7 +50,7 @@ namespace Catch {
|
|||||||
}
|
}
|
||||||
|
|
||||||
virtual void sectionStarting( SectionInfo const& _sectionInfo ) {
|
virtual void sectionStarting( SectionInfo const& _sectionInfo ) {
|
||||||
m_printedCurrentSection = false;
|
m_headerPrinted = false;
|
||||||
StreamingReporterBase::sectionStarting( _sectionInfo );
|
StreamingReporterBase::sectionStarting( _sectionInfo );
|
||||||
}
|
}
|
||||||
virtual void sectionEnded( SectionStats const& _sectionStats ) {
|
virtual void sectionEnded( SectionStats const& _sectionStats ) {
|
||||||
@ -59,7 +59,7 @@ namespace Catch {
|
|||||||
TextColour colour( TextColour::ResultError );
|
TextColour colour( TextColour::ResultError );
|
||||||
stream << "\nNo assertions in section, '" << _sectionStats.sectionInfo.name << "'\n" << std::endl;
|
stream << "\nNo assertions in section, '" << _sectionStats.sectionInfo.name << "'\n" << std::endl;
|
||||||
}
|
}
|
||||||
m_printedCurrentSection = false;
|
m_headerPrinted = false;
|
||||||
StreamingReporterBase::sectionEnded( _sectionStats );
|
StreamingReporterBase::sectionEnded( _sectionStats );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,6 +71,7 @@ namespace Catch {
|
|||||||
stream << "\nNo assertions in test case, '" << _testCaseStats.testInfo.name << "'\n" << std::endl;
|
stream << "\nNo assertions in test case, '" << _testCaseStats.testInfo.name << "'\n" << std::endl;
|
||||||
}
|
}
|
||||||
StreamingReporterBase::testCaseEnded( _testCaseStats );
|
StreamingReporterBase::testCaseEnded( _testCaseStats );
|
||||||
|
m_headerPrinted = false;
|
||||||
}
|
}
|
||||||
virtual void testGroupEnded( TestGroupStats const& _testGroupStats ) {
|
virtual void testGroupEnded( TestGroupStats const& _testGroupStats ) {
|
||||||
if( !unusedGroupInfo ) {
|
if( !unusedGroupInfo ) {
|
||||||
@ -250,11 +251,11 @@ namespace Catch {
|
|||||||
lazyPrintRunInfo();
|
lazyPrintRunInfo();
|
||||||
if( unusedGroupInfo )
|
if( unusedGroupInfo )
|
||||||
lazyPrintGroupInfo();
|
lazyPrintGroupInfo();
|
||||||
if( unusedTestCaseInfo )
|
|
||||||
lazyPrintTestCaseInfo();
|
|
||||||
if( currentSectionInfo && !m_printedCurrentSection )
|
|
||||||
lazyPrintSectionInfo();
|
|
||||||
|
|
||||||
|
if( !m_headerPrinted ) {
|
||||||
|
printTestCaseAndSectionHeader();
|
||||||
|
m_headerPrinted = true;
|
||||||
|
}
|
||||||
m_atLeastOneTestCasePrinted = true;
|
m_atLeastOneTestCasePrinted = true;
|
||||||
}
|
}
|
||||||
void lazyPrintRunInfo() {
|
void lazyPrintRunInfo() {
|
||||||
@ -271,19 +272,19 @@ namespace Catch {
|
|||||||
}
|
}
|
||||||
void lazyPrintGroupInfo() {
|
void lazyPrintGroupInfo() {
|
||||||
if( !unusedGroupInfo->name.empty() && unusedGroupInfo->groupsCounts > 1 ) {
|
if( !unusedGroupInfo->name.empty() && unusedGroupInfo->groupsCounts > 1 ) {
|
||||||
printHeader( "Group: " + unusedGroupInfo->name );
|
printClosedHeader( "Group: " + unusedGroupInfo->name );
|
||||||
unusedGroupInfo.reset();
|
unusedGroupInfo.reset();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void lazyPrintTestCaseInfo() {
|
void lazyPrintTestCaseInfo() {
|
||||||
if( !currentSectionInfo ) {
|
if( !currentSectionInfo ) {
|
||||||
printHeader( unusedTestCaseInfo->name );
|
printClosedHeader( unusedTestCaseInfo->name );
|
||||||
stream << std::endl;
|
stream << std::endl;
|
||||||
// unusedTestCaseInfo.reset();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void lazyPrintSectionInfo() {
|
void printTestCaseAndSectionHeader() {
|
||||||
|
printOpenHeader( unusedTestCaseInfo->name );
|
||||||
|
if( currentSectionInfo ) {
|
||||||
std::vector<ThreadedSectionInfo*> sections;
|
std::vector<ThreadedSectionInfo*> sections;
|
||||||
for( ThreadedSectionInfo* section = currentSectionInfo.get();
|
for( ThreadedSectionInfo* section = currentSectionInfo.get();
|
||||||
section;
|
section;
|
||||||
@ -292,21 +293,21 @@ namespace Catch {
|
|||||||
|
|
||||||
// Sections
|
// Sections
|
||||||
if( !sections.empty() ) {
|
if( !sections.empty() ) {
|
||||||
printHeader( unusedTestCaseInfo->name, false );
|
|
||||||
|
|
||||||
typedef std::vector<ThreadedSectionInfo*>::const_reverse_iterator It;
|
typedef std::vector<ThreadedSectionInfo*>::const_reverse_iterator It;
|
||||||
for( It it = sections.rbegin(), itEnd = sections.rend(); it != itEnd; ++it )
|
for( It it = sections.rbegin(), itEnd = sections.rend(); it != itEnd; ++it )
|
||||||
stream << " " << (*it)->name << "\n";
|
stream << " " << (*it)->name << "\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
stream << getDots() << "\n" << std::endl;
|
stream << getDots() << "\n" << std::endl;
|
||||||
}
|
}
|
||||||
m_printedCurrentSection = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
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"
|
stream << getDashes() << "\n"
|
||||||
<< _name << "\n";
|
<< _name << "\n";
|
||||||
if( closed )
|
|
||||||
stream << getDots() << "\n";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void printTotals( const Totals& totals ) {
|
void printTotals( const Totals& totals ) {
|
||||||
@ -376,7 +377,7 @@ namespace Catch {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool m_printedCurrentSection;
|
bool m_headerPrinted;
|
||||||
bool m_atLeastOneTestCasePrinted;
|
bool m_atLeastOneTestCasePrinted;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -314,3 +314,62 @@ TEST_CASE( "./succeeding/SafeBool", "Objects that evaluated in boolean contexts
|
|||||||
CHECK( !False );
|
CHECK( !False );
|
||||||
CHECK_FALSE( 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 );
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user