mirror of https://github.com/catchorg/Catch2.git
Moar reformatting
This commit is contained in:
parent
d0be9ed5d9
commit
c67a7eef2b
|
@ -1,27 +1,17 @@
|
|||
/*
|
||||
* catch_commandline.hpp
|
||||
* Catch
|
||||
*
|
||||
* Created by Phil on 02/11/2010.
|
||||
* Copyright 2010 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_CATCH_COMMANDLINE_HPP_INCLUDED
|
||||
#define TWOBLUECUBES_CATCH_COMMANDLINE_HPP_INCLUDED
|
||||
|
||||
#include "catch_config.hpp"
|
||||
#include "catch_runner_impl.hpp"
|
||||
|
||||
namespace Catch
|
||||
{
|
||||
// !TBD: This could be refactored to be more "declarative"
|
||||
// have a table up front that relates the mode, option strings, # arguments, names of arguments
|
||||
// - may not be worth it at this scale
|
||||
|
||||
namespace Catch {
|
||||
// -l, --list tests [xml] lists available tests (optionally in xml)
|
||||
// -l, --list reporters [xml] lists available reports (optionally in xml)
|
||||
// -l, --list all [xml] lists available tests and reports (optionally in xml)
|
||||
|
@ -31,10 +21,9 @@ namespace Catch
|
|||
// -s, --success report successful cases too
|
||||
// -b, --break breaks into debugger on test failure
|
||||
// -n, --name specifies an optional name for the test run
|
||||
class ArgParser : NonCopyable
|
||||
{
|
||||
enum Mode
|
||||
{
|
||||
class ArgParser : NonCopyable {
|
||||
|
||||
enum Mode {
|
||||
modeNone,
|
||||
modeList,
|
||||
modeTest,
|
||||
|
@ -49,20 +38,12 @@ namespace Catch
|
|||
};
|
||||
|
||||
public:
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
ArgParser
|
||||
(
|
||||
int argc,
|
||||
char * const argv[],
|
||||
Config& config
|
||||
)
|
||||
ArgParser ( int argc, char * const argv[], Config& config )
|
||||
: m_mode( modeNone ),
|
||||
m_config( config )
|
||||
{
|
||||
for( int i=1; i < argc; ++i )
|
||||
{
|
||||
if( argv[i][0] == '-' )
|
||||
{
|
||||
m_config( config ) {
|
||||
|
||||
for( int i=1; i < argc; ++i ) {
|
||||
if( argv[i][0] == '-' ) {
|
||||
std::string cmd = ( argv[i] );
|
||||
if( cmd == "-l" || cmd == "--list" )
|
||||
changeMode( cmd, modeList );
|
||||
|
@ -81,8 +62,7 @@ namespace Catch
|
|||
else if( cmd == "-h" || cmd == "-?" || cmd == "--help" )
|
||||
changeMode( cmd, modeHelp );
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
m_args.push_back( argv[i] );
|
||||
}
|
||||
if( m_mode == modeError )
|
||||
|
@ -92,15 +72,11 @@ namespace Catch
|
|||
}
|
||||
|
||||
private:
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
std::string argsAsString
|
||||
()
|
||||
{
|
||||
std::string argsAsString() {
|
||||
std::ostringstream oss;
|
||||
std::vector<std::string>::const_iterator it = m_args.begin();
|
||||
std::vector<std::string>::const_iterator itEnd = m_args.end();
|
||||
for( bool first = true; it != itEnd; ++it, first = false )
|
||||
{
|
||||
for( bool first = true; it != itEnd; ++it, first = false ) {
|
||||
if( !first )
|
||||
oss << " ";
|
||||
oss << *it;
|
||||
|
@ -108,30 +84,20 @@ namespace Catch
|
|||
return oss.str();
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
void changeMode
|
||||
(
|
||||
const std::string& cmd,
|
||||
Mode mode
|
||||
)
|
||||
{
|
||||
void changeMode( const std::string& cmd, Mode mode ) {
|
||||
m_command = cmd;
|
||||
switch( m_mode )
|
||||
{
|
||||
switch( m_mode ) {
|
||||
case modeNone:
|
||||
if( m_args.size() > 0 )
|
||||
return setErrorMode( "Unexpected arguments before " + m_command + ": " + argsAsString() );
|
||||
break;
|
||||
case modeList:
|
||||
if( m_args.size() > 2 )
|
||||
{
|
||||
if( m_args.size() > 2 ) {
|
||||
return setErrorMode( m_command + " expected upto 2 arguments but recieved: " + argsAsString() );
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
Config::List::What listSpec = Config::List::All;
|
||||
if( m_args.size() >= 1 )
|
||||
{
|
||||
if( m_args.size() >= 1 ) {
|
||||
if( m_args[0] == "tests" )
|
||||
listSpec = Config::List::Tests;
|
||||
else if( m_args[0] == "reporters" )
|
||||
|
@ -139,8 +105,7 @@ namespace Catch
|
|||
else
|
||||
return setErrorMode( m_command + " expected [tests] or [reporters] but recieved: [" + m_args[0] + "]" );
|
||||
}
|
||||
if( m_args.size() >= 2 )
|
||||
{
|
||||
if( m_args.size() >= 2 ) {
|
||||
if( m_args[1] == "xml" )
|
||||
listSpec = static_cast<Config::List::What>( listSpec | Config::List::AsXml );
|
||||
else if( m_args[1] == "text" )
|
||||
|
@ -202,12 +167,7 @@ namespace Catch
|
|||
m_mode = mode;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
void setErrorMode
|
||||
(
|
||||
const std::string& errorMessage
|
||||
)
|
||||
{
|
||||
void setErrorMode( const std::string& errorMessage ) {
|
||||
m_mode = modeError;
|
||||
m_command = "";
|
||||
m_config.setError( errorMessage );
|
||||
|
|
|
@ -1,15 +1,10 @@
|
|||
/*
|
||||
* catch_config.hpp
|
||||
* Catch
|
||||
*
|
||||
* Created by Phil on 08/11/2010.
|
||||
* Copyright 2010 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_CATCH_RUNNERCONFIG_HPP_INCLUDED
|
||||
#define TWOBLUECUBES_CATCH_RUNNERCONFIG_HPP_INCLUDED
|
||||
|
||||
|
@ -21,24 +16,20 @@
|
|||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
namespace Catch
|
||||
{
|
||||
namespace Catch {
|
||||
|
||||
class Config : public IReporterConfig
|
||||
{
|
||||
class Config : public IReporterConfig {
|
||||
private:
|
||||
Config( const Config& other );
|
||||
Config& operator = ( const Config& other );
|
||||
public:
|
||||
|
||||
struct Include { enum What
|
||||
{
|
||||
struct Include { enum What {
|
||||
FailedOnly,
|
||||
SuccessfulResults
|
||||
}; };
|
||||
|
||||
struct List{ enum What
|
||||
{
|
||||
struct List{ enum What {
|
||||
None = 0,
|
||||
|
||||
Reports = 1,
|
||||
|
@ -54,7 +45,6 @@ namespace Catch
|
|||
}; };
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
Config()
|
||||
: m_listSpec( List::None ),
|
||||
m_shouldDebugBreak( false ),
|
||||
|
@ -64,167 +54,115 @@ namespace Catch
|
|||
m_includeWhat( Include::FailedOnly )
|
||||
{}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
~Config()
|
||||
{
|
||||
~Config() {
|
||||
m_os.rdbuf( std::cout.rdbuf() );
|
||||
delete m_streambuf;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
void setReporter( const std::string& reporterName )
|
||||
{
|
||||
void setReporter( const std::string& reporterName ) {
|
||||
if( m_reporter.get() )
|
||||
return setError( "Only one reporter may be specified" );
|
||||
setReporter( Context::getReporterRegistry().create( reporterName, *this ) );
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
void addTestSpec( const std::string& testSpec )
|
||||
{
|
||||
void addTestSpec( const std::string& testSpec ) {
|
||||
m_testSpecs.push_back( testSpec );
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
bool testsSpecified() const
|
||||
{
|
||||
bool testsSpecified() const {
|
||||
return !m_testSpecs.empty();
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
const std::vector<std::string>& getTestSpecs() const
|
||||
{
|
||||
const std::vector<std::string>& getTestSpecs() const {
|
||||
return m_testSpecs;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
List::What getListSpec( void ) const
|
||||
{
|
||||
List::What getListSpec( void ) const {
|
||||
return m_listSpec;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
void setListSpec( List::What listSpec )
|
||||
{
|
||||
void setListSpec( List::What listSpec ) {
|
||||
m_listSpec = listSpec;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
void setFilename( const std::string& filename )
|
||||
{
|
||||
void setFilename( const std::string& filename ) {
|
||||
m_filename = filename;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
const std::string& getFilename() const
|
||||
{
|
||||
const std::string& getFilename() const {
|
||||
return m_filename;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
const std::string& getMessage() const
|
||||
{
|
||||
const std::string& getMessage() const {
|
||||
return m_message;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
void setError( const std::string& errorMessage )
|
||||
{
|
||||
void setError( const std::string& errorMessage ) {
|
||||
m_message = errorMessage + "\n\n" + "Usage: ...";
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
void setReporter( IReporter* reporter )
|
||||
{
|
||||
void setReporter( IReporter* reporter ) {
|
||||
m_reporter = reporter;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
Ptr<IReporter> getReporter()
|
||||
{
|
||||
Ptr<IReporter> getReporter() {
|
||||
if( !m_reporter.get() )
|
||||
const_cast<Config*>( this )->setReporter( Context::getReporterRegistry().create( "basic", *this ) );
|
||||
return m_reporter;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
List::What listWhat() const
|
||||
{
|
||||
List::What listWhat() const {
|
||||
return static_cast<List::What>( m_listSpec & List::WhatMask );
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
List::What listAs() const
|
||||
{
|
||||
List::What listAs() const {
|
||||
return static_cast<List::What>( m_listSpec & List::AsMask );
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
void setIncludeWhat( Include::What includeWhat )
|
||||
{
|
||||
void setIncludeWhat( Include::What includeWhat ) {
|
||||
m_includeWhat = includeWhat;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
void setShouldDebugBreak( bool shouldDebugBreakFlag )
|
||||
{
|
||||
void setShouldDebugBreak( bool shouldDebugBreakFlag ) {
|
||||
m_shouldDebugBreak = shouldDebugBreakFlag;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
void setName( const std::string& name )
|
||||
{
|
||||
void setName( const std::string& name ) {
|
||||
m_name = name;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
std::string getName() const
|
||||
{
|
||||
std::string getName() const {
|
||||
return m_name;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
bool shouldDebugBreak() const
|
||||
{
|
||||
bool shouldDebugBreak() const {
|
||||
return m_shouldDebugBreak;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
void setShowHelp( bool showHelpFlag )
|
||||
{
|
||||
void setShowHelp( bool showHelpFlag ) {
|
||||
m_showHelp = showHelpFlag;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
bool showHelp() const
|
||||
{
|
||||
bool showHelp() const {
|
||||
return m_showHelp;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
virtual std::ostream& stream() const
|
||||
{
|
||||
virtual std::ostream& stream() const {
|
||||
return m_os;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
void setStreamBuf( std::streambuf* buf )
|
||||
{
|
||||
void setStreamBuf( std::streambuf* buf ) {
|
||||
m_os.rdbuf( buf ? buf : std::cout.rdbuf() );
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
void useStream( const std::string& streamName )
|
||||
{
|
||||
void useStream( const std::string& streamName ) {
|
||||
std::streambuf* newBuf = Context::createStreamBuf( streamName );
|
||||
setStreamBuf( newBuf );
|
||||
delete m_streambuf;
|
||||
m_streambuf = newBuf;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
virtual bool includeSuccessfulResults() const
|
||||
{
|
||||
virtual bool includeSuccessfulResults() const {
|
||||
return m_includeWhat == Include::SuccessfulResults;
|
||||
}
|
||||
|
||||
|
|
|
@ -14,8 +14,8 @@
|
|||
#include <vector>
|
||||
#include <stdlib.h>
|
||||
|
||||
namespace Catch
|
||||
{
|
||||
namespace Catch {
|
||||
|
||||
class TestCaseInfo;
|
||||
struct IResultCapture;
|
||||
struct ITestCaseRegistry;
|
||||
|
@ -25,8 +25,8 @@ namespace Catch
|
|||
|
||||
class StreamBufBase : public std::streambuf{};
|
||||
|
||||
class Context
|
||||
{
|
||||
class Context {
|
||||
|
||||
Context();
|
||||
Context( const Context& );
|
||||
void operator=( const Context& );
|
||||
|
|
|
@ -1,69 +1,51 @@
|
|||
/*
|
||||
* catch_list.hpp
|
||||
* Catch
|
||||
*
|
||||
* Created by Phil on 5/11/2010.
|
||||
* Copyright 2010 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_CATCH_LIST_HPP_INCLUDED
|
||||
#define TWOBLUECUBES_CATCH_LIST_HPP_INCLUDED
|
||||
|
||||
#include "catch_commandline.hpp"
|
||||
#include <limits>
|
||||
|
||||
namespace Catch
|
||||
{
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
inline int List
|
||||
(
|
||||
Config& config
|
||||
)
|
||||
{
|
||||
if( config.listWhat() & Config::List::Reports )
|
||||
{
|
||||
namespace Catch {
|
||||
inline int List( Config& config ) {
|
||||
|
||||
if( config.listWhat() & Config::List::Reports ) {
|
||||
std::cout << "Available reports:\n";
|
||||
IReporterRegistry::FactoryMap::const_iterator it = Context::getReporterRegistry().getFactories().begin();
|
||||
IReporterRegistry::FactoryMap::const_iterator itEnd = Context::getReporterRegistry().getFactories().end();
|
||||
for(; it != itEnd; ++it )
|
||||
{
|
||||
for(; it != itEnd; ++it ) {
|
||||
// !TBD: consider listAs()
|
||||
std::cout << "\t" << it->first << "\n\t\t'" << it->second->getDescription() << "'\n";
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
if( config.listWhat() & Config::List::Tests )
|
||||
{
|
||||
|
||||
if( config.listWhat() & Config::List::Tests ) {
|
||||
std::cout << "Available tests:\n";
|
||||
std::vector<TestCaseInfo>::const_iterator it = Context::getTestCaseRegistry().getAllTests().begin();
|
||||
std::vector<TestCaseInfo>::const_iterator itEnd = Context::getTestCaseRegistry().getAllTests().end();
|
||||
for(; it != itEnd; ++it )
|
||||
{
|
||||
for(; it != itEnd; ++it ) {
|
||||
// !TBD: consider listAs()
|
||||
std::cout << "\t" << it->getName() << "\n\t\t '" << it->getDescription() << "'\n";
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
if( ( config.listWhat() & Config::List::All ) == 0 )
|
||||
{
|
||||
|
||||
if( ( config.listWhat() & Config::List::All ) == 0 ) {
|
||||
std::cerr << "Unknown list type" << std::endl;
|
||||
return (std::numeric_limits<int>::max)();
|
||||
}
|
||||
|
||||
if( config.getReporter().get() )
|
||||
{
|
||||
std::cerr << "Reporters ignored when listing" << std::endl;
|
||||
}
|
||||
if( !config.testsSpecified() )
|
||||
{
|
||||
std::cerr << "Test specs ignored when listing" << std::endl;
|
||||
}
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
} // end namespace Catch
|
||||
|
|
|
@ -11,12 +11,11 @@
|
|||
#include "catch_test_case_info.hpp"
|
||||
#include "catch_section_info.hpp"
|
||||
|
||||
namespace Catch
|
||||
{
|
||||
class RunningTest
|
||||
{
|
||||
enum RunStatus
|
||||
{
|
||||
namespace Catch {
|
||||
|
||||
class RunningTest {
|
||||
|
||||
enum RunStatus {
|
||||
NothingRun,
|
||||
EncounteredASection,
|
||||
RanAtLeastOneSection,
|
||||
|
@ -25,74 +24,49 @@ namespace Catch
|
|||
};
|
||||
|
||||
public:
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
explicit RunningTest
|
||||
(
|
||||
const TestCaseInfo* info = NULL
|
||||
)
|
||||
explicit RunningTest( const TestCaseInfo* info = NULL )
|
||||
: m_info( info ),
|
||||
m_runStatus( RanAtLeastOneSection ),
|
||||
m_currentSection( &m_rootSection ),
|
||||
m_changed( false )
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
bool wasSectionSeen
|
||||
()
|
||||
const
|
||||
{
|
||||
bool wasSectionSeen() const {
|
||||
return m_runStatus == RanAtLeastOneSection ||
|
||||
m_runStatus == RanToCompletionWithSections;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
void reset
|
||||
()
|
||||
{
|
||||
void reset() {
|
||||
m_runStatus = NothingRun;
|
||||
m_changed = false;
|
||||
m_lastSectionToRun = NULL;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
void ranToCompletion
|
||||
()
|
||||
{
|
||||
void ranToCompletion() {
|
||||
if( m_runStatus == RanAtLeastOneSection ||
|
||||
m_runStatus == EncounteredASection )
|
||||
{
|
||||
m_runStatus == EncounteredASection ) {
|
||||
m_runStatus = RanToCompletionWithSections;
|
||||
if( m_lastSectionToRun )
|
||||
{
|
||||
if( m_lastSectionToRun ) {
|
||||
m_lastSectionToRun->ranToCompletion();
|
||||
m_changed = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
m_runStatus = RanToCompletionWithNoSections;
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
bool addSection
|
||||
(
|
||||
const std::string& name
|
||||
)
|
||||
{
|
||||
bool addSection( const std::string& name ) {
|
||||
if( m_runStatus == NothingRun )
|
||||
m_runStatus = EncounteredASection;
|
||||
|
||||
SectionInfo* thisSection = m_currentSection->findSubSection( name );
|
||||
if( !thisSection )
|
||||
{
|
||||
if( !thisSection ) {
|
||||
thisSection = m_currentSection->addSubSection( name );
|
||||
m_changed = true;
|
||||
}
|
||||
|
||||
if( !wasSectionSeen() && thisSection->shouldRun() )
|
||||
{
|
||||
if( !wasSectionSeen() && thisSection->shouldRun() ) {
|
||||
m_currentSection = thisSection;
|
||||
m_lastSectionToRun = NULL;
|
||||
return true;
|
||||
|
@ -100,38 +74,23 @@ namespace Catch
|
|||
return false;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
void endSection
|
||||
(
|
||||
const std::string&
|
||||
)
|
||||
{
|
||||
if( m_currentSection->ran() )
|
||||
{
|
||||
void endSection( const std::string& ) {
|
||||
if( m_currentSection->ran() ) {
|
||||
m_runStatus = RanAtLeastOneSection;
|
||||
m_changed = true;
|
||||
}
|
||||
else if( m_runStatus == EncounteredASection )
|
||||
{
|
||||
else if( m_runStatus == EncounteredASection ) {
|
||||
m_runStatus = RanAtLeastOneSection;
|
||||
m_lastSectionToRun = m_currentSection;
|
||||
}
|
||||
m_currentSection = m_currentSection->getParent();
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
const TestCaseInfo& getTestCaseInfo
|
||||
()
|
||||
const
|
||||
{
|
||||
const TestCaseInfo& getTestCaseInfo() const {
|
||||
return *m_info;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
bool hasUntestedSections
|
||||
()
|
||||
const
|
||||
{
|
||||
bool hasUntestedSections() const {
|
||||
return m_runStatus == RanAtLeastOneSection ||
|
||||
( m_rootSection.hasUntestedSections() && m_changed );
|
||||
}
|
||||
|
|
|
@ -13,15 +13,12 @@
|
|||
#include <map>
|
||||
#include <string>
|
||||
|
||||
namespace Catch
|
||||
{
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
class SectionInfo
|
||||
{
|
||||
namespace Catch {
|
||||
|
||||
class SectionInfo {
|
||||
public:
|
||||
enum Status
|
||||
{
|
||||
|
||||
enum Status {
|
||||
Root,
|
||||
Unknown,
|
||||
Branch,
|
||||
|
@ -29,103 +26,62 @@ namespace Catch
|
|||
TestedLeaf
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
SectionInfo
|
||||
(
|
||||
SectionInfo* parent
|
||||
)
|
||||
SectionInfo( SectionInfo* parent )
|
||||
: m_status( Unknown ),
|
||||
m_parent( parent )
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
SectionInfo
|
||||
()
|
||||
SectionInfo()
|
||||
: m_status( Root ),
|
||||
m_parent( NULL )
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
~SectionInfo
|
||||
()
|
||||
{
|
||||
~SectionInfo() {
|
||||
deleteAllValues( m_subSections );
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
bool shouldRun
|
||||
()
|
||||
const
|
||||
{
|
||||
bool shouldRun() const {
|
||||
return m_status < TestedBranch;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
bool ran
|
||||
()
|
||||
{
|
||||
if( m_status < Branch )
|
||||
{
|
||||
bool ran() {
|
||||
if( m_status < Branch ) {
|
||||
m_status = TestedLeaf;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
void ranToCompletion
|
||||
()
|
||||
{
|
||||
|
||||
void ranToCompletion() {
|
||||
if( m_status == Branch && !hasUntestedSections() )
|
||||
{
|
||||
m_status = TestedBranch;
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
SectionInfo* findSubSection
|
||||
(
|
||||
const std::string& name
|
||||
)
|
||||
{
|
||||
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* 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
|
||||
()
|
||||
{
|
||||
SectionInfo* getParent() {
|
||||
return m_parent;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
bool hasUntestedSections
|
||||
()
|
||||
const
|
||||
{
|
||||
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 )
|
||||
{
|
||||
for(; it != itEnd; ++it ) {
|
||||
if( it->second->hasUntestedSections() )
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -1,15 +1,10 @@
|
|||
/*
|
||||
* catch_test_case_info.hpp
|
||||
* Catch
|
||||
*
|
||||
* Created by Phil on 29/10/2010.
|
||||
* Copyright 2010 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_CATCH_TESTCASEINFO_HPP_INCLUDED
|
||||
#define TWOBLUECUBES_CATCH_TESTCASEINFO_HPP_INCLUDED
|
||||
|
||||
|
@ -17,147 +12,82 @@
|
|||
#include <map>
|
||||
#include <string>
|
||||
|
||||
namespace Catch
|
||||
{
|
||||
class TestCaseInfo
|
||||
{
|
||||
namespace Catch {
|
||||
|
||||
class TestCaseInfo {
|
||||
public:
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
TestCaseInfo
|
||||
(
|
||||
ITestCase* testCase,
|
||||
const char* name,
|
||||
const char* description,
|
||||
const SourceLineInfo& lineInfo
|
||||
)
|
||||
TestCaseInfo( ITestCase* testCase,
|
||||
const char* name,
|
||||
const char* description,
|
||||
const SourceLineInfo& lineInfo )
|
||||
: m_test( testCase ),
|
||||
m_name( name ),
|
||||
m_description( description ),
|
||||
m_lineInfo( lineInfo )
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
TestCaseInfo
|
||||
()
|
||||
TestCaseInfo()
|
||||
: m_test( NULL ),
|
||||
m_name(),
|
||||
m_description()
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
TestCaseInfo
|
||||
(
|
||||
const TestCaseInfo& other
|
||||
)
|
||||
TestCaseInfo( const TestCaseInfo& other )
|
||||
: m_test( other.m_test->clone() ),
|
||||
m_name( other.m_name ),
|
||||
m_description( other.m_description ),
|
||||
m_lineInfo( other.m_lineInfo )
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
TestCaseInfo
|
||||
(
|
||||
const TestCaseInfo& other,
|
||||
const std::string& name
|
||||
)
|
||||
TestCaseInfo( const TestCaseInfo& other, const std::string& name )
|
||||
: m_test( other.m_test->clone() ),
|
||||
m_name( name ),
|
||||
m_description( other.m_description ),
|
||||
m_lineInfo( other.m_lineInfo )
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
TestCaseInfo& operator =
|
||||
(
|
||||
const TestCaseInfo& other
|
||||
)
|
||||
{
|
||||
TestCaseInfo& operator = ( const TestCaseInfo& other ) {
|
||||
TestCaseInfo temp( other );
|
||||
swap( temp );
|
||||
return *this;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
~TestCaseInfo
|
||||
()
|
||||
{
|
||||
~TestCaseInfo() {
|
||||
delete m_test;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
void invoke
|
||||
()
|
||||
const
|
||||
{
|
||||
void invoke() const {
|
||||
m_test->invoke();
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
const std::string& getName
|
||||
()
|
||||
const
|
||||
{
|
||||
const std::string& getName() const {
|
||||
return m_name;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
const std::string& getDescription
|
||||
()
|
||||
const
|
||||
{
|
||||
const std::string& getDescription() const {
|
||||
return m_description;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
const SourceLineInfo& getLineInfo
|
||||
()
|
||||
const
|
||||
{
|
||||
const SourceLineInfo& getLineInfo() const {
|
||||
return m_lineInfo;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
bool isHidden
|
||||
()
|
||||
const
|
||||
{
|
||||
bool isHidden() const {
|
||||
return m_name.size() >= 2 && m_name[0] == '.' && m_name[1] == '/';
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
void swap
|
||||
(
|
||||
TestCaseInfo& other
|
||||
)
|
||||
{
|
||||
void swap( TestCaseInfo& other ) {
|
||||
std::swap( m_test, other.m_test );
|
||||
m_name.swap( other.m_name );
|
||||
m_description.swap( other.m_description );
|
||||
m_lineInfo.swap( other.m_lineInfo );
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
bool operator ==
|
||||
(
|
||||
const TestCaseInfo& other
|
||||
)
|
||||
const
|
||||
{
|
||||
bool operator == ( const TestCaseInfo& other ) const {
|
||||
return *m_test == *other.m_test && m_name == other.m_name;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
bool operator <
|
||||
(
|
||||
const TestCaseInfo& other
|
||||
)
|
||||
const
|
||||
{
|
||||
bool operator < ( const TestCaseInfo& other ) const {
|
||||
return m_name < other.m_name;
|
||||
}
|
||||
|
||||
|
@ -168,34 +98,21 @@ namespace Catch
|
|||
SourceLineInfo m_lineInfo;
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class TestSpec
|
||||
{
|
||||
class TestSpec {
|
||||
public:
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
TestSpec
|
||||
(
|
||||
const std::string& rawSpec
|
||||
)
|
||||
TestSpec( const std::string& rawSpec )
|
||||
: m_rawSpec( rawSpec ),
|
||||
m_isWildcarded( false )
|
||||
{
|
||||
if( m_rawSpec[m_rawSpec.size()-1] == '*' )
|
||||
{
|
||||
m_isWildcarded( false ) {
|
||||
|
||||
if( m_rawSpec[m_rawSpec.size()-1] == '*' ) {
|
||||
m_rawSpec = m_rawSpec.substr( 0, m_rawSpec.size()-1 );
|
||||
m_isWildcarded = true;
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
bool matches
|
||||
(
|
||||
const std::string& testName
|
||||
)
|
||||
const
|
||||
{
|
||||
bool matches ( const std::string& testName ) const {
|
||||
if( !m_isWildcarded )
|
||||
return m_rawSpec == testName;
|
||||
else
|
||||
|
|
|
@ -8,10 +8,9 @@
|
|||
#ifndef TWOBLUECUBES_CATCH_TOTALS_HPP_INCLUDED
|
||||
#define TWOBLUECUBES_CATCH_TOTALS_HPP_INCLUDED
|
||||
|
||||
namespace Catch
|
||||
{
|
||||
struct Counts
|
||||
{
|
||||
namespace Catch {
|
||||
|
||||
struct Counts {
|
||||
Counts() : passed( 0 ), failed( 0 ) {}
|
||||
|
||||
Counts operator - ( const Counts& other ) const {
|
||||
|
@ -29,8 +28,8 @@ namespace Catch
|
|||
std::size_t failed;
|
||||
};
|
||||
|
||||
struct Totals
|
||||
{
|
||||
struct Totals {
|
||||
|
||||
Totals operator - ( const Totals& other ) const {
|
||||
Totals diff;
|
||||
diff.assertions = assertions - other.assertions;
|
||||
|
|
Loading…
Reference in New Issue