mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-26 15:26:11 +01:00
Integrated new section tracker.
- also pass extra section to reporter - one for each test case - ignore it in headers (this is so we know a test case has restarted) - significant effect on regression test due to change of ordering of sections - fixes infinite loop issue
This commit is contained in:
parent
6a484fdb02
commit
9aff9aa328
@ -34,12 +34,18 @@ namespace Catch {
|
|||||||
nullableValue = new( storage ) T( *_other );
|
nullableValue = new( storage ) T( *_other );
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
Option& operator = ( T const& _value ) {
|
||||||
|
reset();
|
||||||
|
nullableValue = new( storage ) T( _value );
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
void reset() {
|
void reset() {
|
||||||
if( nullableValue )
|
if( nullableValue )
|
||||||
nullableValue->~T();
|
nullableValue->~T();
|
||||||
nullableValue = NULL;
|
nullableValue = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
T& operator*() { return *nullableValue; }
|
T& operator*() { return *nullableValue; }
|
||||||
T const& operator*() const { return *nullableValue; }
|
T const& operator*() const { return *nullableValue; }
|
||||||
T* operator->() { return nullableValue; }
|
T* operator->() { return nullableValue; }
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
#include "catch_totals.hpp"
|
#include "catch_totals.hpp"
|
||||||
#include "catch_running_test.hpp"
|
#include "catch_running_test.hpp"
|
||||||
#include "catch_test_spec.h"
|
#include "catch_test_spec.h"
|
||||||
|
#include "catch_test_case_tracker.hpp"
|
||||||
|
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <string>
|
#include <string>
|
||||||
@ -114,13 +115,15 @@ namespace Catch {
|
|||||||
|
|
||||||
m_reporter->testCaseStarting( testInfo );
|
m_reporter->testCaseStarting( testInfo );
|
||||||
|
|
||||||
m_runningTest = new RunningTest( testCase );
|
m_runningTest = new RunningTest( testCase ); // deprecated
|
||||||
|
m_testCaseTracker = TestCaseTracker( testInfo.name );
|
||||||
|
|
||||||
do {
|
do {
|
||||||
do {
|
do {
|
||||||
runCurrentTest( redirectedCout, redirectedCerr );
|
runCurrentTest( redirectedCout, redirectedCerr );
|
||||||
}
|
}
|
||||||
while( m_runningTest->hasUntestedSections() && !aborting() );
|
// while( m_runningTest->hasUntestedSections() && !aborting() );
|
||||||
|
while( !m_testCaseTracker->isCompleted() && !aborting() );
|
||||||
}
|
}
|
||||||
while( getCurrentContext().advanceGeneratorsForCurrentTest() && !aborting() );
|
while( getCurrentContext().advanceGeneratorsForCurrentTest() && !aborting() );
|
||||||
|
|
||||||
@ -144,6 +147,7 @@ namespace Catch {
|
|||||||
|
|
||||||
delete m_runningTest;
|
delete m_runningTest;
|
||||||
m_runningTest = NULL;
|
m_runningTest = NULL;
|
||||||
|
m_testCaseTracker.reset();
|
||||||
|
|
||||||
return deltaTotals;
|
return deltaTotals;
|
||||||
}
|
}
|
||||||
@ -182,10 +186,12 @@ namespace Catch {
|
|||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
oss << sectionInfo.name << "@" << sectionInfo.lineInfo;
|
oss << sectionInfo.name << "@" << sectionInfo.lineInfo;
|
||||||
|
|
||||||
|
if( !m_testCaseTracker->enterSection( oss.str() ) )
|
||||||
if( !m_runningTest->addSection( oss.str() ) )
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
// if( !m_runningTest->addSection( oss.str() ) ) // deprecated
|
||||||
|
// return false;
|
||||||
|
|
||||||
m_lastAssertionInfo.lineInfo = sectionInfo.lineInfo;
|
m_lastAssertionInfo.lineInfo = sectionInfo.lineInfo;
|
||||||
|
|
||||||
m_reporter->sectionStarting( sectionInfo );
|
m_reporter->sectionStarting( sectionInfo );
|
||||||
@ -205,13 +211,15 @@ namespace Catch {
|
|||||||
bool missingAssertions = false;
|
bool missingAssertions = false;
|
||||||
if( assertions.total() == 0 &&
|
if( assertions.total() == 0 &&
|
||||||
m_config->warnAboutMissingAssertions() &&
|
m_config->warnAboutMissingAssertions() &&
|
||||||
!m_runningTest->isBranchSection() ) {
|
!m_testCaseTracker->currentSectionHasChildren() ) {
|
||||||
|
// m_runningTest->isBranchSection() ) { // deprecated
|
||||||
m_totals.assertions.failed++;
|
m_totals.assertions.failed++;
|
||||||
assertions.failed++;
|
assertions.failed++;
|
||||||
missingAssertions = true;
|
missingAssertions = true;
|
||||||
|
|
||||||
}
|
}
|
||||||
m_runningTest->endSection( info.name, false );
|
// m_runningTest->endSection( info.name, false ); // deprecated
|
||||||
|
m_testCaseTracker->leaveSection();
|
||||||
|
|
||||||
m_reporter->sectionEnded( SectionStats( info, assertions, missingAssertions ) );
|
m_reporter->sectionEnded( SectionStats( info, assertions, missingAssertions ) );
|
||||||
m_messages.clear();
|
m_messages.clear();
|
||||||
@ -264,9 +272,13 @@ namespace Catch {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void runCurrentTest( std::string& redirectedCout, std::string& redirectedCerr ) {
|
void runCurrentTest( std::string& redirectedCout, std::string& redirectedCerr ) {
|
||||||
|
TestCaseInfo const& testCaseInfo = m_runningTest->getTestCase().getTestCaseInfo();
|
||||||
|
SectionInfo testCaseSection( testCaseInfo.name, testCaseInfo.description, testCaseInfo.lineInfo );
|
||||||
|
m_reporter->sectionStarting( testCaseSection );
|
||||||
try {
|
try {
|
||||||
m_lastAssertionInfo = AssertionInfo( "TEST_CASE", m_runningTest->getTestCase().getTestCaseInfo().lineInfo, "", ResultDisposition::Normal );
|
m_lastAssertionInfo = AssertionInfo( "TEST_CASE", testCaseInfo.lineInfo, "", ResultDisposition::Normal );
|
||||||
m_runningTest->reset();
|
//m_runningTest->reset(); // deprecated
|
||||||
|
m_testCaseTracker->enter();
|
||||||
|
|
||||||
if( m_reporter->getPreferences().shouldRedirectStdOut ) {
|
if( m_reporter->getPreferences().shouldRedirectStdOut ) {
|
||||||
StreamRedirect coutRedir( std::cout, redirectedCout );
|
StreamRedirect coutRedir( std::cout, redirectedCout );
|
||||||
@ -276,12 +288,15 @@ namespace Catch {
|
|||||||
else {
|
else {
|
||||||
m_runningTest->getTestCase().invoke();
|
m_runningTest->getTestCase().invoke();
|
||||||
}
|
}
|
||||||
m_runningTest->ranToCompletion();
|
//m_runningTest->ranToCompletion(); // deprecated
|
||||||
|
m_testCaseTracker->leave();
|
||||||
}
|
}
|
||||||
catch( TestFailureException& ) {
|
catch( TestFailureException& ) {
|
||||||
// This just means the test was aborted due to failure
|
// This just means the test was aborted due to failure
|
||||||
|
m_testCaseTracker->leave(); // !TBD: RAII
|
||||||
}
|
}
|
||||||
catch(...) {
|
catch(...) {
|
||||||
|
m_testCaseTracker->leave();
|
||||||
ExpressionResultBuilder exResult( ResultWas::ThrewException );
|
ExpressionResultBuilder exResult( ResultWas::ThrewException );
|
||||||
exResult << translateActiveException();
|
exResult << translateActiveException();
|
||||||
actOnCurrentResult( exResult.buildResult( m_lastAssertionInfo ) );
|
actOnCurrentResult( exResult.buildResult( m_lastAssertionInfo ) );
|
||||||
@ -295,6 +310,8 @@ namespace Catch {
|
|||||||
sectionEnded( it->info, it->prevAssertions );
|
sectionEnded( it->info, it->prevAssertions );
|
||||||
m_unfinishedSections.clear();
|
m_unfinishedSections.clear();
|
||||||
m_messages.clear();
|
m_messages.clear();
|
||||||
|
SectionStats testCaseSectionStats( testCaseSection, Counts(), 0 ); // !TBD
|
||||||
|
m_reporter->sectionEnded( testCaseSectionStats );
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -309,7 +326,8 @@ namespace Catch {
|
|||||||
|
|
||||||
TestRunInfo m_runInfo;
|
TestRunInfo m_runInfo;
|
||||||
IMutableContext& m_context;
|
IMutableContext& m_context;
|
||||||
RunningTest* m_runningTest;
|
RunningTest* m_runningTest; // deprecated
|
||||||
|
Option<TestCaseTracker> m_testCaseTracker;
|
||||||
AssertionResult m_lastResult;
|
AssertionResult m_lastResult;
|
||||||
|
|
||||||
Ptr<IConfig const> m_config;
|
Ptr<IConfig const> m_config;
|
||||||
|
@ -57,6 +57,9 @@ namespace SectionTracking {
|
|||||||
TrackedSection* getParent() {
|
TrackedSection* getParent() {
|
||||||
return m_parent;
|
return m_parent;
|
||||||
}
|
}
|
||||||
|
bool hasChildren() const {
|
||||||
|
return !m_children.empty();
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string m_name;
|
std::string m_name;
|
||||||
@ -98,6 +101,9 @@ namespace SectionTracking {
|
|||||||
m_completedASectionThisRun = true;
|
m_completedASectionThisRun = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool currentSectinHasChildren() const {
|
||||||
|
return m_currentSection->hasChildren();
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
TrackedSection* m_currentSection;
|
TrackedSection* m_currentSection;
|
||||||
@ -109,11 +115,11 @@ namespace SectionTracking {
|
|||||||
|
|
||||||
TestCaseTracker( std::string const& testCaseName )
|
TestCaseTracker( std::string const& testCaseName )
|
||||||
: m_testCase( testCaseName, NULL ),
|
: m_testCase( testCaseName, NULL ),
|
||||||
sections( m_testCase )
|
m_sections( m_testCase )
|
||||||
{}
|
{}
|
||||||
|
|
||||||
void enter() {
|
void enter() {
|
||||||
sections = SectionTracker( m_testCase );
|
m_sections = SectionTracker( m_testCase );
|
||||||
m_testCase.enter();
|
m_testCase.enter();
|
||||||
}
|
}
|
||||||
void leave() {
|
void leave() {
|
||||||
@ -121,19 +127,23 @@ namespace SectionTracking {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool enterSection( std::string const& name ) {
|
bool enterSection( std::string const& name ) {
|
||||||
return sections.enterSection( name );
|
return m_sections.enterSection( name );
|
||||||
}
|
}
|
||||||
void leaveSection() {
|
void leaveSection() {
|
||||||
sections.leaveSection();
|
m_sections.leaveSection();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isCompleted() const {
|
bool isCompleted() const {
|
||||||
return m_testCase.runState() == TrackedSection::Completed;
|
return m_testCase.runState() == TrackedSection::Completed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool currentSectionHasChildren() const {
|
||||||
|
return m_sections.currentSectinHasChildren();
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
TrackedSection m_testCase;
|
TrackedSection m_testCase;
|
||||||
SectionTracker sections;
|
SectionTracker m_sections;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace SectionTracking
|
} // namespace SectionTracking
|
||||||
|
@ -271,12 +271,10 @@ namespace Catch {
|
|||||||
sections.push_back( section );
|
sections.push_back( section );
|
||||||
|
|
||||||
// Sections
|
// Sections
|
||||||
if( !sections.empty() ) {
|
std::vector<ThreadedSectionInfo*>::const_reverse_iterator
|
||||||
typedef std::vector<ThreadedSectionInfo*>::const_reverse_iterator It;
|
it = sections.rbegin(), itEnd = sections.rend();
|
||||||
for( It it = sections.rbegin(), itEnd = sections.rend(); it != itEnd; ++it )
|
for( ++it; it != itEnd; ++it ) // Skip first section (test case)
|
||||||
printHeaderString( (*it)->name, 2 );
|
printHeaderString( (*it)->name, 2 );
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
SourceLineInfo lineInfo = currentSectionInfo
|
SourceLineInfo lineInfo = currentSectionInfo
|
||||||
? currentSectionInfo->lineInfo
|
? currentSectionInfo->lineInfo
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
namespace Catch {
|
namespace Catch {
|
||||||
class XmlReporter : public SharedImpl<IReporter> {
|
class XmlReporter : public SharedImpl<IReporter> {
|
||||||
public:
|
public:
|
||||||
XmlReporter( ReporterConfig const& config ) : m_config( config ) {}
|
XmlReporter( ReporterConfig const& config ) : m_config( config ), m_sectionDepth( 0 ) {}
|
||||||
|
|
||||||
static std::string getDescription() {
|
static std::string getDescription() {
|
||||||
return "Reports test results as an XML document";
|
return "Reports test results as an XML document";
|
||||||
@ -56,18 +56,22 @@ namespace Catch {
|
|||||||
}
|
}
|
||||||
|
|
||||||
virtual void StartSection( const std::string& sectionName, const std::string& description ) {
|
virtual void StartSection( const std::string& sectionName, const std::string& description ) {
|
||||||
m_xml.startElement( "Section" )
|
if( m_sectionDepth++ > 0 ) {
|
||||||
.writeAttribute( "name", sectionName )
|
m_xml.startElement( "Section" )
|
||||||
.writeAttribute( "description", description );
|
.writeAttribute( "name", sectionName )
|
||||||
|
.writeAttribute( "description", description );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
virtual void NoAssertionsInSection( const std::string& ) {}
|
virtual void NoAssertionsInSection( const std::string& ) {}
|
||||||
virtual void NoAssertionsInTestCase( const std::string& ) {}
|
virtual void NoAssertionsInTestCase( const std::string& ) {}
|
||||||
|
|
||||||
virtual void EndSection( const std::string& /*sectionName*/, const Counts& assertions ) {
|
virtual void EndSection( const std::string& /*sectionName*/, const Counts& assertions ) {
|
||||||
m_xml.scopedElement( "OverallResults" )
|
if( --m_sectionDepth > 0 ) {
|
||||||
.writeAttribute( "successes", assertions.passed )
|
m_xml.scopedElement( "OverallResults" )
|
||||||
.writeAttribute( "failures", assertions.failed );
|
.writeAttribute( "successes", assertions.passed )
|
||||||
m_xml.endElement();
|
.writeAttribute( "failures", assertions.failed );
|
||||||
|
m_xml.endElement();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void StartTestCase( const Catch::TestCaseInfo& testInfo ) {
|
virtual void StartTestCase( const Catch::TestCaseInfo& testInfo ) {
|
||||||
@ -138,6 +142,7 @@ namespace Catch {
|
|||||||
ReporterConfig m_config;
|
ReporterConfig m_config;
|
||||||
bool m_currentTestSuccess;
|
bool m_currentTestSuccess;
|
||||||
XmlWriter m_xml;
|
XmlWriter m_xml;
|
||||||
|
int m_sectionDepth;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // end namespace Catch
|
} // end namespace Catch
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -333,11 +333,11 @@ TEST_CASE( "vectors can be sized and resized", "[vector]" ) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// https://github.com/philsquared/Catch/issues/166
|
// https://github.com/philsquared/Catch/issues/166
|
||||||
//TEST_CASE("CatchSectionInfiniteLoop", "")
|
TEST_CASE("./failing/CatchSectionInfiniteLoop", "")
|
||||||
//{
|
{
|
||||||
// SECTION("Outer", "")
|
SECTION("Outer", "")
|
||||||
// SECTION("Inner", "")
|
SECTION("Inner", "")
|
||||||
// SUCCEED("that's not flying - that's failing in style");
|
SUCCEED("that's not flying - that's failing in style");
|
||||||
//
|
|
||||||
// FAIL("to infinity and beyond");
|
FAIL("to infinity and beyond");
|
||||||
//}
|
}
|
||||||
|
@ -38,15 +38,15 @@ TEST_CASE( "selftest/main", "Runs all Catch self tests and checks their results"
|
|||||||
SECTION( "selftest/test counts/succeeding tests",
|
SECTION( "selftest/test counts/succeeding tests",
|
||||||
"Number of 'succeeding' tests is fixed" ) {
|
"Number of 'succeeding' tests is fixed" ) {
|
||||||
Totals totals = runner.runMatching( "./succeeding/*", 0, 2 );
|
Totals totals = runner.runMatching( "./succeeding/*", 0, 2 );
|
||||||
CHECK( totals.assertions.passed == 296 );
|
CHECK( totals.assertions.passed == 298 );
|
||||||
CHECK( totals.assertions.failed == 0 );
|
CHECK( totals.assertions.failed == 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION( "selftest/test counts/failing tests",
|
SECTION( "selftest/test counts/failing tests",
|
||||||
"Number of 'failing' tests is fixed" ) {
|
"Number of 'failing' tests is fixed" ) {
|
||||||
Totals totals = runner.runMatching( "./failing/*", 1, 2 );
|
Totals totals = runner.runMatching( "./failing/*", 1, 2 );
|
||||||
CHECK( totals.assertions.passed == 1 );
|
CHECK( totals.assertions.passed == 2 );
|
||||||
CHECK( totals.assertions.failed == 74 );
|
CHECK( totals.assertions.failed == 77 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user