mirror of
https://github.com/catchorg/Catch2.git
synced 2025-08-01 12:55:40 +02:00
Fixed section ordering issue
If a branch section completes without running any inner sections it will no run subsequent sections (until the next isolated run).
This commit is contained in:
@@ -19,6 +19,7 @@
|
||||
#include "catch_test_case_info.hpp"
|
||||
#include "catch_capture.hpp"
|
||||
#include "catch_totals.hpp"
|
||||
#include "catch_running_test.hpp"
|
||||
|
||||
#include <set>
|
||||
#include <string>
|
||||
@@ -57,237 +58,6 @@ namespace Catch
|
||||
std::string& m_targetString;
|
||||
};
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
class SectionInfo
|
||||
{
|
||||
public:
|
||||
enum Status
|
||||
{
|
||||
Root,
|
||||
Unknown,
|
||||
NonLeaf,
|
||||
TestedLeaf
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
SectionInfo
|
||||
(
|
||||
SectionInfo* parent
|
||||
)
|
||||
: m_status( Unknown ),
|
||||
m_parent( parent )
|
||||
{
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
SectionInfo
|
||||
()
|
||||
: m_status( Root ),
|
||||
m_parent( NULL )
|
||||
{
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
~SectionInfo
|
||||
()
|
||||
{
|
||||
deleteAllValues( m_subSections );
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
bool shouldRun
|
||||
()
|
||||
const
|
||||
{
|
||||
return m_status != TestedLeaf;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
bool ran
|
||||
()
|
||||
{
|
||||
if( m_status != NonLeaf )
|
||||
{
|
||||
m_status = TestedLeaf;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
SectionInfo* findSubSection
|
||||
(
|
||||
const std::string& name
|
||||
)
|
||||
{
|
||||
std::map<std::string, SectionInfo*>::const_iterator it = m_subSections.find( name );
|
||||
return it != m_subSections.end()
|
||||
? it->second
|
||||
: NULL;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
SectionInfo* addSubSection
|
||||
(
|
||||
const std::string& name
|
||||
)
|
||||
{
|
||||
SectionInfo* subSection = new SectionInfo( this );
|
||||
m_subSections.insert( std::make_pair( name, subSection ) );
|
||||
m_status = NonLeaf;
|
||||
return subSection;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
SectionInfo* getParent
|
||||
()
|
||||
{
|
||||
return m_parent;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
bool hasUntestedSections
|
||||
()
|
||||
const
|
||||
{
|
||||
if( m_status == Unknown )
|
||||
return true;
|
||||
|
||||
std::map<std::string, SectionInfo*>::const_iterator it = m_subSections.begin();
|
||||
std::map<std::string, SectionInfo*>::const_iterator itEnd = m_subSections.end();
|
||||
for(; it != itEnd; ++it )
|
||||
{
|
||||
if( it->second->hasUntestedSections() )
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private:
|
||||
Status m_status;
|
||||
std::map<std::string, SectionInfo*> m_subSections;
|
||||
SectionInfo* m_parent;
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class RunningTest
|
||||
{
|
||||
enum RunStatus
|
||||
{
|
||||
NothingRun,
|
||||
EncounteredASection,
|
||||
RanAtLeastOneSection,
|
||||
RanToCompletionWithSections,
|
||||
RanToCompletionWithNoSections
|
||||
};
|
||||
|
||||
public:
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
explicit RunningTest
|
||||
(
|
||||
const TestCaseInfo* info = NULL
|
||||
)
|
||||
: m_info( info ),
|
||||
m_runStatus( RanAtLeastOneSection ),
|
||||
m_currentSection( &m_rootSection ),
|
||||
m_changed( false )
|
||||
{
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
bool wasSectionSeen
|
||||
()
|
||||
const
|
||||
{
|
||||
return m_runStatus == RanAtLeastOneSection ||
|
||||
m_runStatus == RanToCompletionWithSections;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
void reset
|
||||
()
|
||||
{
|
||||
m_runStatus = NothingRun;
|
||||
m_changed = false;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
void ranToCompletion
|
||||
()
|
||||
{
|
||||
m_runStatus = m_runStatus == RanAtLeastOneSection ||
|
||||
m_runStatus == EncounteredASection
|
||||
? RanToCompletionWithSections
|
||||
: RanToCompletionWithNoSections;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
bool addSection
|
||||
(
|
||||
const std::string& name
|
||||
)
|
||||
{
|
||||
if( m_runStatus == NothingRun )
|
||||
m_runStatus = EncounteredASection;
|
||||
|
||||
SectionInfo* thisSection = m_currentSection->findSubSection( name );
|
||||
if( !thisSection )
|
||||
{
|
||||
thisSection = m_currentSection->addSubSection( name );
|
||||
m_changed = true;
|
||||
}
|
||||
|
||||
if( !wasSectionSeen() && thisSection->shouldRun() )
|
||||
{
|
||||
m_currentSection = thisSection;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
void endSection
|
||||
(
|
||||
const std::string&
|
||||
)
|
||||
{
|
||||
if( m_currentSection->ran() )
|
||||
{
|
||||
m_runStatus = RanAtLeastOneSection;
|
||||
m_changed = true;
|
||||
}
|
||||
m_currentSection = m_currentSection->getParent();
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
const TestCaseInfo& getTestCaseInfo
|
||||
()
|
||||
const
|
||||
{
|
||||
return *m_info;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
bool hasUntestedSections
|
||||
()
|
||||
const
|
||||
{
|
||||
return m_runStatus == RanAtLeastOneSection ||
|
||||
( m_rootSection.hasUntestedSections() && m_changed );
|
||||
}
|
||||
|
||||
private:
|
||||
const TestCaseInfo* m_info;
|
||||
RunStatus m_runStatus;
|
||||
SectionInfo m_rootSection;
|
||||
SectionInfo* m_currentSection;
|
||||
bool m_changed;
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
class Runner : public IResultCapture, public IRunner
|
||||
|
150
include/internal/catch_running_test.hpp
Normal file
150
include/internal/catch_running_test.hpp
Normal file
@@ -0,0 +1,150 @@
|
||||
/*
|
||||
* 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"
|
||||
|
||||
namespace Catch
|
||||
{
|
||||
class RunningTest
|
||||
{
|
||||
enum RunStatus
|
||||
{
|
||||
NothingRun,
|
||||
EncounteredASection,
|
||||
RanAtLeastOneSection,
|
||||
RanToCompletionWithSections,
|
||||
RanToCompletionWithNoSections
|
||||
};
|
||||
|
||||
public:
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
explicit RunningTest
|
||||
(
|
||||
const TestCaseInfo* info = NULL
|
||||
)
|
||||
: m_info( info ),
|
||||
m_runStatus( RanAtLeastOneSection ),
|
||||
m_currentSection( &m_rootSection ),
|
||||
m_changed( false )
|
||||
{
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
bool wasSectionSeen
|
||||
()
|
||||
const
|
||||
{
|
||||
return m_runStatus == RanAtLeastOneSection ||
|
||||
m_runStatus == RanToCompletionWithSections;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
void reset
|
||||
()
|
||||
{
|
||||
m_runStatus = NothingRun;
|
||||
m_changed = false;
|
||||
m_lastSectionToRun = NULL;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
void ranToCompletion
|
||||
()
|
||||
{
|
||||
if( m_runStatus == RanAtLeastOneSection ||
|
||||
m_runStatus == EncounteredASection )
|
||||
{
|
||||
m_runStatus = RanToCompletionWithSections;
|
||||
if( m_lastSectionToRun )
|
||||
{
|
||||
m_lastSectionToRun->ranToCompletion();
|
||||
m_changed = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_runStatus = RanToCompletionWithNoSections;
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
bool addSection
|
||||
(
|
||||
const std::string& name
|
||||
)
|
||||
{
|
||||
if( m_runStatus == NothingRun )
|
||||
m_runStatus = EncounteredASection;
|
||||
|
||||
SectionInfo* thisSection = m_currentSection->findSubSection( name );
|
||||
if( !thisSection )
|
||||
{
|
||||
thisSection = m_currentSection->addSubSection( name );
|
||||
m_changed = true;
|
||||
}
|
||||
|
||||
if( !wasSectionSeen() && thisSection->shouldRun() )
|
||||
{
|
||||
m_currentSection = thisSection;
|
||||
m_lastSectionToRun = NULL;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
void endSection
|
||||
(
|
||||
const std::string&
|
||||
)
|
||||
{
|
||||
if( m_currentSection->ran() )
|
||||
{
|
||||
m_runStatus = RanAtLeastOneSection;
|
||||
m_changed = true;
|
||||
}
|
||||
else if( m_runStatus == EncounteredASection )
|
||||
{
|
||||
m_runStatus = RanAtLeastOneSection;
|
||||
m_lastSectionToRun = m_currentSection;
|
||||
// m_changed = true;
|
||||
}
|
||||
m_currentSection = m_currentSection->getParent();
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
const TestCaseInfo& getTestCaseInfo
|
||||
()
|
||||
const
|
||||
{
|
||||
return *m_info;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
bool hasUntestedSections
|
||||
()
|
||||
const
|
||||
{
|
||||
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
|
142
include/internal/catch_section_info.hpp
Normal file
142
include/internal/catch_section_info.hpp
Normal file
@@ -0,0 +1,142 @@
|
||||
/*
|
||||
* 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_SECTION_INFO_HPP_INCLUDED
|
||||
#define TWOBLUECUBES_INTERNAL_CATCH_SECTION_INFO_HPP_INCLUDED
|
||||
|
||||
#include "catch_common.h"
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
namespace Catch
|
||||
{
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
class SectionInfo
|
||||
{
|
||||
public:
|
||||
enum Status
|
||||
{
|
||||
Root,
|
||||
Unknown,
|
||||
Branch,
|
||||
TestedBranch,
|
||||
TestedLeaf
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
SectionInfo
|
||||
(
|
||||
SectionInfo* parent
|
||||
)
|
||||
: m_status( Unknown ),
|
||||
m_parent( parent )
|
||||
{
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
SectionInfo
|
||||
()
|
||||
: m_status( Root ),
|
||||
m_parent( NULL )
|
||||
{
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
~SectionInfo
|
||||
()
|
||||
{
|
||||
deleteAllValues( m_subSections );
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
bool shouldRun
|
||||
()
|
||||
const
|
||||
{
|
||||
return m_status < TestedBranch;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
bool ran
|
||||
()
|
||||
{
|
||||
if( m_status < Branch )
|
||||
{
|
||||
m_status = TestedLeaf;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
void ranToCompletion
|
||||
()
|
||||
{
|
||||
if( m_status == Branch && !hasUntestedSections() )
|
||||
{
|
||||
m_status = TestedBranch;
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
SectionInfo* findSubSection
|
||||
(
|
||||
const std::string& name
|
||||
)
|
||||
{
|
||||
std::map<std::string, SectionInfo*>::const_iterator it = m_subSections.find( name );
|
||||
return it != m_subSections.end()
|
||||
? it->second
|
||||
: NULL;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
SectionInfo* addSubSection
|
||||
(
|
||||
const std::string& name
|
||||
)
|
||||
{
|
||||
SectionInfo* subSection = new SectionInfo( this );
|
||||
m_subSections.insert( std::make_pair( name, subSection ) );
|
||||
m_status = Branch;
|
||||
return subSection;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
SectionInfo* getParent
|
||||
()
|
||||
{
|
||||
return m_parent;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
bool hasUntestedSections
|
||||
()
|
||||
const
|
||||
{
|
||||
if( m_status == Unknown )
|
||||
return true;
|
||||
|
||||
std::map<std::string, SectionInfo*>::const_iterator it = m_subSections.begin();
|
||||
std::map<std::string, SectionInfo*>::const_iterator itEnd = m_subSections.end();
|
||||
for(; it != itEnd; ++it )
|
||||
{
|
||||
if( it->second->hasUntestedSections() )
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private:
|
||||
Status m_status;
|
||||
std::map<std::string, SectionInfo*> m_subSections;
|
||||
SectionInfo* m_parent;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // TWOBLUECUBES_INTERNAL_CATCH_SECTION_INFO_HPP_INCLUDED
|
@@ -18,7 +18,6 @@
|
||||
#include <set>
|
||||
#include <sstream>
|
||||
|
||||
#include <iostream> // !TBD DBG
|
||||
namespace Catch
|
||||
{
|
||||
class TestRegistry : public ITestCaseRegistry
|
||||
|
Reference in New Issue
Block a user