mirror of
https://github.com/catchorg/Catch2.git
synced 2025-05-31 08:57:58 +00:00
Standardize header names and file locations
This is both a really big and a really small commit. It is small in that it only contains renaming, moving and modification of include directives caused by this. It is really big in the obvious way of touching something like 200 files. The new rules for naming files is simple: headers use the `.hpp` extension. The rules for physical file layout is still kinda in progress, but the basics are also simple: * Significant parts of functionality get their own subfolder * Benchmarking is in `catch2/benchmark` * Matchers are in `catch2/matchers` * Generators are in `catch2/generators` * Reporters are in `catch2/reporters` * Baseline testing facilities are in `catch2/` * Various top level folders also contain `internal` subfolder, with files that users probably do not want to include directly, at least not until they have to write something like their own reporter. * The exact files in these subfolders is likely to change later on Note that while some includes were cleaned up in this commit, it is only the low hanging fruit and further cleanup using automatic tooling will happen later. Also note that various include guards, copyright notices and file headers will also be standardized later, rather than in this commit.
This commit is contained in:
parent
3836aa9ceb
commit
e1e6872c4c
204 changed files with 668 additions and 632 deletions
247
src/catch2/internal/catch_test_case_tracker.cpp
Normal file
247
src/catch2/internal/catch_test_case_tracker.cpp
Normal file
|
@ -0,0 +1,247 @@
|
|||
/*
|
||||
* Created by Martin on 19/07/2017
|
||||
*
|
||||
* 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)
|
||||
*/
|
||||
|
||||
#include <catch2/internal/catch_test_case_tracker.hpp>
|
||||
|
||||
#include <catch2/internal/catch_enforce.hpp>
|
||||
#include <catch2/internal/catch_string_manip.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <memory>
|
||||
#include <sstream>
|
||||
|
||||
#if defined(__clang__)
|
||||
# pragma clang diagnostic push
|
||||
# pragma clang diagnostic ignored "-Wexit-time-destructors"
|
||||
#endif
|
||||
|
||||
namespace Catch {
|
||||
namespace TestCaseTracking {
|
||||
|
||||
NameAndLocation::NameAndLocation( std::string const& _name, SourceLineInfo const& _location )
|
||||
: name( _name ),
|
||||
location( _location )
|
||||
{}
|
||||
|
||||
|
||||
ITracker::~ITracker() = default;
|
||||
|
||||
|
||||
ITracker& TrackerContext::startRun() {
|
||||
m_rootTracker = std::make_shared<SectionTracker>( NameAndLocation( "{root}", CATCH_INTERNAL_LINEINFO ), *this, nullptr );
|
||||
m_currentTracker = nullptr;
|
||||
m_runState = Executing;
|
||||
return *m_rootTracker;
|
||||
}
|
||||
|
||||
void TrackerContext::endRun() {
|
||||
m_rootTracker.reset();
|
||||
m_currentTracker = nullptr;
|
||||
m_runState = NotStarted;
|
||||
}
|
||||
|
||||
void TrackerContext::startCycle() {
|
||||
m_currentTracker = m_rootTracker.get();
|
||||
m_runState = Executing;
|
||||
}
|
||||
void TrackerContext::completeCycle() {
|
||||
m_runState = CompletedCycle;
|
||||
}
|
||||
|
||||
bool TrackerContext::completedCycle() const {
|
||||
return m_runState == CompletedCycle;
|
||||
}
|
||||
ITracker& TrackerContext::currentTracker() {
|
||||
return *m_currentTracker;
|
||||
}
|
||||
void TrackerContext::setCurrentTracker( ITracker* tracker ) {
|
||||
m_currentTracker = tracker;
|
||||
}
|
||||
|
||||
|
||||
TrackerBase::TrackerBase( NameAndLocation const& nameAndLocation, TrackerContext& ctx, ITracker* parent )
|
||||
: m_nameAndLocation( nameAndLocation ),
|
||||
m_ctx( ctx ),
|
||||
m_parent( parent )
|
||||
{}
|
||||
|
||||
NameAndLocation const& TrackerBase::nameAndLocation() const {
|
||||
return m_nameAndLocation;
|
||||
}
|
||||
bool TrackerBase::isComplete() const {
|
||||
return m_runState == CompletedSuccessfully || m_runState == Failed;
|
||||
}
|
||||
bool TrackerBase::isSuccessfullyCompleted() const {
|
||||
return m_runState == CompletedSuccessfully;
|
||||
}
|
||||
bool TrackerBase::isOpen() const {
|
||||
return m_runState != NotStarted && !isComplete();
|
||||
}
|
||||
bool TrackerBase::hasChildren() const {
|
||||
return !m_children.empty();
|
||||
}
|
||||
|
||||
|
||||
void TrackerBase::addChild( ITrackerPtr const& child ) {
|
||||
m_children.push_back( child );
|
||||
}
|
||||
|
||||
ITrackerPtr TrackerBase::findChild( NameAndLocation const& nameAndLocation ) {
|
||||
auto it = std::find_if( m_children.begin(), m_children.end(),
|
||||
[&nameAndLocation]( ITrackerPtr const& tracker ){
|
||||
return
|
||||
tracker->nameAndLocation().location == nameAndLocation.location &&
|
||||
tracker->nameAndLocation().name == nameAndLocation.name;
|
||||
} );
|
||||
return( it != m_children.end() )
|
||||
? *it
|
||||
: nullptr;
|
||||
}
|
||||
ITracker& TrackerBase::parent() {
|
||||
assert( m_parent ); // Should always be non-null except for root
|
||||
return *m_parent;
|
||||
}
|
||||
|
||||
void TrackerBase::openChild() {
|
||||
if( m_runState != ExecutingChildren ) {
|
||||
m_runState = ExecutingChildren;
|
||||
if( m_parent )
|
||||
m_parent->openChild();
|
||||
}
|
||||
}
|
||||
|
||||
bool TrackerBase::isSectionTracker() const { return false; }
|
||||
bool TrackerBase::isGeneratorTracker() const { return false; }
|
||||
|
||||
void TrackerBase::open() {
|
||||
m_runState = Executing;
|
||||
moveToThis();
|
||||
if( m_parent )
|
||||
m_parent->openChild();
|
||||
}
|
||||
|
||||
void TrackerBase::close() {
|
||||
|
||||
// Close any still open children (e.g. generators)
|
||||
while( &m_ctx.currentTracker() != this )
|
||||
m_ctx.currentTracker().close();
|
||||
|
||||
switch( m_runState ) {
|
||||
case NeedsAnotherRun:
|
||||
break;
|
||||
|
||||
case Executing:
|
||||
m_runState = CompletedSuccessfully;
|
||||
break;
|
||||
case ExecutingChildren:
|
||||
if( std::all_of(m_children.begin(), m_children.end(), [](ITrackerPtr const& t){ return t->isComplete(); }) )
|
||||
m_runState = CompletedSuccessfully;
|
||||
break;
|
||||
|
||||
case NotStarted:
|
||||
case CompletedSuccessfully:
|
||||
case Failed:
|
||||
CATCH_INTERNAL_ERROR( "Illogical state: " << m_runState );
|
||||
|
||||
default:
|
||||
CATCH_INTERNAL_ERROR( "Unknown state: " << m_runState );
|
||||
}
|
||||
moveToParent();
|
||||
m_ctx.completeCycle();
|
||||
}
|
||||
void TrackerBase::fail() {
|
||||
m_runState = Failed;
|
||||
if( m_parent )
|
||||
m_parent->markAsNeedingAnotherRun();
|
||||
moveToParent();
|
||||
m_ctx.completeCycle();
|
||||
}
|
||||
void TrackerBase::markAsNeedingAnotherRun() {
|
||||
m_runState = NeedsAnotherRun;
|
||||
}
|
||||
|
||||
void TrackerBase::moveToParent() {
|
||||
assert( m_parent );
|
||||
m_ctx.setCurrentTracker( m_parent );
|
||||
}
|
||||
void TrackerBase::moveToThis() {
|
||||
m_ctx.setCurrentTracker( this );
|
||||
}
|
||||
|
||||
SectionTracker::SectionTracker( NameAndLocation const& nameAndLocation, TrackerContext& ctx, ITracker* parent )
|
||||
: TrackerBase( nameAndLocation, ctx, parent ),
|
||||
m_trimmed_name(trim(nameAndLocation.name))
|
||||
{
|
||||
if( parent ) {
|
||||
while( !parent->isSectionTracker() )
|
||||
parent = &parent->parent();
|
||||
|
||||
SectionTracker& parentSection = static_cast<SectionTracker&>( *parent );
|
||||
addNextFilters( parentSection.m_filters );
|
||||
}
|
||||
}
|
||||
|
||||
bool SectionTracker::isComplete() const {
|
||||
bool complete = true;
|
||||
|
||||
if ((m_filters.empty() || m_filters[0] == "")
|
||||
|| std::find(m_filters.begin(), m_filters.end(), m_trimmed_name) != m_filters.end()) {
|
||||
complete = TrackerBase::isComplete();
|
||||
}
|
||||
return complete;
|
||||
}
|
||||
|
||||
bool SectionTracker::isSectionTracker() const { return true; }
|
||||
|
||||
SectionTracker& SectionTracker::acquire( TrackerContext& ctx, NameAndLocation const& nameAndLocation ) {
|
||||
std::shared_ptr<SectionTracker> section;
|
||||
|
||||
ITracker& currentTracker = ctx.currentTracker();
|
||||
if( ITrackerPtr childTracker = currentTracker.findChild( nameAndLocation ) ) {
|
||||
assert( childTracker );
|
||||
assert( childTracker->isSectionTracker() );
|
||||
section = std::static_pointer_cast<SectionTracker>( childTracker );
|
||||
}
|
||||
else {
|
||||
section = std::make_shared<SectionTracker>( nameAndLocation, ctx, ¤tTracker );
|
||||
currentTracker.addChild( section );
|
||||
}
|
||||
if( !ctx.completedCycle() )
|
||||
section->tryOpen();
|
||||
return *section;
|
||||
}
|
||||
|
||||
void SectionTracker::tryOpen() {
|
||||
if( !isComplete() )
|
||||
open();
|
||||
}
|
||||
|
||||
void SectionTracker::addInitialFilters( std::vector<std::string> const& filters ) {
|
||||
if( !filters.empty() ) {
|
||||
m_filters.reserve( m_filters.size() + filters.size() + 2 );
|
||||
m_filters.emplace_back(""); // Root - should never be consulted
|
||||
m_filters.emplace_back(""); // Test Case - not a section filter
|
||||
m_filters.insert( m_filters.end(), filters.begin(), filters.end() );
|
||||
}
|
||||
}
|
||||
void SectionTracker::addNextFilters( std::vector<std::string> const& filters ) {
|
||||
if( filters.size() > 1 )
|
||||
m_filters.insert( m_filters.end(), filters.begin()+1, filters.end() );
|
||||
}
|
||||
|
||||
} // namespace TestCaseTracking
|
||||
|
||||
using TestCaseTracking::ITracker;
|
||||
using TestCaseTracking::TrackerContext;
|
||||
using TestCaseTracking::SectionTracker;
|
||||
|
||||
} // namespace Catch
|
||||
|
||||
#if defined(__clang__)
|
||||
# pragma clang diagnostic pop
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue