More reformatting

This commit is contained in:
Phil Nash 2012-05-10 21:46:46 +01:00
parent d53573c95a
commit d10d2d3485
6 changed files with 150 additions and 225 deletions

View File

@ -1,15 +1,10 @@
/*
* catch_objc.hpp
* Catch
*
* Created by Phil on 14/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_OBJC_HPP_INCLUDED
#define TWOBLUECUBES_CATCH_OBJC_HPP_INCLUDED

View File

@ -1,13 +1,9 @@
/*
* catch_runner.hpp
* Catch
*
* Created by Phil on 22/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_INTERNAL_CATCH_RUNNER_HPP_INCLUDED
#define TWOBLUECUBES_INTERNAL_CATCH_RUNNER_HPP_INCLUDED
@ -26,7 +22,6 @@
namespace Catch
{
class StreamRedirect
{
public:

View File

@ -1,15 +1,10 @@
/*
* catch_test_case_registry_impl.hpp
* Catch
*
* Created by Phil on 7/1/2011
* 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)
*
*/
#include "catch_test_registry.hpp"
#include "catch_test_case_info.hpp"
#include "catch_context.h"
@ -20,35 +15,22 @@
namespace Catch
{
class TestRegistry : public ITestCaseRegistry
{
class TestRegistry : public ITestCaseRegistry {
public:
///////////////////////////////////////////////////////////////////////////
TestRegistry
()
: m_unnamedCount( 0 )
{
}
TestRegistry() : m_unnamedCount( 0 ) {}
///////////////////////////////////////////////////////////////////////////
virtual void registerTest
(
const TestCaseInfo& testInfo
)
{
if( testInfo.getName() == "" )
{
virtual void registerTest( const TestCaseInfo& testInfo ) {
if( testInfo.getName() == "" ) {
std::ostringstream oss;
oss << testInfo.getName() << "unnamed/" << ++m_unnamedCount;
return registerTest( TestCaseInfo( testInfo, oss.str() ) );
}
if( m_functions.find( testInfo ) == m_functions.end() )
{
if( m_functions.find( testInfo ) == m_functions.end() ) {
m_functions.insert( testInfo );
m_functionsInOrder.push_back( testInfo );
}
else
{
else {
const TestCaseInfo& prev = *m_functions.find( testInfo );
std::cerr << "error: TEST_CASE( \"" << testInfo.getName() << "\" ) already defined.\n"
<< "\tFirst seen at " << SourceLineInfo( prev.getLineInfo() ) << "\n"
@ -57,29 +39,18 @@ namespace Catch
}
}
///////////////////////////////////////////////////////////////////////////
virtual const std::vector<TestCaseInfo>& getAllTests
()
const
{
virtual const std::vector<TestCaseInfo>& getAllTests() const {
return m_functionsInOrder;
}
///////////////////////////////////////////////////////////////////////////
virtual std::vector<TestCaseInfo> getMatchingTestCases
(
const std::string& rawTestSpec
)
{
virtual std::vector<TestCaseInfo> getMatchingTestCases( const std::string& rawTestSpec ) {
TestSpec testSpec( rawTestSpec );
std::vector<TestCaseInfo> testList;
std::vector<TestCaseInfo>::const_iterator it = m_functionsInOrder.begin();
std::vector<TestCaseInfo>::const_iterator itEnd = m_functionsInOrder.end();
for(; it != itEnd; ++it )
{
if( testSpec.matches( it->getName() ) )
{
for(; it != itEnd; ++it ) {
if( testSpec.matches( it->getName() ) ) {
testList.push_back( *it );
}
}
@ -94,53 +65,26 @@ namespace Catch
};
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
class FreeFunctionTestCase : public ITestCase {
public:
struct FreeFunctionTestCase : ITestCase
{
///////////////////////////////////////////////////////////////////////////
FreeFunctionTestCase
(
TestFunction fun
)
: m_fun( fun )
{}
FreeFunctionTestCase( TestFunction fun ) : m_fun( fun ) {}
///////////////////////////////////////////////////////////////////////////
virtual void invoke
()
const
{
virtual void invoke() const {
m_fun();
}
///////////////////////////////////////////////////////////////////////////
virtual ITestCase* clone
()
const
{
virtual ITestCase* clone() const {
return new FreeFunctionTestCase( m_fun );
}
///////////////////////////////////////////////////////////////////////////
virtual bool operator ==
(
const ITestCase& other
)
const
{
virtual bool operator == ( const ITestCase& other ) const {
const FreeFunctionTestCase* ffOther = dynamic_cast<const FreeFunctionTestCase*> ( &other );
return ffOther && m_fun == ffOther->m_fun;
}
///////////////////////////////////////////////////////////////////////////
virtual bool operator <
(
const ITestCase& other
)
const
{
virtual bool operator < ( const ITestCase& other ) const {
const FreeFunctionTestCase* ffOther = dynamic_cast<const FreeFunctionTestCase*> ( &other );
return ffOther && m_fun < ffOther->m_fun;
}
@ -149,36 +93,21 @@ namespace Catch
TestFunction m_fun;
};
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
AutoReg::AutoReg
(
TestFunction function,
const char* name,
const char* description,
const SourceLineInfo& lineInfo
)
{
AutoReg::AutoReg( TestFunction function,
const char* name,
const char* description,
const SourceLineInfo& lineInfo ) {
registerTestCase( new FreeFunctionTestCase( function ), name, description, lineInfo );
}
///////////////////////////////////////////////////////////////////////////
AutoReg::~AutoReg
()
{
}
AutoReg::~AutoReg() {}
///////////////////////////////////////////////////////////////////////////
void AutoReg::registerTestCase
(
ITestCase* testCase,
const char* name,
const char* description,
const SourceLineInfo& lineInfo
)
{
void AutoReg::registerTestCase( ITestCase* testCase,
const char* name,
const char* description,
const SourceLineInfo& lineInfo ) {
Context::getTestCaseRegistry().registerTest( TestCaseInfo( testCase, name, description, lineInfo ) );
}

View File

@ -1,13 +1,9 @@
/*
* catch_test_registry.hpp
* Catch
*
* Created by Phil on 18/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_REGISTRY_HPP_INCLUDED
#define TWOBLUECUBES_CATCH_REGISTRY_HPP_INCLUDED
@ -19,51 +15,26 @@ namespace Catch
{
template<typename C>
struct MethodTestCase : ITestCase
class MethodTestCase : public ITestCase
{
///////////////////////////////////////////////////////////////////////////
MethodTestCase
(
void (C::*method)()
)
: m_method( method )
{}
public:
MethodTestCase( void (C::*method)() ) : m_method( method ) {}
///////////////////////////////////////////////////////////////////////////
virtual void invoke
()
const
{
virtual void invoke() const {
C obj;
(obj.*m_method)();
}
///////////////////////////////////////////////////////////////////////////
virtual ITestCase* clone
()
const
{
virtual ITestCase* clone() const {
return new MethodTestCase<C>( m_method );
}
///////////////////////////////////////////////////////////////////////////
virtual bool operator ==
(
const ITestCase& other
)
const
{
virtual bool operator == ( const ITestCase& other ) const {
const MethodTestCase* mtOther = dynamic_cast<const MethodTestCase*>( &other );
return mtOther && m_method == mtOther->m_method;
}
///////////////////////////////////////////////////////////////////////////
virtual bool operator <
(
const ITestCase& other
)
const
{
virtual bool operator < ( const ITestCase& other ) const {
const MethodTestCase* mtOther = dynamic_cast<const MethodTestCase*>( &other );
return mtOther && &m_method < &mtOther->m_method;
}
@ -76,44 +47,29 @@ typedef void(*TestFunction)();
struct AutoReg
{
AutoReg
( TestFunction function,
const char* name,
const char* description,
const SourceLineInfo& lineInfo
);
AutoReg( TestFunction function,
const char* name,
const char* description,
const SourceLineInfo& lineInfo );
///////////////////////////////////////////////////////////////////////////
template<typename C>
AutoReg
(
void (C::*method)(),
const char* name,
const char* description,
const SourceLineInfo& lineInfo
)
{
AutoReg( void (C::*method)(),
const char* name,
const char* description,
const SourceLineInfo& lineInfo ) {
registerTestCase( new MethodTestCase<C>( method ), name, description, lineInfo );
}
///////////////////////////////////////////////////////////////////////////
void registerTestCase
(
ITestCase* testCase,
const char* name,
const char* description,
const SourceLineInfo& lineInfo
);
void registerTestCase( ITestCase* testCase,
const char* name,
const char* description,
const SourceLineInfo& lineInfo );
~AutoReg
();
~AutoReg();
private:
AutoReg
( const AutoReg& );
void operator=
( const AutoReg& );
AutoReg( const AutoReg& );
void operator= ( const AutoReg& );
};
} // end namespace Catch

View File

@ -12,32 +12,26 @@ namespace Catch
{
struct Counts
{
Counts
()
: passed( 0 ),
failed( 0 )
{}
Counts() : passed( 0 ), failed( 0 ) {}
Counts operator - ( const Counts& other ) const
{
Counts operator - ( const Counts& other ) const {
Counts diff;
diff.passed = passed - other.passed;
diff.failed = failed - other.failed;
return diff;
}
std::size_t total() const
{
std::size_t total() const {
return passed + failed;
}
std::size_t passed;
std::size_t failed;
};
struct Totals
{
Totals operator - ( const Totals& other ) const
{
Totals operator - ( const Totals& other ) const {
Totals diff;
diff.assertions = assertions - other.assertions;
diff.testCases = testCases - other.testCases;

View File

@ -165,42 +165,14 @@
4A6D0C45149B3E3D00DB3EAA /* internal */ = {
isa = PBXGroup;
children = (
4AC91CC3155C38D300DC5117 /* Objective-C */,
4AC91CC2155C388300DC5117 /* Infrastructure */,
4AC91CC1155C387400DC5117 /* Interfaces */,
4AC91CC0155C384400DC5117 /* Process */,
4AC91CBF155C381600DC5117 /* Test execution */,
4AC91CBE155C37F800DC5117 /* Registries */,
4AC91CBD155C37B500DC5117 /* Assertions */,
4AC91CB4155B9EBF00DC5117 /* impl */,
4A6D0C46149B3E3D00DB3EAA /* catch_approx.hpp */,
4A6D0C47149B3E3D00DB3EAA /* catch_capture.hpp */,
4A6D0C48149B3E3D00DB3EAA /* catch_commandline.hpp */,
4A6D0C49149B3E3D00DB3EAA /* catch_common.h */,
4A6D0C4A149B3E3D00DB3EAA /* catch_config.hpp */,
4A6D0C4B149B3E3D00DB3EAA /* catch_debugger.hpp */,
4A6D0C4C149B3E3D00DB3EAA /* catch_default_main.hpp */,
4A6D0C4D149B3E3D00DB3EAA /* catch_evaluate.hpp */,
4A6D0C4E149B3E3D00DB3EAA /* catch_exception_translator_registry.hpp */,
4A6D0C4F149B3E3D00DB3EAA /* catch_generators.hpp */,
4A6D0C51149B3E3D00DB3EAA /* catch_context.h */,
4A6D0C53149B3E3D00DB3EAA /* catch_interfaces_capture.h */,
4A6D0C54149B3E3D00DB3EAA /* catch_interfaces_exception.h */,
4A6D0C55149B3E3D00DB3EAA /* catch_interfaces_reporter.h */,
4A6D0C56149B3E3D00DB3EAA /* catch_interfaces_runner.h */,
4A6D0C57149B3E3D00DB3EAA /* catch_interfaces_testcase.h */,
4A6D0C58149B3E3D00DB3EAA /* catch_list.hpp */,
4A6D0C59149B3E3D00DB3EAA /* catch_objc.hpp */,
4A6D0C5A149B3E3D00DB3EAA /* catch_reporter_registrars.hpp */,
4A6D0C5B149B3E3D00DB3EAA /* catch_reporter_registry.hpp */,
4A6D0C5C149B3E3D00DB3EAA /* catch_result_type.h */,
4A6D0C5D149B3E3D00DB3EAA /* catch_resultinfo.hpp */,
4A9D84B315599AC900FBB209 /* catch_resultinfo_builder.hpp */,
4A6D0C5F149B3E3D00DB3EAA /* catch_section.hpp */,
4A6D0C60149B3E3D00DB3EAA /* catch_stream.hpp */,
4A6D0C61149B3E3D00DB3EAA /* catch_test_case_info.hpp */,
4A6D0C63149B3E3D00DB3EAA /* catch_test_registry.hpp */,
4A6D0C64149B3E3D00DB3EAA /* catch_xmlwriter.hpp */,
4A7ADB4314F631E10094FE10 /* catch_totals.hpp */,
4AB1C73714F97C1300F31DF7 /* catch_console_colour.hpp */,
4A3D7DD01503869D005F9203 /* catch_matchers.hpp */,
4AB77CB51551AEA200857BF0 /* catch_ptr.hpp */,
4AB77CB71553B72B00857BF0 /* catch_section_info.hpp */,
4AB77CB81553BB3800857BF0 /* catch_running_test.hpp */,
4A9D84B11558FC0400FBB209 /* catch_tostring.hpp */,
);
name = internal;
path = ../../../../include/internal;
@ -229,6 +201,90 @@
name = impl;
sourceTree = "<group>";
};
4AC91CBD155C37B500DC5117 /* Assertions */ = {
isa = PBXGroup;
children = (
4A6D0C4D149B3E3D00DB3EAA /* catch_evaluate.hpp */,
4A6D0C4F149B3E3D00DB3EAA /* catch_generators.hpp */,
4A6D0C5C149B3E3D00DB3EAA /* catch_result_type.h */,
4A6D0C5D149B3E3D00DB3EAA /* catch_resultinfo.hpp */,
4A9D84B315599AC900FBB209 /* catch_resultinfo_builder.hpp */,
4A6D0C5F149B3E3D00DB3EAA /* catch_section.hpp */,
4A3D7DD01503869D005F9203 /* catch_matchers.hpp */,
4A9D84B11558FC0400FBB209 /* catch_tostring.hpp */,
4A6D0C46149B3E3D00DB3EAA /* catch_approx.hpp */,
4A6D0C47149B3E3D00DB3EAA /* catch_capture.hpp */,
);
name = Assertions;
sourceTree = "<group>";
};
4AC91CBE155C37F800DC5117 /* Registries */ = {
isa = PBXGroup;
children = (
4A6D0C4E149B3E3D00DB3EAA /* catch_exception_translator_registry.hpp */,
4A6D0C5A149B3E3D00DB3EAA /* catch_reporter_registrars.hpp */,
4A6D0C5B149B3E3D00DB3EAA /* catch_reporter_registry.hpp */,
4A6D0C63149B3E3D00DB3EAA /* catch_test_registry.hpp */,
);
name = Registries;
sourceTree = "<group>";
};
4AC91CBF155C381600DC5117 /* Test execution */ = {
isa = PBXGroup;
children = (
4A6D0C4A149B3E3D00DB3EAA /* catch_config.hpp */,
4A6D0C51149B3E3D00DB3EAA /* catch_context.h */,
4A6D0C61149B3E3D00DB3EAA /* catch_test_case_info.hpp */,
4A7ADB4314F631E10094FE10 /* catch_totals.hpp */,
4AB77CB71553B72B00857BF0 /* catch_section_info.hpp */,
4AB77CB81553BB3800857BF0 /* catch_running_test.hpp */,
);
name = "Test execution";
sourceTree = "<group>";
};
4AC91CC0155C384400DC5117 /* Process */ = {
isa = PBXGroup;
children = (
4A6D0C58149B3E3D00DB3EAA /* catch_list.hpp */,
4A6D0C48149B3E3D00DB3EAA /* catch_commandline.hpp */,
4A6D0C4C149B3E3D00DB3EAA /* catch_default_main.hpp */,
);
name = Process;
sourceTree = "<group>";
};
4AC91CC1155C387400DC5117 /* Interfaces */ = {
isa = PBXGroup;
children = (
4A6D0C53149B3E3D00DB3EAA /* catch_interfaces_capture.h */,
4A6D0C54149B3E3D00DB3EAA /* catch_interfaces_exception.h */,
4A6D0C55149B3E3D00DB3EAA /* catch_interfaces_reporter.h */,
4A6D0C56149B3E3D00DB3EAA /* catch_interfaces_runner.h */,
4A6D0C57149B3E3D00DB3EAA /* catch_interfaces_testcase.h */,
);
name = Interfaces;
sourceTree = "<group>";
};
4AC91CC2155C388300DC5117 /* Infrastructure */ = {
isa = PBXGroup;
children = (
4A6D0C49149B3E3D00DB3EAA /* catch_common.h */,
4A6D0C4B149B3E3D00DB3EAA /* catch_debugger.hpp */,
4A6D0C60149B3E3D00DB3EAA /* catch_stream.hpp */,
4A6D0C64149B3E3D00DB3EAA /* catch_xmlwriter.hpp */,
4AB1C73714F97C1300F31DF7 /* catch_console_colour.hpp */,
4AB77CB51551AEA200857BF0 /* catch_ptr.hpp */,
);
name = Infrastructure;
sourceTree = "<group>";
};
4AC91CC3155C38D300DC5117 /* Objective-C */ = {
isa = PBXGroup;
children = (
4A6D0C59149B3E3D00DB3EAA /* catch_objc.hpp */,
);
name = "Objective-C";
sourceTree = "<group>";
};
/* End PBXGroup section */
/* Begin PBXNativeTarget section */