Moar reformatting

This commit is contained in:
Phil Nash 2012-05-15 23:58:23 +01:00
parent d0be9ed5d9
commit c67a7eef2b
8 changed files with 140 additions and 429 deletions

View File

@ -1,27 +1,17 @@
/* /*
* catch_commandline.hpp
* Catch
*
* Created by Phil on 02/11/2010. * Created by Phil on 02/11/2010.
* Copyright 2010 Two Blue Cubes Ltd. All rights reserved. * Copyright 2010 Two Blue Cubes Ltd. All rights reserved.
* *
* Distributed under the Boost Software License, Version 1.0. (See accompanying * 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) * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
*
*/ */
#ifndef TWOBLUECUBES_CATCH_COMMANDLINE_HPP_INCLUDED #ifndef TWOBLUECUBES_CATCH_COMMANDLINE_HPP_INCLUDED
#define TWOBLUECUBES_CATCH_COMMANDLINE_HPP_INCLUDED #define TWOBLUECUBES_CATCH_COMMANDLINE_HPP_INCLUDED
#include "catch_config.hpp" #include "catch_config.hpp"
#include "catch_runner_impl.hpp" #include "catch_runner_impl.hpp"
namespace Catch 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
// -l, --list tests [xml] lists available tests (optionally in xml) // -l, --list tests [xml] lists available tests (optionally in xml)
// -l, --list reporters [xml] lists available reports (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) // -l, --list all [xml] lists available tests and reports (optionally in xml)
@ -31,10 +21,9 @@ namespace Catch
// -s, --success report successful cases too // -s, --success report successful cases too
// -b, --break breaks into debugger on test failure // -b, --break breaks into debugger on test failure
// -n, --name specifies an optional name for the test run // -n, --name specifies an optional name for the test run
class ArgParser : NonCopyable class ArgParser : NonCopyable {
{
enum Mode enum Mode {
{
modeNone, modeNone,
modeList, modeList,
modeTest, modeTest,
@ -49,20 +38,12 @@ namespace Catch
}; };
public: public:
/////////////////////////////////////////////////////////////////////// ArgParser ( int argc, char * const argv[], Config& config )
ArgParser
(
int argc,
char * const argv[],
Config& config
)
: m_mode( modeNone ), : m_mode( modeNone ),
m_config( config ) m_config( config ) {
{
for( int i=1; i < argc; ++i ) for( int i=1; i < argc; ++i ) {
{ if( argv[i][0] == '-' ) {
if( argv[i][0] == '-' )
{
std::string cmd = ( argv[i] ); std::string cmd = ( argv[i] );
if( cmd == "-l" || cmd == "--list" ) if( cmd == "-l" || cmd == "--list" )
changeMode( cmd, modeList ); changeMode( cmd, modeList );
@ -81,8 +62,7 @@ namespace Catch
else if( cmd == "-h" || cmd == "-?" || cmd == "--help" ) else if( cmd == "-h" || cmd == "-?" || cmd == "--help" )
changeMode( cmd, modeHelp ); changeMode( cmd, modeHelp );
} }
else else {
{
m_args.push_back( argv[i] ); m_args.push_back( argv[i] );
} }
if( m_mode == modeError ) if( m_mode == modeError )
@ -92,15 +72,11 @@ namespace Catch
} }
private: private:
/////////////////////////////////////////////////////////////////////// std::string argsAsString() {
std::string argsAsString
()
{
std::ostringstream oss; std::ostringstream oss;
std::vector<std::string>::const_iterator it = m_args.begin(); std::vector<std::string>::const_iterator it = m_args.begin();
std::vector<std::string>::const_iterator itEnd = m_args.end(); 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 ) if( !first )
oss << " "; oss << " ";
oss << *it; oss << *it;
@ -108,30 +84,20 @@ namespace Catch
return oss.str(); return oss.str();
} }
/////////////////////////////////////////////////////////////////////// void changeMode( const std::string& cmd, Mode mode ) {
void changeMode
(
const std::string& cmd,
Mode mode
)
{
m_command = cmd; m_command = cmd;
switch( m_mode ) switch( m_mode ) {
{
case modeNone: case modeNone:
if( m_args.size() > 0 ) if( m_args.size() > 0 )
return setErrorMode( "Unexpected arguments before " + m_command + ": " + argsAsString() ); return setErrorMode( "Unexpected arguments before " + m_command + ": " + argsAsString() );
break; break;
case modeList: case modeList:
if( m_args.size() > 2 ) if( m_args.size() > 2 ) {
{
return setErrorMode( m_command + " expected upto 2 arguments but recieved: " + argsAsString() ); return setErrorMode( m_command + " expected upto 2 arguments but recieved: " + argsAsString() );
} }
else else {
{
Config::List::What listSpec = Config::List::All; Config::List::What listSpec = Config::List::All;
if( m_args.size() >= 1 ) if( m_args.size() >= 1 ) {
{
if( m_args[0] == "tests" ) if( m_args[0] == "tests" )
listSpec = Config::List::Tests; listSpec = Config::List::Tests;
else if( m_args[0] == "reporters" ) else if( m_args[0] == "reporters" )
@ -139,8 +105,7 @@ namespace Catch
else else
return setErrorMode( m_command + " expected [tests] or [reporters] but recieved: [" + m_args[0] + "]" ); 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" ) if( m_args[1] == "xml" )
listSpec = static_cast<Config::List::What>( listSpec | Config::List::AsXml ); listSpec = static_cast<Config::List::What>( listSpec | Config::List::AsXml );
else if( m_args[1] == "text" ) else if( m_args[1] == "text" )
@ -202,12 +167,7 @@ namespace Catch
m_mode = mode; m_mode = mode;
} }
/////////////////////////////////////////////////////////////////////// void setErrorMode( const std::string& errorMessage ) {
void setErrorMode
(
const std::string& errorMessage
)
{
m_mode = modeError; m_mode = modeError;
m_command = ""; m_command = "";
m_config.setError( errorMessage ); m_config.setError( errorMessage );

View File

@ -1,15 +1,10 @@
/* /*
* catch_config.hpp
* Catch
*
* Created by Phil on 08/11/2010. * Created by Phil on 08/11/2010.
* Copyright 2010 Two Blue Cubes Ltd. All rights reserved. * Copyright 2010 Two Blue Cubes Ltd. All rights reserved.
* *
* Distributed under the Boost Software License, Version 1.0. (See accompanying * 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) * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
*
*/ */
#ifndef TWOBLUECUBES_CATCH_RUNNERCONFIG_HPP_INCLUDED #ifndef TWOBLUECUBES_CATCH_RUNNERCONFIG_HPP_INCLUDED
#define TWOBLUECUBES_CATCH_RUNNERCONFIG_HPP_INCLUDED #define TWOBLUECUBES_CATCH_RUNNERCONFIG_HPP_INCLUDED
@ -21,24 +16,20 @@
#include <string> #include <string>
#include <iostream> #include <iostream>
namespace Catch namespace Catch {
{
class Config : public IReporterConfig class Config : public IReporterConfig {
{
private: private:
Config( const Config& other ); Config( const Config& other );
Config& operator = ( const Config& other ); Config& operator = ( const Config& other );
public: public:
struct Include { enum What struct Include { enum What {
{
FailedOnly, FailedOnly,
SuccessfulResults SuccessfulResults
}; }; }; };
struct List{ enum What struct List{ enum What {
{
None = 0, None = 0,
Reports = 1, Reports = 1,
@ -54,7 +45,6 @@ namespace Catch
}; }; }; };
///////////////////////////////////////////////////////////////////////////
Config() Config()
: m_listSpec( List::None ), : m_listSpec( List::None ),
m_shouldDebugBreak( false ), m_shouldDebugBreak( false ),
@ -64,167 +54,115 @@ namespace Catch
m_includeWhat( Include::FailedOnly ) m_includeWhat( Include::FailedOnly )
{} {}
/////////////////////////////////////////////////////////////////////////// ~Config() {
~Config()
{
m_os.rdbuf( std::cout.rdbuf() ); m_os.rdbuf( std::cout.rdbuf() );
delete m_streambuf; delete m_streambuf;
} }
/////////////////////////////////////////////////////////////////////////// void setReporter( const std::string& reporterName ) {
void setReporter( const std::string& reporterName )
{
if( m_reporter.get() ) if( m_reporter.get() )
return setError( "Only one reporter may be specified" ); return setError( "Only one reporter may be specified" );
setReporter( Context::getReporterRegistry().create( reporterName, *this ) ); setReporter( Context::getReporterRegistry().create( reporterName, *this ) );
} }
/////////////////////////////////////////////////////////////////////////// void addTestSpec( const std::string& testSpec ) {
void addTestSpec( const std::string& testSpec )
{
m_testSpecs.push_back( testSpec ); m_testSpecs.push_back( testSpec );
} }
/////////////////////////////////////////////////////////////////////////// bool testsSpecified() const {
bool testsSpecified() const
{
return !m_testSpecs.empty(); return !m_testSpecs.empty();
} }
/////////////////////////////////////////////////////////////////////////// const std::vector<std::string>& getTestSpecs() const {
const std::vector<std::string>& getTestSpecs() const
{
return m_testSpecs; return m_testSpecs;
} }
/////////////////////////////////////////////////////////////////////////// List::What getListSpec( void ) const {
List::What getListSpec( void ) const
{
return m_listSpec; return m_listSpec;
} }
/////////////////////////////////////////////////////////////////////////// void setListSpec( List::What listSpec ) {
void setListSpec( List::What listSpec )
{
m_listSpec = listSpec; m_listSpec = listSpec;
} }
/////////////////////////////////////////////////////////////////////////// void setFilename( const std::string& filename ) {
void setFilename( const std::string& filename )
{
m_filename = filename; m_filename = filename;
} }
/////////////////////////////////////////////////////////////////////////// const std::string& getFilename() const {
const std::string& getFilename() const
{
return m_filename; return m_filename;
} }
/////////////////////////////////////////////////////////////////////////// const std::string& getMessage() const {
const std::string& getMessage() const
{
return m_message; return m_message;
} }
/////////////////////////////////////////////////////////////////////////// void setError( const std::string& errorMessage ) {
void setError( const std::string& errorMessage )
{
m_message = errorMessage + "\n\n" + "Usage: ..."; m_message = errorMessage + "\n\n" + "Usage: ...";
} }
/////////////////////////////////////////////////////////////////////////// void setReporter( IReporter* reporter ) {
void setReporter( IReporter* reporter )
{
m_reporter = reporter; m_reporter = reporter;
} }
/////////////////////////////////////////////////////////////////////////// Ptr<IReporter> getReporter() {
Ptr<IReporter> getReporter()
{
if( !m_reporter.get() ) if( !m_reporter.get() )
const_cast<Config*>( this )->setReporter( Context::getReporterRegistry().create( "basic", *this ) ); const_cast<Config*>( this )->setReporter( Context::getReporterRegistry().create( "basic", *this ) );
return m_reporter; return m_reporter;
} }
/////////////////////////////////////////////////////////////////////////// List::What listWhat() const {
List::What listWhat() const
{
return static_cast<List::What>( m_listSpec & List::WhatMask ); 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 ); return static_cast<List::What>( m_listSpec & List::AsMask );
} }
/////////////////////////////////////////////////////////////////////////// void setIncludeWhat( Include::What includeWhat ) {
void setIncludeWhat( Include::What includeWhat )
{
m_includeWhat = includeWhat; m_includeWhat = includeWhat;
} }
/////////////////////////////////////////////////////////////////////////// void setShouldDebugBreak( bool shouldDebugBreakFlag ) {
void setShouldDebugBreak( bool shouldDebugBreakFlag )
{
m_shouldDebugBreak = shouldDebugBreakFlag; m_shouldDebugBreak = shouldDebugBreakFlag;
} }
/////////////////////////////////////////////////////////////////////////// void setName( const std::string& name ) {
void setName( const std::string& name )
{
m_name = name; m_name = name;
} }
/////////////////////////////////////////////////////////////////////////// std::string getName() const {
std::string getName() const
{
return m_name; return m_name;
} }
/////////////////////////////////////////////////////////////////////////// bool shouldDebugBreak() const {
bool shouldDebugBreak() const
{
return m_shouldDebugBreak; return m_shouldDebugBreak;
} }
/////////////////////////////////////////////////////////////////////////// void setShowHelp( bool showHelpFlag ) {
void setShowHelp( bool showHelpFlag )
{
m_showHelp = showHelpFlag; m_showHelp = showHelpFlag;
} }
/////////////////////////////////////////////////////////////////////////// bool showHelp() const {
bool showHelp() const
{
return m_showHelp; return m_showHelp;
} }
/////////////////////////////////////////////////////////////////////////// virtual std::ostream& stream() const {
virtual std::ostream& stream() const
{
return m_os; return m_os;
} }
/////////////////////////////////////////////////////////////////////////// void setStreamBuf( std::streambuf* buf ) {
void setStreamBuf( std::streambuf* buf )
{
m_os.rdbuf( buf ? buf : std::cout.rdbuf() ); 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 ); std::streambuf* newBuf = Context::createStreamBuf( streamName );
setStreamBuf( newBuf ); setStreamBuf( newBuf );
delete m_streambuf; delete m_streambuf;
m_streambuf = newBuf; m_streambuf = newBuf;
} }
/////////////////////////////////////////////////////////////////////////// virtual bool includeSuccessfulResults() const {
virtual bool includeSuccessfulResults() const
{
return m_includeWhat == Include::SuccessfulResults; return m_includeWhat == Include::SuccessfulResults;
} }

