Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorPhil Nash2013-07-25 08:07:55 +0100
committerPhil Nash2013-07-25 08:07:55 +0100
commit28d3881ff984488f3e85fc6d7834f1bae299aaef (patch)
treec8014f0dde021170118a3a971d84dc8c8a4584f8 /include
parentee647f509941321c84e73a8c9acc3963e35906a1 (diff)
downloadcatch3-28d3881ff984488f3e85fc6d7834f1bae299aaef.tar.gz
Merged TestCaseTracker and SectionTracker and introduced TestCaseTracker::Guard
Diffstat (limited to 'include')
-rw-r--r--include/internal/catch_runner_impl.hpp5
-rw-r--r--include/internal/catch_test_case_tracker.hpp67
2 files changed, 30 insertions, 42 deletions
diff --git a/include/internal/catch_runner_impl.hpp b/include/internal/catch_runner_impl.hpp
index 9b3d7c43..cf971539 100644
--- a/include/internal/catch_runner_impl.hpp
+++ b/include/internal/catch_runner_impl.hpp
@@ -269,7 +269,7 @@ namespace Catch {
m_reporter->sectionStarting( testCaseSection );
try {
m_lastAssertionInfo = AssertionInfo( "TEST_CASE", testCaseInfo.lineInfo, "", ResultDisposition::Normal );
- m_testCaseTracker->enter();
+ TestCaseTracker::Guard guard( *m_testCaseTracker );
if( m_reporter->getPreferences().shouldRedirectStdOut ) {
StreamRedirect coutRedir( std::cout, redirectedCout );
@@ -279,14 +279,11 @@ namespace Catch {
else {
m_activeTestCase->invoke();
}
- m_testCaseTracker->leave();
}
catch( TestFailureException& ) {
// This just means the test was aborted due to failure
- m_testCaseTracker->leave(); // !TBD: RAII
}
catch(...) {
- m_testCaseTracker->leave();
ExpressionResultBuilder exResult( ResultWas::ThrewException );
exResult << translateActiveException();
actOnCurrentResult( exResult.buildResult( m_lastAssertionInfo ) );
diff --git a/include/internal/catch_test_case_tracker.hpp b/include/internal/catch_test_case_tracker.hpp
index e0298d4e..f12d8868 100644
--- a/include/internal/catch_test_case_tracker.hpp
+++ b/include/internal/catch_test_case_tracker.hpp
@@ -69,13 +69,14 @@ namespace SectionTracking {
};
- class SectionTracker {
+ class TestCaseTracker {
public:
- SectionTracker( TrackedSection& testCase )
- : m_currentSection( &testCase ),
+ TestCaseTracker( std::string const& testCaseName )
+ : m_testCase( testCaseName, NULL ),
+ m_currentSection( &m_testCase ),
m_completedASectionThisRun( false )
{}
-
+
bool enterSection( std::string const& name ) {
if( m_completedASectionThisRun )
return false;
@@ -93,7 +94,6 @@ namespace SectionTracking {
return false;
}
}
-
void leaveSection() {
m_currentSection->leave();
m_currentSection = m_currentSection->getParent();
@@ -101,49 +101,40 @@ namespace SectionTracking {
m_completedASectionThisRun = true;
}
- bool currentSectinHasChildren() const {
+ bool currentSectionHasChildren() const {
return m_currentSection->hasChildren();
}
+ bool isCompleted() const {
+ return m_testCase.runState() == TrackedSection::Completed;
+ }
- private:
- TrackedSection* m_currentSection;
- bool m_completedASectionThisRun;
- };
-
- class TestCaseTracker {
- public:
-
- TestCaseTracker( std::string const& testCaseName )
- : m_testCase( testCaseName, NULL ),
- m_sections( m_testCase )
- {}
+ class Guard {
+ public:
+ Guard( TestCaseTracker& tracker )
+ : m_tracker( tracker )
+ {
+ m_tracker.enterTestCase();
+ }
+ ~Guard() {
+ m_tracker.leaveTestCase();
+ }
+ private:
+ TestCaseTracker& m_tracker;
+ };
- void enter() {
- m_sections = SectionTracker( m_testCase );
+ private:
+ void enterTestCase() {
+ m_currentSection = &m_testCase;
+ m_completedASectionThisRun = false;
m_testCase.enter();
}
- void leave() {
+ void leaveTestCase() {
m_testCase.leave();
}
- bool enterSection( std::string const& name ) {
- return m_sections.enterSection( name );
- }
- void leaveSection() {
- m_sections.leaveSection();
- }
-
- bool isCompleted() const {
- return m_testCase.runState() == TrackedSection::Completed;
- }
-
- bool currentSectionHasChildren() const {
- return m_sections.currentSectinHasChildren();
- }
-
- private:
TrackedSection m_testCase;
- SectionTracker m_sections;
+ TrackedSection* m_currentSection;
+ bool m_completedASectionThisRun;
};
} // namespace SectionTracking