mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-04 05:09:53 +01:00
Replaced currentSectionInfo and m_rootSection with m_sectionStack
This commit is contained in:
parent
6339254cb2
commit
29ccaa67ad
@ -58,8 +58,6 @@ namespace Catch {
|
|||||||
TestCaseStats::~TestCaseStats() {}
|
TestCaseStats::~TestCaseStats() {}
|
||||||
TestGroupStats::~TestGroupStats() {}
|
TestGroupStats::~TestGroupStats() {}
|
||||||
TestRunStats::~TestRunStats() {}
|
TestRunStats::~TestRunStats() {}
|
||||||
TestGroupNode::~TestGroupNode() {}
|
|
||||||
TestRunNode::~TestRunNode() {}
|
|
||||||
|
|
||||||
BasicReporter::~BasicReporter() {}
|
BasicReporter::~BasicReporter() {}
|
||||||
StreamingReporterBase::~StreamingReporterBase() {}
|
StreamingReporterBase::~StreamingReporterBase() {}
|
||||||
|
@ -47,7 +47,7 @@ namespace Catch
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
template<typename T>
|
template<typename T, typename ChildT=T>
|
||||||
struct Node : SharedImpl<> {
|
struct Node : SharedImpl<> {
|
||||||
Node( T const& _value, Node* _parent = NULL )
|
Node( T const& _value, Node* _parent = NULL )
|
||||||
: value( _value ),
|
: value( _value ),
|
||||||
@ -223,6 +223,8 @@ namespace Catch
|
|||||||
|
|
||||||
struct StreamingReporterBase : SharedImpl<IStreamingReporter> {
|
struct StreamingReporterBase : SharedImpl<IStreamingReporter> {
|
||||||
|
|
||||||
|
typedef Ptr<Node<SectionInfo> > SectionInfoNode;
|
||||||
|
|
||||||
StreamingReporterBase( ReporterConfig const& _config )
|
StreamingReporterBase( ReporterConfig const& _config )
|
||||||
: m_config( _config.fullConfig() ),
|
: m_config( _config.fullConfig() ),
|
||||||
stream( _config.stream() )
|
stream( _config.stream() )
|
||||||
@ -244,28 +246,20 @@ namespace Catch
|
|||||||
}
|
}
|
||||||
virtual void sectionStarting( SectionInfo const& _sectionInfo ) {
|
virtual void sectionStarting( SectionInfo const& _sectionInfo ) {
|
||||||
Ptr<Node<SectionInfo> > sectionInfo = new Node<SectionInfo>( _sectionInfo );
|
Ptr<Node<SectionInfo> > sectionInfo = new Node<SectionInfo>( _sectionInfo );
|
||||||
if( !currentSectionInfo ) {
|
m_sectionStack.push_back( sectionInfo );
|
||||||
currentSectionInfo = sectionInfo;
|
|
||||||
m_rootSections.push_back( currentSectionInfo );
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
currentSectionInfo->children.push_back( sectionInfo );
|
|
||||||
sectionInfo->parent = currentSectionInfo.get();
|
|
||||||
currentSectionInfo = sectionInfo;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void sectionEnded( SectionStats const& /* _sectionStats */ ) {
|
virtual void sectionEnded( SectionStats const& /* _sectionStats */ ) {
|
||||||
currentSectionInfo = currentSectionInfo->parent;
|
m_sectionStack.pop_back();
|
||||||
}
|
}
|
||||||
virtual void testCaseEnded( TestCaseStats const& /* _testCaseStats */ ) {
|
virtual void testCaseEnded( TestCaseStats const& /* _testCaseStats */ ) {
|
||||||
unusedTestCaseInfo.reset();
|
unusedTestCaseInfo.reset();
|
||||||
|
assert( m_sectionStack.empty() );
|
||||||
}
|
}
|
||||||
virtual void testGroupEnded( TestGroupStats const& /* _testGroupStats */ ) {
|
virtual void testGroupEnded( TestGroupStats const& /* _testGroupStats */ ) {
|
||||||
unusedGroupInfo.reset();
|
unusedGroupInfo.reset();
|
||||||
}
|
}
|
||||||
virtual void testRunEnded( TestRunStats const& /* _testRunStats */ ) {
|
virtual void testRunEnded( TestRunStats const& /* _testRunStats */ ) {
|
||||||
currentSectionInfo.reset();
|
|
||||||
unusedTestCaseInfo.reset();
|
unusedTestCaseInfo.reset();
|
||||||
unusedGroupInfo.reset();
|
unusedGroupInfo.reset();
|
||||||
testRunInfo.reset();
|
testRunInfo.reset();
|
||||||
@ -275,26 +269,27 @@ namespace Catch
|
|||||||
Option<TestRunInfo> testRunInfo;
|
Option<TestRunInfo> testRunInfo;
|
||||||
Option<GroupInfo> unusedGroupInfo;
|
Option<GroupInfo> unusedGroupInfo;
|
||||||
Option<TestCaseInfo> unusedTestCaseInfo;
|
Option<TestCaseInfo> unusedTestCaseInfo;
|
||||||
Ptr<Node<SectionInfo> > currentSectionInfo;
|
|
||||||
std::ostream& stream;
|
std::ostream& stream;
|
||||||
|
|
||||||
// !TBD: This should really go in the TestCaseStats class
|
std::vector<SectionInfoNode> m_sectionStack;
|
||||||
std::vector<Ptr<Node<SectionInfo> > > m_rootSections;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct TestGroupNode : TestGroupStats {
|
struct CumulativeReporterBase : StreamingReporterBase {
|
||||||
TestGroupNode( TestGroupStats const& _stats ) : TestGroupStats( _stats ) {}
|
virtual void testRunStarting( TestRunInfo const& testRunInfo ) = 0;
|
||||||
// TestGroupNode( GroupInfo const& _info ) : TestGroupStats( _stats ) {}
|
virtual void testGroupStarting( GroupInfo const& groupInfo ) = 0;
|
||||||
~TestGroupNode();
|
|
||||||
|
|
||||||
};
|
virtual void testCaseStarting( TestCaseInfo const& testInfo ) = 0;
|
||||||
|
virtual void sectionStarting( SectionInfo const& sectionInfo ) = 0;
|
||||||
|
|
||||||
struct TestRunNode : TestRunStats {
|
virtual void assertionStarting( AssertionInfo const& assertionInfo ) = 0;
|
||||||
|
|
||||||
TestRunNode( TestRunStats const& _stats ) : TestRunStats( _stats ) {}
|
virtual bool assertionEnded( AssertionStats const& assertionStats ) = 0;
|
||||||
~TestRunNode();
|
virtual void sectionEnded( SectionStats const& sectionStats ) = 0;
|
||||||
|
virtual void testCaseEnded( TestCaseStats const& testCaseStats ) = 0;
|
||||||
|
virtual void testGroupEnded( TestGroupStats const& testGroupStats ) = 0;
|
||||||
|
virtual void testRunEnded( TestRunStats const& testRunStats ) = 0;
|
||||||
|
|
||||||
std::vector<TestGroupNode> groups;
|
std::vector<Ptr<Node<TestGroupStats> > > m_groups;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Deprecated
|
// Deprecated
|
||||||
@ -333,8 +328,9 @@ namespace Catch
|
|||||||
};
|
};
|
||||||
|
|
||||||
inline std::string trim( std::string const& str ) {
|
inline std::string trim( std::string const& str ) {
|
||||||
std::string::size_type start = str.find_first_not_of( "\n\r\t " );
|
static char const* whitespaceChars = "\n\r\t ";
|
||||||
std::string::size_type end = str.find_last_not_of( "\n\r\t " );
|
std::string::size_type start = str.find_first_not_of( whitespaceChars );
|
||||||
|
std::string::size_type end = str.find_last_not_of( whitespaceChars );
|
||||||
|
|
||||||
return start != std::string::npos ? str.substr( start, 1+end-start ) : "";
|
return start != std::string::npos ? str.substr( start, 1+end-start ) : "";
|
||||||
}
|
}
|
||||||
|
@ -62,7 +62,7 @@ namespace Catch {
|
|||||||
if( _sectionStats.missingAssertions ) {
|
if( _sectionStats.missingAssertions ) {
|
||||||
lazyPrint();
|
lazyPrint();
|
||||||
Colour colour( Colour::ResultError );
|
Colour colour( Colour::ResultError );
|
||||||
if( currentSectionInfo->parent )
|
if( m_sectionStack.size() > 1 )
|
||||||
stream << "\nNo assertions in section";
|
stream << "\nNo assertions in section";
|
||||||
else
|
else
|
||||||
stream << "\nNo assertions in test case";
|
stream << "\nNo assertions in test case";
|
||||||
@ -261,25 +261,20 @@ namespace Catch {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
void printTestCaseAndSectionHeader() {
|
void printTestCaseAndSectionHeader() {
|
||||||
|
assert( !m_sectionStack.empty() );
|
||||||
printOpenHeader( unusedTestCaseInfo->name );
|
printOpenHeader( unusedTestCaseInfo->name );
|
||||||
assert( currentSectionInfo );
|
|
||||||
if( currentSectionInfo ) {
|
|
||||||
Colour colourGuard( Colour::Headers );
|
|
||||||
std::vector<Node<SectionInfo>*> sections;
|
|
||||||
for( Node<SectionInfo>* section = currentSectionInfo.get();
|
|
||||||
section;
|
|
||||||
section = section->parent )
|
|
||||||
sections.push_back( section );
|
|
||||||
|
|
||||||
// Sections
|
if( m_sectionStack.size() > 1 ) {
|
||||||
std::vector<Node<SectionInfo>*>::const_reverse_iterator
|
Colour colourGuard( Colour::Headers );
|
||||||
it = sections.rbegin(), itEnd = sections.rend();
|
|
||||||
for( ++it; it != itEnd; ++it ) // Skip first section (test case)
|
std::vector<SectionInfoNode>::const_iterator
|
||||||
|
it = m_sectionStack.begin()+1, // Skip first section (test case)
|
||||||
|
itEnd = m_sectionStack.end();
|
||||||
|
for( ; it != itEnd; ++it )
|
||||||
printHeaderString( (*it)->value.name, 2 );
|
printHeaderString( (*it)->value.name, 2 );
|
||||||
}
|
}
|
||||||
SourceLineInfo lineInfo = currentSectionInfo
|
|
||||||
? currentSectionInfo->value.lineInfo
|
SourceLineInfo lineInfo = m_sectionStack.front()->value.lineInfo;
|
||||||
: unusedTestCaseInfo->lineInfo;
|
|
||||||
|
|
||||||
if( !lineInfo.empty() ){
|
if( !lineInfo.empty() ){
|
||||||
stream << getDashes() << "\n";
|
stream << getDashes() << "\n";
|
||||||
|
@ -670,8 +670,6 @@ MiscTests.cpp: FAILED:
|
|||||||
explicitly with message:
|
explicitly with message:
|
||||||
to infinity and beyond
|
to infinity and beyond
|
||||||
|
|
||||||
starting...
|
|
||||||
finished in 0.322593
|
|
||||||
Message from section one
|
Message from section one
|
||||||
Message from section two
|
Message from section two
|
||||||
Some information
|
Some information
|
||||||
@ -710,7 +708,7 @@ with expansion:
|
|||||||
"first" == "second"
|
"first" == "second"
|
||||||
|
|
||||||
===============================================================================
|
===============================================================================
|
||||||
122 test cases - 35 failed (738 assertions - 90 failed)
|
121 test cases - 35 failed (737 assertions - 90 failed)
|
||||||
|
|
||||||
|
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
@ -4318,19 +4316,6 @@ MiscTests.cpp: FAILED:
|
|||||||
explicitly with message:
|
explicitly with message:
|
||||||
to infinity and beyond
|
to infinity and beyond
|
||||||
|
|
||||||
starting...
|
|
||||||
finished in 0.323247
|
|
||||||
-------------------------------------------------------------------------------
|
|
||||||
Timer
|
|
||||||
-------------------------------------------------------------------------------
|
|
||||||
MiscTests.cpp
|
|
||||||
...............................................................................
|
|
||||||
|
|
||||||
MiscTests.cpp:
|
|
||||||
PASSED:
|
|
||||||
with message:
|
|
||||||
yay
|
|
||||||
|
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
selftest/main
|
selftest/main
|
||||||
selftest/expected result
|
selftest/expected result
|
||||||
@ -7184,13 +7169,13 @@ with expansion:
|
|||||||
true
|
true
|
||||||
|
|
||||||
===============================================================================
|
===============================================================================
|
||||||
122 test cases - 50 failed (757 assertions - 109 failed)
|
121 test cases - 50 failed (756 assertions - 109 failed)
|
||||||
|
|
||||||
No test cases matched '~dummy 4'
|
No test cases matched '~dummy 4'
|
||||||
No tests ran
|
No tests ran
|
||||||
|
|
||||||
<testsuites>
|
<testsuites>
|
||||||
<testsuite name="~dummy" errors="10" failures="81" tests="757" hostname="tbd" time="" timestamp="tbd">
|
<testsuite name="~dummy" errors="10" failures="81" tests="756" hostname="tbd" time="" timestamp="tbd">
|
||||||
<testcase classname="global" name="./succeeding/Approx/simple" time="0"/>
|
<testcase classname="global" name="./succeeding/Approx/simple" time="0"/>
|
||||||
<testcase classname="global" name="./succeeding/Approx/epsilon" time="0"/>
|
<testcase classname="global" name="./succeeding/Approx/epsilon" time="0"/>
|
||||||
<testcase classname="global" name="./succeeding/Approx/float" time="0"/>
|
<testcase classname="global" name="./succeeding/Approx/float" time="0"/>
|
||||||
@ -7639,12 +7624,6 @@ MiscTests.cpp
|
|||||||
MiscTests.cpp
|
MiscTests.cpp
|
||||||
</failure>
|
</failure>
|
||||||
</testcase>
|
</testcase>
|
||||||
<testcase classname="global" name="Timer" time="0">
|
|
||||||
<system-out>
|
|
||||||
starting...
|
|
||||||
finished in 0.322247
|
|
||||||
</system-out>
|
|
||||||
</testcase>
|
|
||||||
<testcase classname="global" name="selftest/main" time="0">
|
<testcase classname="global" name="selftest/main" time="0">
|
||||||
<system-out>
|
<system-out>
|
||||||
Message from section one
|
Message from section one
|
||||||
@ -7728,9 +7707,6 @@ Message from section two
|
|||||||
|
|
||||||
Some information
|
Some information
|
||||||
|
|
||||||
starting...
|
|
||||||
finished in 0.322247
|
|
||||||
|
|
||||||
Message from section one
|
Message from section one
|
||||||
Message from section two
|
Message from section two
|
||||||
Some information
|
Some information
|
||||||
@ -11438,9 +11414,6 @@ An error
|
|||||||
</Failure>
|
</Failure>
|
||||||
<OverallResult success="false"/>
|
<OverallResult success="false"/>
|
||||||
</TestCase>
|
</TestCase>
|
||||||
<TestCase name="Timer">
|
|
||||||
<OverallResult success="true"/>
|
|
||||||
</TestCase>
|
|
||||||
<TestCase name="selftest/main">
|
<TestCase name="selftest/main">
|
||||||
<Section name="selftest/expected result" description="Tests do what they claim">
|
<Section name="selftest/expected result" description="Tests do what they claim">
|
||||||
<OverallResults successes="0" failures="0"/>
|
<OverallResults successes="0" failures="0"/>
|
||||||
@ -14096,7 +14069,7 @@ there"
|
|||||||
</Section>
|
</Section>
|
||||||
<OverallResult success="true"/>
|
<OverallResult success="true"/>
|
||||||
</TestCase>
|
</TestCase>
|
||||||
<OverallResults successes="648" failures="109"/>
|
<OverallResults successes="647" failures="109"/>
|
||||||
</Group>
|
</Group>
|
||||||
<OverallResults successes="648" failures="109"/>
|
<OverallResults successes="647" failures="109"/>
|
||||||
</Catch>
|
</Catch>
|
||||||
|
@ -343,24 +343,24 @@ TEST_CASE("./failing/CatchSectionInfiniteLoop", "")
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#include "internal/catch_timer.h"
|
//#include "internal/catch_timer.h"
|
||||||
|
//
|
||||||
TEST_CASE( "Timer", "[work-in-progress]" )
|
//TEST_CASE( "Timer", "[work-in-progress]" )
|
||||||
{
|
//{
|
||||||
Catch::Timer t;
|
// Catch::Timer t;
|
||||||
t.start();
|
// t.start();
|
||||||
|
//
|
||||||
std::cout << "starting..." << std::endl;
|
// std::cout << "starting..." << std::endl;
|
||||||
|
//
|
||||||
double d = 0;
|
// double d = 0;
|
||||||
for( int i = 0; i < 100000; ++i )
|
// for( int i = 0; i < 100000; ++i )
|
||||||
for( int j = 0; j < 1000; ++j )
|
// for( int j = 0; j < 1000; ++j )
|
||||||
d += (double)i*(double)j;
|
// d += (double)i*(double)j;
|
||||||
|
//
|
||||||
double duration = t.getElapsedSeconds();
|
// double duration = t.getElapsedSeconds();
|
||||||
|
//
|
||||||
std::cout << "finished in " << duration << std::endl;
|
// std::cout << "finished in " << duration << std::endl;
|
||||||
|
//
|
||||||
SUCCEED("yay");
|
// SUCCEED("yay");
|
||||||
|
//
|
||||||
}
|
//}
|
||||||
|
Loading…
Reference in New Issue
Block a user