View File

@ -14,8 +14,8 @@
#include <vector> #include <vector>
#include <stdlib.h> #include <stdlib.h>
namespace Catch namespace Catch {
{
class TestCaseInfo; class TestCaseInfo;
struct IResultCapture; struct IResultCapture;
struct ITestCaseRegistry; struct ITestCaseRegistry;
@ -25,8 +25,8 @@ namespace Catch
class StreamBufBase : public std::streambuf{}; class StreamBufBase : public std::streambuf{};
class Context class Context {
{
Context(); Context();
Context( const Context& ); Context( const Context& );
void operator=( const Context& ); void operator=( const Context& );

View File

@ -1,69 +1,51 @@
/* /*
* catch_list.hpp
* Catch
*
* Created by Phil on 5/11/2010. * Created by Phil on 5/11/2010.
* Copyright 2010 Two Blue Cubes Ltd. All rights reserved. * Copyright 2010 Two Blue Cubes Ltd. All rights reserved.
* *
* Distributed under the Boost Software License, Version 1.0. (See accompanying * 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) * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
*
*/ */
#ifndef TWOBLUECUBES_CATCH_LIST_HPP_INCLUDED #ifndef TWOBLUECUBES_CATCH_LIST_HPP_INCLUDED
#define TWOBLUECUBES_CATCH_LIST_HPP_INCLUDED #define TWOBLUECUBES_CATCH_LIST_HPP_INCLUDED
#include "catch_commandline.hpp" #include "catch_commandline.hpp"
#include <limits> #include <limits>
namespace Catch namespace Catch {
{ inline int List( Config& config ) {
///////////////////////////////////////////////////////////////////////////
inline int List if( config.listWhat() & Config::List::Reports ) {
(
Config& config
)
{
if( config.listWhat() & Config::List::Reports )
{
std::cout << "Available reports:\n"; std::cout << "Available reports:\n";
IReporterRegistry::FactoryMap::const_iterator it = Context::getReporterRegistry().getFactories().begin(); IReporterRegistry::FactoryMap::const_iterator it = Context::getReporterRegistry().getFactories().begin();
IReporterRegistry::FactoryMap::const_iterator itEnd = Context::getReporterRegistry().getFactories().end(); IReporterRegistry::FactoryMap::const_iterator itEnd = Context::getReporterRegistry().getFactories().end();
for(; it != itEnd; ++it ) for(; it != itEnd; ++it ) {
{
// !TBD: consider listAs() // !TBD: consider listAs()
std::cout << "\t" << it->first << "\n\t\t'" << it->second->getDescription() << "'\n"; std::cout << "\t" << it->first << "\n\t\t'" << it->second->getDescription() << "'\n";
} }
std::cout << std::endl; std::cout << std::endl;
} }
if( config.listWhat() & Config::List::Tests )
{ if( config.listWhat() & Config::List::Tests ) {
std::cout << "Available tests:\n"; std::cout << "Available tests:\n";
std::vector<TestCaseInfo>::const_iterator it = Context::getTestCaseRegistry().getAllTests().begin(); std::vector<TestCaseInfo>::const_iterator it = Context::getTestCaseRegistry().getAllTests().begin();
std::vector<TestCaseInfo>::const_iterator itEnd = Context::getTestCaseRegistry().getAllTests().end(); std::vector<TestCaseInfo>::const_iterator itEnd = Context::getTestCaseRegistry().getAllTests().end();
for(; it != itEnd; ++it ) for(; it != itEnd; ++it ) {
{
// !TBD: consider listAs() // !TBD: consider listAs()
std::cout << "\t" << it->getName() << "\n\t\t '" << it->getDescription() << "'\n"; std::cout << "\t" << it->getName() << "\n\t\t '" << it->getDescription() << "'\n";
} }
std::cout << std::endl; 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; std::cerr << "Unknown list type" << std::endl;
return (std::numeric_limits<int>::max)(); return (std::numeric_limits<int>::max)();
} }
if( config.getReporter().get() ) if( config.getReporter().get() )
{
std::cerr << "Reporters ignored when listing" << std::endl; std::cerr << "Reporters ignored when listing" << std::endl;
}
if( !config.testsSpecified() ) if( !config.testsSpecified() )
{
std::cerr << "Test specs ignored when listing" << std::endl; std::cerr << "Test specs ignored when listing" << std::endl;
}
return 0; return 0;
} }
} // end namespace Catch } // end namespace Catch

View File

@ -11,12 +11,11 @@
#include "catch_test_case_info.hpp" #include "catch_test_case_info.hpp"
#include "catch_section_info.hpp" #include "catch_section_info.hpp"
namespace Catch namespace Catch {
{
class RunningTest class RunningTest {
{
enum RunStatus enum RunStatus {
{
NothingRun, NothingRun,
EncounteredASection, EncounteredASection,
RanAtLeastOneSection, RanAtLeastOneSection,
@ -25,74 +24,49 @@ namespace Catch
}; };
public: public:
/////////////////////////////////////////////////////////////////////// explicit RunningTest( const TestCaseInfo* info = NULL )
explicit RunningTest
(
const TestCaseInfo* info = NULL
)
: m_info( info ), : m_info( info ),
m_runStatus( RanAtLeastOneSection ), m_runStatus( RanAtLeastOneSection ),
m_currentSection( &m_rootSection ), m_currentSection( &m_rootSection ),
m_changed( false ) m_changed( false )
{ {}
}
/////////////////////////////////////////////////////////////////////// bool wasSectionSeen() const {
bool wasSectionSeen
()
const
{
return m_runStatus == RanAtLeastOneSection || return m_runStatus == RanAtLeastOneSection ||
m_runStatus == RanToCompletionWithSections; m_runStatus == RanToCompletionWithSections;
} }
/////////////////////////////////////////////////////////////////////// void reset() {
void reset
()
{
m_runStatus = NothingRun; m_runStatus = NothingRun;
m_changed = false; m_changed = false;
m_lastSectionToRun = NULL; m_lastSectionToRun = NULL;
} }
/////////////////////////////////////////////////////////////////////// void ranToCompletion() {
void ranToCompletion
()
{
if( m_runStatus == RanAtLeastOneSection || if( m_runStatus == RanAtLeastOneSection ||
m_runStatus == EncounteredASection ) m_runStatus == EncounteredASection ) {
{
m_runStatus = RanToCompletionWithSections; m_runStatus = RanToCompletionWithSections;
if( m_lastSectionToRun ) if( m_lastSectionToRun ) {
{
m_lastSectionToRun->ranToCompletion(); m_lastSectionToRun->ranToCompletion();
m_changed = true; m_changed = true;
} }
} }
else else {
{
m_runStatus = RanToCompletionWithNoSections; m_runStatus = RanToCompletionWithNoSections;
} }
} }
/////////////////////////////////////////////////////////////////////// bool addSection( const std::string& name ) {
bool addSection
(
const std::string& name
)
{
if( m_runStatus == NothingRun ) if( m_runStatus == NothingRun )
m_runStatus = EncounteredASection; m_runStatus = EncounteredASection;
SectionInfo* thisSection = m_currentSection->findSubSection( name ); SectionInfo* thisSection = m_currentSection->findSubSection( name );
if( !thisSection ) if( !thisSection ) {
{
thisSection = m_currentSection->addSubSection( name ); thisSection = m_currentSection->addSubSection( name );
m_changed = true; m_changed = true;
} }
if( !wasSectionSeen() && thisSection->shouldRun() ) if( !wasSectionSeen() && thisSection->shouldRun() ) {
{
m_currentSection = thisSection; m_currentSection = thisSection;
m_lastSectionToRun = NULL; m_lastSectionToRun = NULL;
return true; return true;
@ -100,38 +74,23 @@ namespace Catch
return false; return false;
} }
/////////////////////////////////////////////////////////////////////// void endSection( const std::string& ) {
void endSection if( m_currentSection->ran() ) {
(
const std::string&
)
{
if( m_currentSection->ran() )
{
m_runStatus = RanAtLeastOneSection; m_runStatus = RanAtLeastOneSection;
m_changed = true; m_changed = true;
} }
else if( m_runStatus == EncounteredASection ) else if( m_runStatus == EncounteredASection ) {
{
m_runStatus = RanAtLeastOneSection; m_runStatus = RanAtLeastOneSection;
m_lastSectionToRun = m_currentSection; m_lastSectionToRun = m_currentSection;
} }
m_currentSection = m_currentSection->getParent(); m_currentSection = m_currentSection->getParent();
} }
/////////////////////////////////////////////////////////////////////// const TestCaseInfo& getTestCaseInfo() const {
const TestCaseInfo& getTestCaseInfo
()
const
{
return *m_info; return *m_info;
} }
/////////////////////////////////////////////////////////////////////// bool hasUntestedSections() const {
bool hasUntestedSections
()
const
{
return m_runStatus == RanAtLeastOneSection || return m_runStatus == RanAtLeastOneSection ||
( m_rootSection.hasUntestedSections() && m_changed ); ( m_rootSection.hasUntestedSections() && m_changed );
} }

View File

@ -13,15 +13,12 @@
#include <map> #include <map>
#include <string> #include <string>
namespace Catch namespace Catch {
{
/////////////////////////////////////////////////////////////////////////// class SectionInfo {
///////////////////////////////////////////////////////////////////////////
class SectionInfo
{
public: public:
enum Status
{ enum Status {
Root, Root,
Unknown, Unknown,
Branch, Branch,
@ -29,103 +26,62 @@ namespace Catch
TestedLeaf TestedLeaf
}; };
/////////////////////////////////////////////////////////////////////// SectionInfo( SectionInfo* parent )
SectionInfo
(
SectionInfo* parent
)
: m_status( Unknown ), : m_status( Unknown ),
m_parent( parent ) m_parent( parent )
{ {}
}
/////////////////////////////////////////////////////////////////////// SectionInfo()
SectionInfo
()
: m_status( Root ), : m_status( Root ),
m_parent( NULL ) m_parent( NULL )
{ {}
}
/////////////////////////////////////////////////////////////////////// ~SectionInfo() {
~SectionInfo
()
{
deleteAllValues( m_subSections ); deleteAllValues( m_subSections );
} }
/////////////////////////////////////////////////////////////////////// bool shouldRun() const {
bool shouldRun
()
const
{
return m_status < TestedBranch; return m_status < TestedBranch;
} }
/////////////////////////////////////////////////////////////////////// bool ran() {
bool ran if( m_status < Branch ) {
()
{
if( m_status < Branch )
{
m_status = TestedLeaf; m_status = TestedLeaf;
return true; return true;
} }
return false; return false;
} }
///////////////////////////////////////////////////////////////////////
void ranToCompletion void ranToCompletion() {
()
{
if( m_status == Branch && !hasUntestedSections() ) if( m_status == Branch && !hasUntestedSections() )
{
m_status = TestedBranch; 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 ); std::map<std::string, SectionInfo*>::const_iterator it = m_subSections.find( name );
return it != m_subSections.end() return it != m_subSections.end()
? it->second ? it->second
: NULL; : NULL;
} }
/////////////////////////////////////////////////////////////////////// SectionInfo* addSubSection( const std::string& name ) {
SectionInfo* addSubSection
(
const std::string& name
)
{
SectionInfo* subSection = new SectionInfo( this ); SectionInfo* subSection = new SectionInfo( this );
m_subSections.insert( std::make_pair( name, subSection ) ); m_subSections.insert( std::make_pair( name, subSection ) );
m_status = Branch; m_status = Branch;
return subSection; return subSection;
} }
/////////////////////////////////////////////////////////////////////// SectionInfo* getParent() {
SectionInfo* getParent
()
{
return m_parent; return m_parent;
} }
/////////////////////////////////////////////////////////////////////// bool hasUntestedSections() const {
bool hasUntestedSections
()
const
{
if( m_status == Unknown ) if( m_status == Unknown )
return true; return true;
std::map<std::string, SectionInfo*>::const_iterator it = m_subSections.begin(); std::map<std::string, SectionInfo*>::const_iterator it = m_subSections.begin();
std::map<std::string, SectionInfo*>::const_iterator itEnd = m_subSections.end(); std::map<std::string, SectionInfo*>::const_iterator itEnd = m_subSections.end();
for(; it != itEnd; ++it ) for(; it != itEnd; ++it ) {
{
if( it->second->hasUntestedSections() ) if( it->second->hasUntestedSections() )
return true; return true;
} }

View File

@ -1,15 +1,10 @@
/* /*
* catch_test_case_info.hpp
* Catch
*
* Created by Phil on 29/10/2010. * Created by Phil on 29/10/2010.
* Copyright 2010 Two Blue Cubes Ltd. All rights reserved. * Copyright 2010 Two Blue Cubes Ltd. All rights reserved.
* *
* Distributed under the Boost Software License, Version 1.0. (See accompanying * 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) * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
*
*/ */
#ifndef TWOBLUECUBES_CATCH_TESTCASEINFO_HPP_INCLUDED #ifndef TWOBLUECUBES_CATCH_TESTCASEINFO_HPP_INCLUDED
#define TWOBLUECUBES_CATCH_TESTCASEINFO_HPP_INCLUDED #define TWOBLUECUBES_CATCH_TESTCASEINFO_HPP_INCLUDED
@ -17,147 +12,82 @@
#include <map> #include <map>
#include <string> #include <string>
namespace Catch namespace Catch {
{
class TestCaseInfo class TestCaseInfo {
{
public: public:
/////////////////////////////////////////////////////////////////////// TestCaseInfo( ITestCase* testCase,
TestCaseInfo
(
ITestCase* testCase,
const char* name, const char* name,
const char* description, const char* description,
const SourceLineInfo& lineInfo const SourceLineInfo& lineInfo )
)
: m_test( testCase ), : m_test( testCase ),
m_name( name ), m_name( name ),
m_description( description ), m_description( description ),
m_lineInfo( lineInfo ) m_lineInfo( lineInfo )
{ {}
}
/////////////////////////////////////////////////////////////////////// TestCaseInfo()
TestCaseInfo
()
: m_test( NULL ), : m_test( NULL ),
m_name(), m_name(),
m_description() m_description()
{ {}
}
/////////////////////////////////////////////////////////////////////// TestCaseInfo( const TestCaseInfo& other )
TestCaseInfo
(
const TestCaseInfo& other
)
: m_test( other.m_test->clone() ), : m_test( other.m_test->clone() ),
m_name( other.m_name ), m_name( other.m_name ),
m_description( other.m_description ), m_description( other.m_description ),
m_lineInfo( other.m_lineInfo ) 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_test( other.m_test->clone() ),
m_name( name ), m_name( name ),
m_description( other.m_description ), m_description( other.m_description ),
m_lineInfo( other.m_lineInfo ) m_lineInfo( other.m_lineInfo )
{ {}
}
/////////////////////////////////////////////////////////////////////// TestCaseInfo& operator = ( const TestCaseInfo& other ) {
TestCaseInfo& operator =
(
const TestCaseInfo& other
)
{
TestCaseInfo temp( other ); TestCaseInfo temp( other );
swap( temp ); swap( temp );
return *this; return *this;
} }
/////////////////////////////////////////////////////////////////////// ~TestCaseInfo() {
~TestCaseInfo
()
{
delete m_test; delete m_test;
} }
/////////////////////////////////////////////////////////////////////// void invoke() const {
void invoke
()
const
{
m_test->invoke(); m_test->invoke();
} }
/////////////////////////////////////////////////////////////////////// const std::string& getName() const {
const std::string& getName
()
const
{
return m_name; return m_name;
} }
/////////////////////////////////////////////////////////////////////// const std::string& getDescription() const {
const std::string& getDescription
()
const
{
return m_description; return m_description;
} }
/////////////////////////////////////////////////////////////////////// const SourceLineInfo& getLineInfo() const {
const SourceLineInfo& getLineInfo
()
const
{
return m_lineInfo; return m_lineInfo;
} }
/////////////////////////////////////////////////////////////////////// bool isHidden() const {
bool isHidden
()
const
{
return m_name.size() >= 2 && m_name[0] == '.' && m_name[1] == '/'; 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 ); std::swap( m_test, other.m_test );
m_name.swap( other.m_name ); m_name.swap( other.m_name );
m_description.swap( other.m_description ); m_description.swap( other.m_description );
m_lineInfo.swap( other.m_lineInfo ); 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; 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; return m_name < other.m_name;
} }
@ -168,34 +98,21 @@ namespace Catch
SourceLineInfo m_lineInfo; SourceLineInfo m_lineInfo;
}; };
///////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
class TestSpec class TestSpec {
{
public: public:
/////////////////////////////////////////////////////////////////////// TestSpec( const std::string& rawSpec )
TestSpec
(
const std::string& rawSpec
)
: m_rawSpec( rawSpec ), : m_rawSpec( rawSpec ),
m_isWildcarded( false ) m_isWildcarded( false ) {
{
if( m_rawSpec[m_rawSpec.size()-1] == '*' ) if( m_rawSpec[m_rawSpec.size()-1] == '*' ) {
{
m_rawSpec = m_rawSpec.substr( 0, m_rawSpec.size()-1 ); m_rawSpec = m_rawSpec.substr( 0, m_rawSpec.size()-1 );
m_isWildcarded = true; m_isWildcarded = true;
} }
} }
/////////////////////////////////////////////////////////////////////// bool matches ( const std::string& testName ) const {
bool matches
(
const std::string& testName
)
const
{
if( !m_isWildcarded ) if( !m_isWildcarded )
return m_rawSpec == testName; return m_rawSpec == testName;
else else

View File

@ -8,10 +8,9 @@
#ifndef TWOBLUECUBES_CATCH_TOTALS_HPP_INCLUDED #ifndef TWOBLUECUBES_CATCH_TOTALS_HPP_INCLUDED
#define TWOBLUECUBES_CATCH_TOTALS_HPP_INCLUDED #define TWOBLUECUBES_CATCH_TOTALS_HPP_INCLUDED
namespace Catch namespace Catch {
{
struct Counts struct Counts {
{
Counts() : passed( 0 ), failed( 0 ) {} Counts() : passed( 0 ), failed( 0 ) {}
Counts operator - ( const Counts& other ) const { Counts operator - ( const Counts& other ) const {
@ -29,8 +28,8 @@ namespace Catch
std::size_t failed; std::size_t failed;
}; };
struct Totals struct Totals {
{
Totals operator - ( const Totals& other ) const { Totals operator - ( const Totals& other ) const {
Totals diff; Totals diff;
diff.assertions = assertions - other.assertions; diff.assertions = assertions - other.assertions;