mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-29 16:53:30 +01:00
Some more refactoring/ cleaning of test case files
This commit is contained in:
parent
95627c40cf
commit
fd58d48665
@ -43,13 +43,14 @@
|
|||||||
4A992A6612B21582002B7B66 /* catch_reporter_junit.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = catch_reporter_junit.hpp; path = ../catch_reporter_junit.hpp; sourceTree = SOURCE_ROOT; };
|
4A992A6612B21582002B7B66 /* catch_reporter_junit.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = catch_reporter_junit.hpp; path = ../catch_reporter_junit.hpp; sourceTree = SOURCE_ROOT; };
|
||||||
4AA7EA9112A438C7005A0B97 /* MiscTests.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MiscTests.cpp; sourceTree = "<group>"; };
|
4AA7EA9112A438C7005A0B97 /* MiscTests.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MiscTests.cpp; sourceTree = "<group>"; };
|
||||||
4AD6775912D71DA0005AAF59 /* catch_test_case_registry_impl.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = catch_test_case_registry_impl.hpp; path = ../internal/catch_test_case_registry_impl.hpp; sourceTree = SOURCE_ROOT; };
|
4AD6775912D71DA0005AAF59 /* catch_test_case_registry_impl.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = catch_test_case_registry_impl.hpp; path = ../internal/catch_test_case_registry_impl.hpp; sourceTree = SOURCE_ROOT; };
|
||||||
|
4AD677B212D7A53E005AAF59 /* catch_interfaces_testcase.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = catch_interfaces_testcase.h; path = ../internal/catch_interfaces_testcase.h; sourceTree = SOURCE_ROOT; };
|
||||||
4AFC341512809A36003A0C29 /* catch_capture.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = catch_capture.hpp; path = ../internal/catch_capture.hpp; sourceTree = SOURCE_ROOT; };
|
4AFC341512809A36003A0C29 /* catch_capture.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = catch_capture.hpp; path = ../internal/catch_capture.hpp; sourceTree = SOURCE_ROOT; };
|
||||||
4AFC341612809A36003A0C29 /* catch_common.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = catch_common.h; path = ../internal/catch_common.h; sourceTree = SOURCE_ROOT; };
|
4AFC341612809A36003A0C29 /* catch_common.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = catch_common.h; path = ../internal/catch_common.h; sourceTree = SOURCE_ROOT; };
|
||||||
4AFC341712809A36003A0C29 /* catch_test_registry.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = catch_test_registry.hpp; path = ../internal/catch_test_registry.hpp; sourceTree = SOURCE_ROOT; };
|
4AFC341712809A36003A0C29 /* catch_test_registry.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = catch_test_registry.hpp; path = ../internal/catch_test_registry.hpp; sourceTree = SOURCE_ROOT; };
|
||||||
4AFC341812809A36003A0C29 /* catch_reporter_registry.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = catch_reporter_registry.hpp; path = ../internal/catch_reporter_registry.hpp; sourceTree = SOURCE_ROOT; };
|
4AFC341812809A36003A0C29 /* catch_reporter_registry.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = catch_reporter_registry.hpp; path = ../internal/catch_reporter_registry.hpp; sourceTree = SOURCE_ROOT; };
|
||||||
4AFC341912809A36003A0C29 /* catch_resultinfo.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = catch_resultinfo.hpp; path = ../internal/catch_resultinfo.hpp; sourceTree = SOURCE_ROOT; };
|
4AFC341912809A36003A0C29 /* catch_resultinfo.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = catch_resultinfo.hpp; path = ../internal/catch_resultinfo.hpp; sourceTree = SOURCE_ROOT; };
|
||||||
4AFC341A12809A36003A0C29 /* catch_runner_impl.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = catch_runner_impl.hpp; path = ../internal/catch_runner_impl.hpp; sourceTree = SOURCE_ROOT; };
|
4AFC341A12809A36003A0C29 /* catch_runner_impl.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = catch_runner_impl.hpp; path = ../internal/catch_runner_impl.hpp; sourceTree = SOURCE_ROOT; };
|
||||||
4AFC341B12809A36003A0C29 /* catch_testcase.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = catch_testcase.hpp; path = ../internal/catch_testcase.hpp; sourceTree = SOURCE_ROOT; };
|
4AFC341B12809A36003A0C29 /* catch_test_case_info.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = catch_test_case_info.hpp; path = ../internal/catch_test_case_info.hpp; sourceTree = SOURCE_ROOT; };
|
||||||
4AFC341C12809A45003A0C29 /* catch_default_main.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = catch_default_main.hpp; path = ../catch_default_main.hpp; sourceTree = SOURCE_ROOT; };
|
4AFC341C12809A45003A0C29 /* catch_default_main.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = catch_default_main.hpp; path = ../catch_default_main.hpp; sourceTree = SOURCE_ROOT; };
|
||||||
4AFC341D12809A45003A0C29 /* catch_reporter_basic.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = catch_reporter_basic.hpp; path = ../catch_reporter_basic.hpp; sourceTree = SOURCE_ROOT; };
|
4AFC341D12809A45003A0C29 /* catch_reporter_basic.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = catch_reporter_basic.hpp; path = ../catch_reporter_basic.hpp; sourceTree = SOURCE_ROOT; };
|
||||||
4AFC341E12809A45003A0C29 /* catch_reporter_xml.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = catch_reporter_xml.hpp; path = ../catch_reporter_xml.hpp; sourceTree = SOURCE_ROOT; };
|
4AFC341E12809A45003A0C29 /* catch_reporter_xml.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = catch_reporter_xml.hpp; path = ../catch_reporter_xml.hpp; sourceTree = SOURCE_ROOT; };
|
||||||
@ -111,7 +112,8 @@
|
|||||||
4AFC359B1281F00B003A0C29 /* catch_section.hpp */,
|
4AFC359B1281F00B003A0C29 /* catch_section.hpp */,
|
||||||
4AFC341512809A36003A0C29 /* catch_capture.hpp */,
|
4AFC341512809A36003A0C29 /* catch_capture.hpp */,
|
||||||
4AFC341712809A36003A0C29 /* catch_test_registry.hpp */,
|
4AFC341712809A36003A0C29 /* catch_test_registry.hpp */,
|
||||||
4AFC341B12809A36003A0C29 /* catch_testcase.hpp */,
|
4AFC341B12809A36003A0C29 /* catch_test_case_info.hpp */,
|
||||||
|
4AD677B212D7A53E005AAF59 /* catch_interfaces_testcase.h */,
|
||||||
);
|
);
|
||||||
name = "TestCase registration";
|
name = "TestCase registration";
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
|
40
internal/catch_interfaces_testcase.h
Normal file
40
internal/catch_interfaces_testcase.h
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
/*
|
||||||
|
* catch_interfaces_testcase.h
|
||||||
|
* Test
|
||||||
|
*
|
||||||
|
* Created by Phil on 07/01/2011.
|
||||||
|
* Copyright 2011 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_INTERFACES_TESTCASE_H_INCLUDED
|
||||||
|
#define TWOBLUECUBES_CATCH_INTERFACES_TESTCASE_H_INCLUDED
|
||||||
|
|
||||||
|
namespace Catch
|
||||||
|
{
|
||||||
|
struct ITestCase
|
||||||
|
{
|
||||||
|
virtual ~ITestCase
|
||||||
|
()
|
||||||
|
{}
|
||||||
|
|
||||||
|
virtual void invoke
|
||||||
|
() const = 0;
|
||||||
|
|
||||||
|
virtual ITestCase* clone
|
||||||
|
() const = 0;
|
||||||
|
|
||||||
|
virtual bool operator ==
|
||||||
|
( const ITestCase& other
|
||||||
|
) const = 0;
|
||||||
|
|
||||||
|
virtual bool operator <
|
||||||
|
( const ITestCase& other
|
||||||
|
) const = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
#endif // TWOBLUECUBES_CATCH_INTERFACES_TESTCASE_H_INCLUDED
|
142
internal/catch_test_case_info.hpp
Normal file
142
internal/catch_test_case_info.hpp
Normal file
@ -0,0 +1,142 @@
|
|||||||
|
/*
|
||||||
|
* 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
|
||||||
|
|
||||||
|
#include "catch_interfaces_testcase.h"
|
||||||
|
#include <map>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace Catch
|
||||||
|
{
|
||||||
|
class TestCaseInfo
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
///////////////////////////////////////////////////////////////////////
|
||||||
|
TestCaseInfo
|
||||||
|
(
|
||||||
|
ITestCase* testCase,
|
||||||
|
const char* name,
|
||||||
|
const char* description
|
||||||
|
)
|
||||||
|
: m_test( testCase ),
|
||||||
|
m_name( name ),
|
||||||
|
m_description( description )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////
|
||||||
|
TestCaseInfo
|
||||||
|
()
|
||||||
|
: m_test( NULL )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////
|
||||||
|
TestCaseInfo
|
||||||
|
(
|
||||||
|
const TestCaseInfo& other
|
||||||
|
)
|
||||||
|
: m_test( other.m_test->clone() ),
|
||||||
|
m_name( other.m_name ),
|
||||||
|
m_description( other.m_description )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////
|
||||||
|
TestCaseInfo& operator =
|
||||||
|
(
|
||||||
|
const TestCaseInfo& other
|
||||||
|
)
|
||||||
|
{
|
||||||
|
TestCaseInfo temp( other );
|
||||||
|
swap( temp );
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////
|
||||||
|
~TestCaseInfo
|
||||||
|
()
|
||||||
|
{
|
||||||
|
delete m_test;
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////
|
||||||
|
void invoke
|
||||||
|
()
|
||||||
|
const
|
||||||
|
{
|
||||||
|
m_test->invoke();
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////
|
||||||
|
const std::string& getName
|
||||||
|
()
|
||||||
|
const
|
||||||
|
{
|
||||||
|
return m_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////
|
||||||
|
const std::string& getDescription
|
||||||
|
()
|
||||||
|
const
|
||||||
|
{
|
||||||
|
return m_description;
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////
|
||||||
|
void swap
|
||||||
|
(
|
||||||
|
TestCaseInfo& other
|
||||||
|
)
|
||||||
|
{
|
||||||
|
std::swap( m_test, other.m_test );
|
||||||
|
m_name.swap( other.m_name );
|
||||||
|
m_description.swap( other.m_description );
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////
|
||||||
|
bool operator ==
|
||||||
|
(
|
||||||
|
const TestCaseInfo& other
|
||||||
|
)
|
||||||
|
const
|
||||||
|
{
|
||||||
|
return *m_test == *other.m_test && m_name == other.m_name && m_description == other.m_description;
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////
|
||||||
|
bool operator <
|
||||||
|
(
|
||||||
|
const TestCaseInfo& other
|
||||||
|
)
|
||||||
|
const
|
||||||
|
{
|
||||||
|
if( m_name < other.m_name )
|
||||||
|
return true;
|
||||||
|
if( m_name > other.m_name )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return *m_test < *other.m_test;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
ITestCase* m_test;
|
||||||
|
std::string m_name;
|
||||||
|
std::string m_description;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // TWOBLUECUBES_CATCH_TESTCASEINFO_HPP_INCLUDED
|
@ -11,6 +11,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "catch_test_registry.hpp"
|
#include "catch_test_registry.hpp"
|
||||||
|
#include "catch_test_case_info.hpp"
|
||||||
#include "catch_hub.h"
|
#include "catch_hub.h"
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@ -42,8 +43,6 @@ namespace Catch
|
|||||||
std::vector<TestCaseInfo> m_functionsInOrder;
|
std::vector<TestCaseInfo> m_functionsInOrder;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef void(*TestFunction)();
|
|
||||||
|
|
||||||
struct FreeFunctionTestCase : ITestCase
|
struct FreeFunctionTestCase : ITestCase
|
||||||
{
|
{
|
||||||
FreeFunctionTestCase( TestFunction fun )
|
FreeFunctionTestCase( TestFunction fun )
|
||||||
|
@ -12,12 +12,11 @@
|
|||||||
#ifndef TWOBLUECUBES_CATCH_REGISTRY_HPP_INCLUDED
|
#ifndef TWOBLUECUBES_CATCH_REGISTRY_HPP_INCLUDED
|
||||||
#define TWOBLUECUBES_CATCH_REGISTRY_HPP_INCLUDED
|
#define TWOBLUECUBES_CATCH_REGISTRY_HPP_INCLUDED
|
||||||
|
|
||||||
#include "catch_testcase.hpp"
|
|
||||||
#include "catch_common.h"
|
#include "catch_common.h"
|
||||||
|
#include "catch_interfaces_testcase.h"
|
||||||
|
|
||||||
namespace Catch
|
namespace Catch
|
||||||
{
|
{
|
||||||
typedef void(*TestFunction)();
|
|
||||||
|
|
||||||
template<typename C>
|
template<typename C>
|
||||||
struct MethodTestCase : ITestCase
|
struct MethodTestCase : ITestCase
|
||||||
@ -53,6 +52,8 @@ private:
|
|||||||
void (C::*method)();
|
void (C::*method)();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
typedef void(*TestFunction)();
|
||||||
|
|
||||||
struct AutoReg
|
struct AutoReg
|
||||||
{
|
{
|
||||||
AutoReg( TestFunction function, const char* name, const char* description );
|
AutoReg( TestFunction function, const char* name, const char* description );
|
||||||
|
@ -1,107 +0,0 @@
|
|||||||
/*
|
|
||||||
* catch_testcase.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
|
|
||||||
|
|
||||||
#include <map>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
namespace Catch
|
|
||||||
{
|
|
||||||
struct ITestCase
|
|
||||||
{
|
|
||||||
virtual ~ITestCase(){}
|
|
||||||
virtual void invoke() const = 0;
|
|
||||||
virtual ITestCase* clone() const = 0;
|
|
||||||
virtual bool operator == ( const ITestCase& other ) const = 0;
|
|
||||||
virtual bool operator < ( const ITestCase& other ) const = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
class TestCaseInfo
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
TestCaseInfo( ITestCase* testCase, const char* name, const char* description )
|
|
||||||
: test( testCase ),
|
|
||||||
name( name ),
|
|
||||||
description( description )
|
|
||||||
{
|
|
||||||
}
|
|
||||||
TestCaseInfo()
|
|
||||||
: test( NULL )
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
TestCaseInfo( const TestCaseInfo& other )
|
|
||||||
: test( other.test->clone() ),
|
|
||||||
name( other.name ),
|
|
||||||
description( other.description )
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
TestCaseInfo& operator = ( const TestCaseInfo& other )
|
|
||||||
{
|
|
||||||
TestCaseInfo temp( other );
|
|
||||||
swap( temp );
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
~TestCaseInfo()
|
|
||||||
{
|
|
||||||
delete test;
|
|
||||||
}
|
|
||||||
|
|
||||||
void invoke() const
|
|
||||||
{
|
|
||||||
test->invoke();
|
|
||||||
}
|
|
||||||
|
|
||||||
const std::string& getName() const
|
|
||||||
{
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
const std::string& getDescription() const
|
|
||||||
{
|
|
||||||
return description;
|
|
||||||
}
|
|
||||||
|
|
||||||
void swap( TestCaseInfo& other )
|
|
||||||
{
|
|
||||||
std::swap( test, other.test );
|
|
||||||
name.swap( other.name );
|
|
||||||
description.swap( other.description );
|
|
||||||
}
|
|
||||||
|
|
||||||
bool operator == ( const TestCaseInfo& other ) const
|
|
||||||
{
|
|
||||||
return *test == *other.test && name == other.name && description == other.description;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool operator < ( const TestCaseInfo& other ) const
|
|
||||||
{
|
|
||||||
if( name < other.name )
|
|
||||||
return true;
|
|
||||||
if( name > other.name )
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return *test < *other.test;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
ITestCase* test;
|
|
||||||
std::string name;
|
|
||||||
std::string description;
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // TWOBLUECUBES_CATCH_TESTCASEINFO_HPP_INCLUDED
|
|
Loading…
Reference in New Issue
Block a user