From a02086599076a0b055c5408a5ed424713eb8bbce Mon Sep 17 00:00:00 2001 From: Phil Nash Date: Mon, 21 Apr 2014 19:02:38 +0100 Subject: [PATCH] Sections are, once again, eagerly entered. When the section tracking code was rewritten a while back to simplify and iron out some bugs the order of evaluation was changed so that each new section was skipped on the first run through. This had unwelcome consequences for some people. This commit restores the original semantics (while maintaining the simpler, less buggy, new code). --- README.md | 2 +- include/internal/catch_runner_impl.hpp | 4 +- include/internal/catch_test_case_tracker.hpp | 39 +- include/internal/catch_version.hpp | 2 +- .../Baselines/console.std.approved.txt | 22 +- .../Baselines/console.sw.approved.txt | 379 +-------------- .../SelfTest/Baselines/junit.sw.approved.txt | 14 +- .../SelfTest/Baselines/xml.sw.approved.txt | 440 ++---------------- projects/SelfTest/SectionTrackerTests.cpp | 73 +-- single_include/catch.hpp | 49 +- 10 files changed, 107 insertions(+), 917 deletions(-) diff --git a/README.md b/README.md index 38e5c828..3916e0a4 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ ![catch logo](catch-logo-small.png) -*v1.0 build 38 (master branch)* +*v1.0 build 39 (master branch)* Build status (on Travis CI) [![Build Status](https://travis-ci.org/philsquared/Catch.png)](https://travis-ci.org/philsquared/Catch) diff --git a/include/internal/catch_runner_impl.hpp b/include/internal/catch_runner_impl.hpp index 8ca65934..9794bc51 100644 --- a/include/internal/catch_runner_impl.hpp +++ b/include/internal/catch_runner_impl.hpp @@ -271,8 +271,8 @@ namespace Catch { } // If sections ended prematurely due to an exception we stored their // infos here so we can tear them down outside the unwind process. - for( std::vector::const_iterator it = m_unfinishedSections.begin(), - itEnd = m_unfinishedSections.end(); + for( std::vector::const_reverse_iterator it = m_unfinishedSections.rbegin(), + itEnd = m_unfinishedSections.rend(); it != itEnd; ++it ) sectionEnded( it->info, it->prevAssertions, it->durationInSeconds ); diff --git a/include/internal/catch_test_case_tracker.hpp b/include/internal/catch_test_case_tracker.hpp index ebb4fb8a..2165e1cc 100644 --- a/include/internal/catch_test_case_tracker.hpp +++ b/include/internal/catch_test_case_tracker.hpp @@ -33,13 +33,18 @@ namespace SectionTracking { RunState runState() const { return m_runState; } - void addChild( std::string const& childName ) { + TrackedSection* findChild( std::string const& childName ) { + TrackedSections::iterator it = m_children.find( childName ); + return it != m_children.end() + ? &it->second + : NULL; + } + TrackedSection* acquireChild( std::string const& childName ) { + if( TrackedSection* child = findChild( childName ) ) + return child; m_children.insert( std::make_pair( childName, TrackedSection( childName, this ) ) ); + return findChild( childName ); } - TrackedSection* getChild( std::string const& childName ) { - return &m_children.find( childName )->second; - } - void enter() { if( m_runState == NotStarted ) m_runState = Executing; @@ -78,21 +83,13 @@ namespace SectionTracking { {} bool enterSection( std::string const& name ) { - if( m_completedASectionThisRun ) + TrackedSection* child = m_currentSection->acquireChild( name ); + if( m_completedASectionThisRun || child->runState() == TrackedSection::Completed ) return false; - if( m_currentSection->runState() == TrackedSection::Executing ) { - m_currentSection->addChild( name ); - return false; - } - else { - TrackedSection* child = m_currentSection->getChild( name ); - if( child->runState() != TrackedSection::Completed ) { - m_currentSection = child; - m_currentSection->enter(); - return true; - } - return false; - } + + m_currentSection = child; + m_currentSection->enter(); + return true; } void leaveSection() { m_currentSection->leave(); @@ -110,9 +107,7 @@ namespace SectionTracking { class Guard { public: - Guard( TestCaseTracker& tracker ) - : m_tracker( tracker ) - { + Guard( TestCaseTracker& tracker ) : m_tracker( tracker ) { m_tracker.enterTestCase(); } ~Guard() { diff --git a/include/internal/catch_version.hpp b/include/internal/catch_version.hpp index 7625293d..652e7f4e 100644 --- a/include/internal/catch_version.hpp +++ b/include/internal/catch_version.hpp @@ -13,7 +13,7 @@ namespace Catch { // These numbers are maintained by a script - Version libraryVersion( 1, 0, 38, "master" ); + Version libraryVersion( 1, 0, 39, "master" ); } #endif // TWOBLUECUBES_CATCH_VERSION_HPP_INCLUDED diff --git a/projects/SelfTest/Baselines/console.std.approved.txt b/projects/SelfTest/Baselines/console.std.approved.txt index af806f01..74b5ae12 100644 --- a/projects/SelfTest/Baselines/console.std.approved.txt +++ b/projects/SelfTest/Baselines/console.std.approved.txt @@ -698,26 +698,6 @@ A couple of nested sections followed by a failure MiscTests.cpp: ............................................................................... -MiscTests.cpp:: FAILED: -explicitly with message: - to infinity and beyond - -------------------------------------------------------------------------------- -A couple of nested sections followed by a failure -------------------------------------------------------------------------------- -MiscTests.cpp: -............................................................................... - -MiscTests.cpp:: FAILED: -explicitly with message: - to infinity and beyond - -------------------------------------------------------------------------------- -A couple of nested sections followed by a failure -------------------------------------------------------------------------------- -MiscTests.cpp: -............................................................................... - MiscTests.cpp:: FAILED: explicitly with message: to infinity and beyond @@ -774,5 +754,5 @@ with expansion: "first" == "second" =============================================================================== -125 test cases - 38 failed (661 assertions - 93 failed) +125 test cases - 38 failed (627 assertions - 91 failed) diff --git a/projects/SelfTest/Baselines/console.sw.approved.txt b/projects/SelfTest/Baselines/console.sw.approved.txt index bf8892f0..3a85adf8 100644 --- a/projects/SelfTest/Baselines/console.sw.approved.txt +++ b/projects/SelfTest/Baselines/console.sw.approved.txt @@ -2848,25 +2848,6 @@ nested SECTION tests MiscTests.cpp: ............................................................................... -MiscTests.cpp:: -PASSED: - REQUIRE( a != b ) -with expansion: - 1 != 2 - -MiscTests.cpp:: -PASSED: - REQUIRE( b != a ) -with expansion: - 2 != 1 - -------------------------------------------------------------------------------- -nested SECTION tests - s1 -------------------------------------------------------------------------------- -MiscTests.cpp: -............................................................................... - MiscTests.cpp:: PASSED: REQUIRE( a != b ) @@ -2906,34 +2887,6 @@ MiscTests.cpp:: FAILED: with expansion: 1 == 2 -------------------------------------------------------------------------------- -more nested SECTION tests - s1 - s3 -------------------------------------------------------------------------------- -MiscTests.cpp: -............................................................................... - -MiscTests.cpp:: -PASSED: - REQUIRE( a != b ) -with expansion: - 1 != 2 - -------------------------------------------------------------------------------- -more nested SECTION tests - s1 - s4 -------------------------------------------------------------------------------- -MiscTests.cpp: -............................................................................... - -MiscTests.cpp:: -PASSED: - REQUIRE( a < b ) -with expansion: - 1 < 2 - ------------------------------------------------------------------------------- even more nested SECTION tests c @@ -3396,24 +3349,6 @@ vectors can be sized and resized MiscTests.cpp: ............................................................................... -MiscTests.cpp:: -PASSED: - REQUIRE( v.size() == 5 ) -with expansion: - 5 == 5 - -MiscTests.cpp:: -PASSED: - REQUIRE( v.capacity() >= 5 ) -with expansion: - 5 >= 5 - -------------------------------------------------------------------------------- -vectors can be sized and resized -------------------------------------------------------------------------------- -MiscTests.cpp: -............................................................................... - MiscTests.cpp:: PASSED: REQUIRE( v.size() == 5 ) @@ -3470,43 +3405,6 @@ vectors can be sized and resized MiscTests.cpp: ............................................................................... -MiscTests.cpp:: -PASSED: - REQUIRE( v.size() == 0 ) -with expansion: - 0 == 0 - -MiscTests.cpp:: -PASSED: - REQUIRE( v.capacity() >= 5 ) -with expansion: - 5 >= 5 - -------------------------------------------------------------------------------- -vectors can be sized and resized -------------------------------------------------------------------------------- -MiscTests.cpp: -............................................................................... - -MiscTests.cpp:: -PASSED: - REQUIRE( v.size() == 5 ) -with expansion: - 5 == 5 - -MiscTests.cpp:: -PASSED: - REQUIRE( v.capacity() >= 5 ) -with expansion: - 5 >= 5 - -------------------------------------------------------------------------------- -vectors can be sized and resized - resizing smaller changes size but not capacity -------------------------------------------------------------------------------- -MiscTests.cpp: -............................................................................... - MiscTests.cpp:: PASSED: REQUIRE( v.size() == 0 ) @@ -3607,26 +3505,6 @@ PASSED: with expansion: 5 >= 5 -------------------------------------------------------------------------------- -A couple of nested sections followed by a failure -------------------------------------------------------------------------------- -MiscTests.cpp: -............................................................................... - -MiscTests.cpp:: FAILED: -explicitly with message: - to infinity and beyond - -------------------------------------------------------------------------------- -A couple of nested sections followed by a failure -------------------------------------------------------------------------------- -MiscTests.cpp: -............................................................................... - -MiscTests.cpp:: FAILED: -explicitly with message: - to infinity and beyond - ------------------------------------------------------------------------------- A couple of nested sections followed by a failure Outer @@ -6261,43 +6139,6 @@ Assertions then sections TrickyTests.cpp: ............................................................................... -TrickyTests.cpp:: -PASSED: - REQUIRE( Catch::isTrue( true ) ) -with expansion: - true - -------------------------------------------------------------------------------- -Assertions then sections -------------------------------------------------------------------------------- -TrickyTests.cpp: -............................................................................... - -TrickyTests.cpp:: -PASSED: - REQUIRE( Catch::isTrue( true ) ) -with expansion: - true - -------------------------------------------------------------------------------- -Assertions then sections - A section -------------------------------------------------------------------------------- -TrickyTests.cpp: -............................................................................... - -TrickyTests.cpp:: -PASSED: - REQUIRE( Catch::isTrue( true ) ) -with expansion: - true - -------------------------------------------------------------------------------- -Assertions then sections -------------------------------------------------------------------------------- -TrickyTests.cpp: -............................................................................... - TrickyTests.cpp:: PASSED: REQUIRE( Catch::isTrue( true ) ) @@ -6505,21 +6346,6 @@ Scenario: Do that thing with the thing BDDTests.cpp: ............................................................................... -BDDTests.cpp:: -PASSED: - REQUIRE( itDoesThis() ) -with expansion: - true - -------------------------------------------------------------------------------- -Scenario: Do that thing with the thing - Given: This stuff exists - When: I do this - Then: it should do this -------------------------------------------------------------------------------- -BDDTests.cpp: -............................................................................... - BDDTests.cpp:: PASSED: REQUIRE( itDoesThis() ) @@ -6549,100 +6375,6 @@ Scenario: Vector resizing affects size and capacity BDDTests.cpp: ............................................................................... -BDDTests.cpp:: -PASSED: - REQUIRE( v.size() == 0 ) -with expansion: - 0 == 0 - -------------------------------------------------------------------------------- -Scenario: Vector resizing affects size and capacity - Given: an empty vector -------------------------------------------------------------------------------- -BDDTests.cpp: -............................................................................... - -BDDTests.cpp:: -PASSED: - REQUIRE( v.size() == 0 ) -with expansion: - 0 == 0 - -------------------------------------------------------------------------------- -Scenario: Vector resizing affects size and capacity - Given: an empty vector -------------------------------------------------------------------------------- -BDDTests.cpp: -............................................................................... - -BDDTests.cpp:: -PASSED: - REQUIRE( v.size() == 0 ) -with expansion: - 0 == 0 - -------------------------------------------------------------------------------- -Scenario: Vector resizing affects size and capacity - Given: an empty vector - When: it is made larger - Then: the size and capacity go up -------------------------------------------------------------------------------- -BDDTests.cpp: -............................................................................... - -BDDTests.cpp:: -PASSED: - REQUIRE( v.size() == 10 ) -with expansion: - 10 == 10 - -BDDTests.cpp:: -PASSED: - REQUIRE( v.capacity() >= 10 ) -with expansion: - 10 >= 10 - -------------------------------------------------------------------------------- -Scenario: Vector resizing affects size and capacity - Given: an empty vector -------------------------------------------------------------------------------- -BDDTests.cpp: -............................................................................... - -BDDTests.cpp:: -PASSED: - REQUIRE( v.size() == 0 ) -with expansion: - 0 == 0 - -------------------------------------------------------------------------------- -Scenario: Vector resizing affects size and capacity - Given: an empty vector - When: it is made larger - Then: the size and capacity go up -------------------------------------------------------------------------------- -BDDTests.cpp: -............................................................................... - -BDDTests.cpp:: -PASSED: - REQUIRE( v.size() == 10 ) -with expansion: - 10 == 10 - -BDDTests.cpp:: -PASSED: - REQUIRE( v.capacity() >= 10 ) -with expansion: - 10 >= 10 - -------------------------------------------------------------------------------- -Scenario: Vector resizing affects size and capacity - Given: an empty vector -------------------------------------------------------------------------------- -BDDTests.cpp: -............................................................................... - BDDTests.cpp:: PASSED: REQUIRE( v.size() == 0 ) @@ -6700,19 +6432,6 @@ Scenario: Vector resizing affects size and capacity BDDTests.cpp: ............................................................................... -BDDTests.cpp:: -PASSED: - REQUIRE( v.size() == 0 ) -with expansion: - 0 == 0 - -------------------------------------------------------------------------------- -Scenario: Vector resizing affects size and capacity - Given: an empty vector -------------------------------------------------------------------------------- -BDDTests.cpp: -............................................................................... - BDDTests.cpp:: PASSED: REQUIRE( v.size() == 0 ) @@ -6764,18 +6483,6 @@ section tracking SectionTrackerTests.cpp: ............................................................................... -SectionTrackerTests.cpp:: -PASSED: - CHECK_FALSE( testCaseTracker.isCompleted() ) -with expansion: - !false - -------------------------------------------------------------------------------- -section tracking -------------------------------------------------------------------------------- -SectionTrackerTests.cpp: -............................................................................... - SectionTrackerTests.cpp:: PASSED: CHECK_FALSE( testCaseTracker.isCompleted() ) @@ -6820,36 +6527,30 @@ section tracking SectionTrackerTests.cpp: ............................................................................... -SectionTrackerTests.cpp:: -PASSED: - CHECK_FALSE( testCaseTracker.enterSection( section1Name ) ) -with expansion: - !false - -SectionTrackerTests.cpp:: -PASSED: - CHECK_FALSE( testCaseTracker.isCompleted() ) -with expansion: - !false - -SectionTrackerTests.cpp:: -PASSED: - CHECK_FALSE( testCaseTracker.isCompleted() ) -with expansion: - !false - SectionTrackerTests.cpp:: PASSED: CHECK( testCaseTracker.enterSection( section1Name ) ) with expansion: true +SectionTrackerTests.cpp:: +PASSED: + CHECK_FALSE( testCaseTracker.isCompleted() ) +with expansion: + !false + SectionTrackerTests.cpp:: PASSED: CHECK( testCaseTracker.isCompleted() ) with expansion: true +SectionTrackerTests.cpp:: +PASSED: + CHECK_FALSE( testCaseTracker.enterSection( section1Name ) ) +with expansion: + !false + ------------------------------------------------------------------------------- section tracking ------------------------------------------------------------------------------- @@ -6869,24 +6570,6 @@ section tracking SectionTrackerTests.cpp: ............................................................................... -SectionTrackerTests.cpp:: -PASSED: - CHECK_FALSE( testCaseTracker.enterSection( section1Name ) ) -with expansion: - !false - -SectionTrackerTests.cpp:: -PASSED: - CHECK_FALSE( testCaseTracker.enterSection( section2Name ) ) -with expansion: - !false - -SectionTrackerTests.cpp:: -PASSED: - CHECK_FALSE( testCaseTracker.isCompleted() ) -with expansion: - !false - SectionTrackerTests.cpp:: PASSED: CHECK( testCaseTracker.enterSection( section1Name ) ) @@ -6942,36 +6625,6 @@ section tracking SectionTrackerTests.cpp: ............................................................................... -SectionTrackerTests.cpp:: -PASSED: - CHECK_FALSE( testCaseTracker.enterSection( section1Name ) ) -with expansion: - !false - -SectionTrackerTests.cpp:: -PASSED: - CHECK_FALSE( testCaseTracker.isCompleted() ) -with expansion: - !false - -SectionTrackerTests.cpp:: -PASSED: - CHECK( testCaseTracker.enterSection( section1Name ) ) -with expansion: - true - -SectionTrackerTests.cpp:: -PASSED: - CHECK_FALSE( testCaseTracker.enterSection( section2Name ) ) -with expansion: - !false - -SectionTrackerTests.cpp:: -PASSED: - CHECK_FALSE( testCaseTracker.isCompleted() ) -with expansion: - !false - SectionTrackerTests.cpp:: PASSED: CHECK( testCaseTracker.enterSection( section1Name ) ) @@ -6984,6 +6637,12 @@ PASSED: with expansion: true +SectionTrackerTests.cpp:: +PASSED: + CHECK_FALSE( testCaseTracker.isCompleted() ) +with expansion: + !false + SectionTrackerTests.cpp:: PASSED: CHECK( testCaseTracker.isCompleted() ) @@ -6991,5 +6650,5 @@ with expansion: true =============================================================================== -125 test cases - 53 failed (680 assertions - 112 failed) +125 test cases - 53 failed (646 assertions - 110 failed) diff --git a/projects/SelfTest/Baselines/junit.sw.approved.txt b/projects/SelfTest/Baselines/junit.sw.approved.txt index 5f848abe..5b36c2bf 100644 --- a/projects/SelfTest/Baselines/junit.sw.approved.txt +++ b/projects/SelfTest/Baselines/junit.sw.approved.txt @@ -1,5 +1,5 @@ - + @@ -323,13 +323,11 @@ MessageTests.cpp: - + MiscTests.cpp: - - MiscTests.cpp: @@ -431,14 +429,6 @@ MiscTests.cpp: to infinity and beyond -MiscTests.cpp: - - -to infinity and beyond -MiscTests.cpp: - - -to infinity and beyond MiscTests.cpp: diff --git a/projects/SelfTest/Baselines/xml.sw.approved.txt b/projects/SelfTest/Baselines/xml.sw.approved.txt index 24560b6d..4aec98f8 100644 --- a/projects/SelfTest/Baselines/xml.sw.approved.txt +++ b/projects/SelfTest/Baselines/xml.sw.approved.txt @@ -2957,25 +2957,6 @@ -
- - - a != b - - - 1 != 2 - - - - - b != a - - - 2 != 1 - - - -
@@ -3009,9 +2990,6 @@ -
- -
@@ -3026,40 +3004,9 @@
-
-
- - - a != b - - - 1 != 2 - - - -
- -
-
-
- - - a < b - - - 1 < 2 - - - -
- -
-
- -
@@ -3498,22 +3445,6 @@ - - - v.size() == 5 - - - 5 == 5 - - - - - v.capacity() >= 5 - - - 5 >= 5 - - v.size() == 5 @@ -3565,41 +3496,6 @@ 5 >= 5 -
- - - v.size() == 0 - - - 0 == 0 - - - - - v.capacity() >= 5 - - - 5 >= 5 - - - -
- - - v.size() == 5 - - - 5 == 5 - - - - - v.capacity() >= 5 - - - 5 >= 5 - -
@@ -3703,15 +3599,6 @@ - - to infinity and beyond - -
- -
- - to infinity and beyond -
@@ -3770,9 +3657,6 @@
-
- -
@@ -3933,9 +3817,6 @@
-
- -
@@ -4002,9 +3883,6 @@
-
- -
@@ -4049,9 +3927,6 @@
-
- -
@@ -4126,9 +4001,6 @@
-
- -
@@ -4173,9 +4045,6 @@
-
- -
@@ -4220,9 +4089,6 @@
-
- -
@@ -4788,9 +4654,6 @@ -
- -
@@ -5117,9 +4980,6 @@ ur"
-
- -
@@ -6554,33 +6414,6 @@ there" - - - Catch::isTrue( true ) - - - true - - - - - Catch::isTrue( true ) - - - true - - -
- - - Catch::isTrue( true ) - - - true - - - -
Catch::isTrue( true ) @@ -6722,32 +6555,6 @@ there"
-
- -
-
-
- -
- -
-
-
-
- - - itDoesThis() - - - true - - - -
- -
- -
@@ -6779,100 +6586,6 @@ there" -
- - - v.size() == 0 - - - 0 == 0 - - - -
-
- - - v.size() == 0 - - - 0 == 0 - - -
- -
- -
-
- - - v.size() == 0 - - - 0 == 0 - - -
-
- - - v.size() == 10 - - - 10 == 10 - - - - - v.capacity() >= 10 - - - 10 >= 10 - - - -
- -
- -
-
- - - v.size() == 0 - - - 0 == 0 - - -
-
- - - v.size() == 10 - - - 10 == 10 - - - - - v.capacity() >= 10 - - - 10 >= 10 - - -
- -
- -
- -
- -
@@ -6928,20 +6641,6 @@ there"
-
- - - v.size() == 0 - - - 0 == 0 - - -
- -
- -
@@ -6978,15 +6677,6 @@ there" -
- -
-
-
- -
- -
@@ -6999,14 +6689,6 @@ there" - - - !testCaseTracker.isCompleted() - - - !false - - !testCaseTracker.isCompleted() @@ -7043,30 +6725,6 @@ there"
- - - !testCaseTracker.enterSection( section1Name ) - - - !false - - - - - !testCaseTracker.isCompleted() - - - !false - - - - - !testCaseTracker.isCompleted() - - - !false - - testCaseTracker.enterSection( section1Name ) @@ -7075,6 +6733,14 @@ there" true + + + !testCaseTracker.isCompleted() + + + !false + + testCaseTracker.isCompleted() @@ -7083,7 +6749,15 @@ there" true - + + + !testCaseTracker.enterSection( section1Name ) + + + !false + + +
@@ -7094,30 +6768,6 @@ there"
- - - !testCaseTracker.enterSection( section1Name ) - - - !false - - - - - !testCaseTracker.enterSection( section2Name ) - - - !false - - - - - !testCaseTracker.isCompleted() - - - !false - - testCaseTracker.enterSection( section1Name ) @@ -7166,7 +6816,7 @@ there" true - +
@@ -7177,46 +6827,6 @@ there"
- - - !testCaseTracker.enterSection( section1Name ) - - - !false - - - - - !testCaseTracker.isCompleted() - - - !false - - - - - testCaseTracker.enterSection( section1Name ) - - - true - - - - - !testCaseTracker.enterSection( section2Name ) - - - !false - - - - - !testCaseTracker.isCompleted() - - - !false - - testCaseTracker.enterSection( section1Name ) @@ -7233,6 +6843,14 @@ there" true + + + !testCaseTracker.isCompleted() + + + !false + + testCaseTracker.isCompleted() @@ -7241,11 +6859,11 @@ there" true - +
- + - + diff --git a/projects/SelfTest/SectionTrackerTests.cpp b/projects/SelfTest/SectionTrackerTests.cpp index eaf3d2a0..df0f8abf 100644 --- a/projects/SelfTest/SectionTrackerTests.cpp +++ b/projects/SelfTest/SectionTrackerTests.cpp @@ -38,13 +38,14 @@ TEST_CASE( "section tracking" ) { { TestCaseTracker::Guard guard( testCaseTracker ); - // Enter section? - no, not yet - CHECK_FALSE( testCaseTracker.enterSection( section1Name ) ); + // Enter section? - yes + CHECK( testCaseTracker.enterSection( section1Name ) ); CHECK_FALSE( testCaseTracker.isCompleted() ); + testCaseTracker.leaveSection(); - // Leave test case - incomplete (still need to visit section) + // Leave test case - now complete } - CHECK_FALSE( testCaseTracker.isCompleted() ); + CHECK( testCaseTracker.isCompleted() ); // ... @@ -52,13 +53,9 @@ TEST_CASE( "section tracking" ) { { TestCaseTracker::Guard guard( testCaseTracker ); - // Enter section? - yes - CHECK( testCaseTracker.enterSection( section1Name ) ); - - // Leave section and test case - now complete - testCaseTracker.leaveSection(); + // Enter section? - no - now complete + CHECK_FALSE( testCaseTracker.enterSection( section1Name ) ); } - CHECK( testCaseTracker.isCompleted() ); } SECTION( "test case with two consecutive sections" ) { @@ -67,27 +64,11 @@ TEST_CASE( "section tracking" ) { { TestCaseTracker::Guard guard( testCaseTracker ); - // Enter section 1? - no, not yet - CHECK_FALSE( testCaseTracker.enterSection( section1Name ) ); - - // Enter section 2? - no, not yet - CHECK_FALSE( testCaseTracker.enterSection( section2Name ) ); - - // Leave test case - incomplete (still need to visit sections) - } - CHECK_FALSE( testCaseTracker.isCompleted() ); - - // ... - - // Enter test case again - { - TestCaseTracker::Guard guard( testCaseTracker ); - // Enter section 1? - yes CHECK( testCaseTracker.enterSection( section1Name ) ); testCaseTracker.leaveSection(); - // Enter section 2? - no, not yet + // Enter section 2? - no - we just exected section 1 CHECK_FALSE( testCaseTracker.enterSection( section2Name ) ); // Leave test case - incomplete (still need to visit section 2) @@ -103,7 +84,7 @@ TEST_CASE( "section tracking" ) { // Enter section 1? - no, already done now CHECK_FALSE( testCaseTracker.enterSection( section1Name ) ); - // Enter section 2? - yes - finally + // Enter section 2? - yes CHECK( testCaseTracker.enterSection( section2Name ) ); testCaseTracker.leaveSection(); @@ -114,19 +95,6 @@ TEST_CASE( "section tracking" ) { SECTION( "test case with one section within another" ) { - // Enter test case - { - TestCaseTracker::Guard guard( testCaseTracker ); - - // Enter section 1? - no, not yet - CHECK_FALSE( testCaseTracker.enterSection( section1Name ) ); - - // Leave test case - incomplete (still need to visit sections) - } - CHECK_FALSE( testCaseTracker.isCompleted() ); - - // ... - // Enter test case again { TestCaseTracker::Guard guard( testCaseTracker ); @@ -134,26 +102,11 @@ TEST_CASE( "section tracking" ) { // Enter section 1? - yes CHECK( testCaseTracker.enterSection( section1Name ) ); - // Enter section 2? - no, not yet - CHECK_FALSE( testCaseTracker.enterSection( section2Name ) ); - - testCaseTracker.leaveSection(); // section 1 - incomplete (section 2) - - // Leave test case - incomplete - } - CHECK_FALSE( testCaseTracker.isCompleted() ); - - // ... - - // Enter test case again - { - TestCaseTracker::Guard guard( testCaseTracker ); - - // Enter section 1? - yes - so we can execute section 2 - CHECK( testCaseTracker.enterSection( section1Name ) ); - - // Enter section 2? - yes - finally + // Enter section 2? - yes CHECK( testCaseTracker.enterSection( section2Name ) ); + + CHECK_FALSE( testCaseTracker.isCompleted() ); + testCaseTracker.leaveSection(); // section 2 testCaseTracker.leaveSection(); // section 1 diff --git a/single_include/catch.hpp b/single_include/catch.hpp index 3b261aa5..57cbca0c 100644 --- a/single_include/catch.hpp +++ b/single_include/catch.hpp @@ -1,6 +1,6 @@ /* - * CATCH v1.0 build 38 (master branch) - * Generated: 2014-04-18 08:47:21.504017 + * CATCH v1.0 build 39 (master branch) + * Generated: 2014-04-21 18:50:19.658444 * ---------------------------------------------------------- * This file has been merged from multiple headers. Please don't edit it directly * Copyright (c) 2012 Two Blue Cubes Ltd. All rights reserved. @@ -4754,13 +4754,18 @@ namespace SectionTracking { RunState runState() const { return m_runState; } - void addChild( std::string const& childName ) { + TrackedSection* findChild( std::string const& childName ) { + TrackedSections::iterator it = m_children.find( childName ); + return it != m_children.end() + ? &it->second + : NULL; + } + TrackedSection* acquireChild( std::string const& childName ) { + if( TrackedSection* child = findChild( childName ) ) + return child; m_children.insert( std::make_pair( childName, TrackedSection( childName, this ) ) ); + return findChild( childName ); } - TrackedSection* getChild( std::string const& childName ) { - return &m_children.find( childName )->second; - } - void enter() { if( m_runState == NotStarted ) m_runState = Executing; @@ -4799,21 +4804,13 @@ namespace SectionTracking { {} bool enterSection( std::string const& name ) { - if( m_completedASectionThisRun ) + TrackedSection* child = m_currentSection->acquireChild( name ); + if( m_completedASectionThisRun || child->runState() == TrackedSection::Completed ) return false; - if( m_currentSection->runState() == TrackedSection::Executing ) { - m_currentSection->addChild( name ); - return false; - } - else { - TrackedSection* child = m_currentSection->getChild( name ); - if( child->runState() != TrackedSection::Completed ) { - m_currentSection = child; - m_currentSection->enter(); - return true; - } - return false; - } + + m_currentSection = child; + m_currentSection->enter(); + return true; } void leaveSection() { m_currentSection->leave(); @@ -4831,9 +4828,7 @@ namespace SectionTracking { class Guard { public: - Guard( TestCaseTracker& tracker ) - : m_tracker( tracker ) - { + Guard( TestCaseTracker& tracker ) : m_tracker( tracker ) { m_tracker.enterTestCase(); } ~Guard() { @@ -5117,8 +5112,8 @@ namespace Catch { } // If sections ended prematurely due to an exception we stored their // infos here so we can tear them down outside the unwind process. - for( std::vector::const_iterator it = m_unfinishedSections.begin(), - itEnd = m_unfinishedSections.end(); + for( std::vector::const_reverse_iterator it = m_unfinishedSections.rbegin(), + itEnd = m_unfinishedSections.rend(); it != itEnd; ++it ) sectionEnded( it->info, it->prevAssertions, it->durationInSeconds ); @@ -6702,7 +6697,7 @@ namespace Catch { namespace Catch { // These numbers are maintained by a script - Version libraryVersion( 1, 0, 38, "master" ); + Version libraryVersion( 1, 0, 39, "master" ); } // #included from: catch_message.hpp