2012-05-05 20:32:52 +02:00
|
|
|
/*
|
|
|
|
* Created by Phil Nash on 4/5/2012
|
|
|
|
* Copyright 2012 Two Blue Cubes Ltd. All rights reserved.
|
|
|
|
*
|
|
|
|
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
|
|
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
*/
|
|
|
|
#ifndef TWOBLUECUBES_INTERNAL_CATCH_RUNNING_TEST_HPP_INCLUDED
|
|
|
|
#define TWOBLUECUBES_INTERNAL_CATCH_RUNNING_TEST_HPP_INCLUDED
|
|
|
|
|
|
|
|
#include "catch_test_case_info.hpp"
|
|
|
|
#include "catch_section_info.hpp"
|
|
|
|
|
2012-05-16 00:58:23 +02:00
|
|
|
namespace Catch {
|
|
|
|
|
|
|
|
class RunningTest {
|
|
|
|
|
|
|
|
enum RunStatus {
|
2012-05-05 20:32:52 +02:00
|
|
|
NothingRun,
|
|
|
|
EncounteredASection,
|
|
|
|
RanAtLeastOneSection,
|
|
|
|
RanToCompletionWithSections,
|
|
|
|
RanToCompletionWithNoSections
|
|
|
|
};
|
|
|
|
|
|
|
|
public:
|
2012-05-16 00:58:23 +02:00
|
|
|
explicit RunningTest( const TestCaseInfo* info = NULL )
|
2012-05-05 20:32:52 +02:00
|
|
|
: m_info( info ),
|
|
|
|
m_runStatus( RanAtLeastOneSection ),
|
|
|
|
m_currentSection( &m_rootSection ),
|
|
|
|
m_changed( false )
|
2012-05-16 00:58:23 +02:00
|
|
|
{}
|
2012-05-05 20:32:52 +02:00
|
|
|
|
2012-05-16 00:58:23 +02:00
|
|
|
bool wasSectionSeen() const {
|
2012-05-05 20:32:52 +02:00
|
|
|
return m_runStatus == RanAtLeastOneSection ||
|
|
|
|
m_runStatus == RanToCompletionWithSections;
|
|
|
|
}
|
|
|
|
|
2012-05-16 00:58:23 +02:00
|
|
|
void reset() {
|
2012-05-05 20:32:52 +02:00
|
|
|
m_runStatus = NothingRun;
|
|
|
|
m_changed = false;
|
|
|
|
m_lastSectionToRun = NULL;
|
|
|
|
}
|
|
|
|
|
2012-05-16 00:58:23 +02:00
|
|
|
void ranToCompletion() {
|
2012-05-05 20:32:52 +02:00
|
|
|
if( m_runStatus == RanAtLeastOneSection ||
|
2012-05-16 00:58:23 +02:00
|
|
|
m_runStatus == EncounteredASection ) {
|
2012-05-05 20:32:52 +02:00
|
|
|
m_runStatus = RanToCompletionWithSections;
|
2012-05-16 00:58:23 +02:00
|
|
|
if( m_lastSectionToRun ) {
|
2012-05-05 20:32:52 +02:00
|
|
|
m_lastSectionToRun->ranToCompletion();
|
|
|
|
m_changed = true;
|
|
|
|
}
|
|
|
|
}
|
2012-05-16 00:58:23 +02:00
|
|
|
else {
|
2012-05-05 20:32:52 +02:00
|
|
|
m_runStatus = RanToCompletionWithNoSections;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-16 00:58:23 +02:00
|
|
|
bool addSection( const std::string& name ) {
|
2012-05-05 20:32:52 +02:00
|
|
|
if( m_runStatus == NothingRun )
|
|
|
|
m_runStatus = EncounteredASection;
|
|
|
|
|
|
|
|
SectionInfo* thisSection = m_currentSection->findSubSection( name );
|
2012-05-16 00:58:23 +02:00
|
|
|
if( !thisSection ) {
|
2012-05-05 20:32:52 +02:00
|
|
|
thisSection = m_currentSection->addSubSection( name );
|
|
|
|
m_changed = true;
|
|
|
|
}
|
|
|
|
|
2012-05-16 00:58:23 +02:00
|
|
|
if( !wasSectionSeen() && thisSection->shouldRun() ) {
|
2012-05-05 20:32:52 +02:00
|
|
|
m_currentSection = thisSection;
|
|
|
|
m_lastSectionToRun = NULL;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-05-16 00:58:23 +02:00
|
|
|
void endSection( const std::string& ) {
|
|
|
|
if( m_currentSection->ran() ) {
|
2012-05-05 20:32:52 +02:00
|
|
|
m_runStatus = RanAtLeastOneSection;
|
|
|
|
m_changed = true;
|
|
|
|
}
|
2012-05-16 00:58:23 +02:00
|
|
|
else if( m_runStatus == EncounteredASection ) {
|
2012-05-05 20:32:52 +02:00
|
|
|
m_runStatus = RanAtLeastOneSection;
|
|
|
|
m_lastSectionToRun = m_currentSection;
|
|
|
|
}
|
|
|
|
m_currentSection = m_currentSection->getParent();
|
|
|
|
}
|
|
|
|
|
2012-05-16 00:58:23 +02:00
|
|
|
const TestCaseInfo& getTestCaseInfo() const {
|
2012-05-05 20:32:52 +02:00
|
|
|
return *m_info;
|
|
|
|
}
|
|
|
|
|
2012-05-16 00:58:23 +02:00
|
|
|
bool hasUntestedSections() const {
|
2012-05-05 20:32:52 +02:00
|
|
|
return m_runStatus == RanAtLeastOneSection ||
|
|
|
|
( m_rootSection.hasUntestedSections() && m_changed );
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
const TestCaseInfo* m_info;
|
|
|
|
RunStatus m_runStatus;
|
|
|
|
SectionInfo m_rootSection;
|
|
|
|
SectionInfo* m_currentSection;
|
|
|
|
SectionInfo* m_lastSectionToRun;
|
|
|
|
bool m_changed;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // TWOBLUECUBES_INTERNAL_CATCH_RUNNING_TEST_HPP_INCLUDED
|