Moved catch_test_spec.h to catch_test_spec.hpp

This commit is contained in:
Phil Nash 2014-05-16 18:28:58 +01:00
parent ae75b3774a
commit b1e7d161b5
9 changed files with 114 additions and 131 deletions

View File

@ -11,7 +11,7 @@
#include "internal/catch_commandline.hpp"
#include "internal/catch_list.hpp"
#include "internal/catch_runner_impl.hpp"
#include "internal/catch_test_spec.h"
#include "internal/catch_test_spec.hpp"
#include "internal/catch_version.h"
#include "internal/catch_text.h"

View File

@ -16,7 +16,7 @@
#include "catch_test_case_info.h"
#include "catch_capture.hpp"
#include "catch_totals.hpp"
#include "catch_test_spec.h"
#include "catch_test_spec.hpp"
#include "catch_test_case_tracker.hpp"
#include "catch_timer.h"

View File

@ -8,7 +8,7 @@
#ifndef TWOBLUECUBES_CATCH_TEST_CASE_INFO_HPP_INCLUDED
#define TWOBLUECUBES_CATCH_TEST_CASE_INFO_HPP_INCLUDED
#include "catch_test_spec.h"
#include "catch_test_spec.hpp"
#include "catch_test_case_info.h"
#include "catch_interfaces_testcase.h"
#include "catch_tags.h"

View File

@ -10,7 +10,7 @@
#include "catch_test_registry.hpp"
#include "catch_test_case_info.h"
#include "catch_test_spec.h"
#include "catch_test_spec.hpp"
#include "catch_context.h"
#include <vector>

View File

@ -1,118 +0,0 @@
/*
* Created by Phil on 14/8/2012.
* 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_TEST_SPEC_H_INCLUDED
#define TWOBLUECUBES_CATCH_TEST_SPEC_H_INCLUDED
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wpadded"
#endif
#include "catch_test_case_info.h"
#include <string>
#include <vector>
namespace Catch {
class TestSpec {
struct Pattern : SharedImpl<> {
virtual ~Pattern();
virtual bool matches( TestCaseInfo const& testCase ) const = 0;
};
class NamePattern : public Pattern {
enum WildcardPosition {
NoWildcard = 0,
WildcardAtStart = 1,
WildcardAtEnd = 2,
WildcardAtBothEnds = WildcardAtStart | WildcardAtEnd
};
public:
NamePattern( std::string const& name ) : m_name( toLower( name ) ), m_wildcard( NoWildcard ) {
if( startsWith( m_name, "*" ) ) {
m_name = name.substr( 1 );
m_wildcard = WildcardAtStart;
}
if( endsWith( m_name, "*" ) ) {
m_name = m_name.substr( 0, m_name.size()-1 );
m_wildcard = (WildcardPosition)( m_wildcard | WildcardAtEnd );
}
}
virtual ~NamePattern();
virtual bool matches( TestCaseInfo const& testCase ) const {
switch( m_wildcard ) {
case NoWildcard:
return m_name == toLower( testCase.name );
case WildcardAtStart:
return endsWith( toLower( testCase.name ), m_name );
case WildcardAtEnd:
return startsWith( toLower( testCase.name ), m_name );
case WildcardAtBothEnds:
return contains( toLower( testCase.name ), m_name );
}
}
private:
std::string m_name;
WildcardPosition m_wildcard;
};
class TagPattern : public Pattern {
public:
TagPattern( std::string const& tag ) : m_tag( toLower( tag ) ) {}
virtual ~TagPattern();
virtual bool matches( TestCaseInfo const& testCase ) const {
return testCase.tags.find( m_tag ) != testCase.tags.end();
}
private:
std::string m_tag;
};
class ExcludedPattern : public Pattern {
public:
ExcludedPattern( Ptr<Pattern> const& underlyingPattern ) : m_underlyingPattern( underlyingPattern ) {}
virtual ~ExcludedPattern();
virtual bool matches( TestCaseInfo const& testCase ) const { return !m_underlyingPattern->matches( testCase ); }
private:
Ptr<Pattern> m_underlyingPattern;
};
struct Filter {
std::vector<Ptr<Pattern> > m_patterns;
bool matches( TestCaseInfo const& testCase ) const {
// All patterns in a filter must match for the filter to be a match
for( std::vector<Ptr<Pattern> >::const_iterator it = m_patterns.begin(), itEnd = m_patterns.end(); it != itEnd; ++it )
if( !(*it)->matches( testCase ) )
return false;
return true;
}
};
public:
bool hasFilters() const {
return !m_filters.empty();
}
bool matches( TestCaseInfo const& testCase ) const {
// A TestSpec matches if any filter matches
for( std::vector<Filter>::const_iterator it = m_filters.begin(), itEnd = m_filters.end(); it != itEnd; ++it )
if( it->matches( testCase ) )
return true;
return false;
}
private:
std::vector<Filter> m_filters;
friend class TestSpecParser;
};
}
#ifdef __clang__
#pragma clang diagnostic pop
#endif
#endif // TWOBLUECUBES_CATCH_TEST_SPEC_H_INCLUDED

View File

@ -1,6 +1,6 @@
/*
* Created by Phil on 2/12/2013.
* Copyright 2013 Two Blue Cubes Ltd. All rights reserved.
* Created by Phil on 14/8/2012.
* 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)
@ -8,8 +8,111 @@
#ifndef TWOBLUECUBES_CATCH_TEST_SPEC_HPP_INCLUDED
#define TWOBLUECUBES_CATCH_TEST_SPEC_HPP_INCLUDED
#include "catch_test_spec.hpp"
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wpadded"
#endif
// deprecated
#include "catch_test_case_info.h"
#include <string>
#include <vector>
namespace Catch {
class TestSpec {
struct Pattern : SharedImpl<> {
virtual ~Pattern();
virtual bool matches( TestCaseInfo const& testCase ) const = 0;
};
class NamePattern : public Pattern {
enum WildcardPosition {
NoWildcard = 0,
WildcardAtStart = 1,
WildcardAtEnd = 2,
WildcardAtBothEnds = WildcardAtStart | WildcardAtEnd
};
public:
NamePattern( std::string const& name ) : m_name( toLower( name ) ), m_wildcard( NoWildcard ) {
if( startsWith( m_name, "*" ) ) {
m_name = name.substr( 1 );
m_wildcard = WildcardAtStart;
}
if( endsWith( m_name, "*" ) ) {
m_name = m_name.substr( 0, m_name.size()-1 );
m_wildcard = (WildcardPosition)( m_wildcard | WildcardAtEnd );
}
}
virtual ~NamePattern();
virtual bool matches( TestCaseInfo const& testCase ) const {
switch( m_wildcard ) {
case NoWildcard:
return m_name == toLower( testCase.name );
case WildcardAtStart:
return endsWith( toLower( testCase.name ), m_name );
case WildcardAtEnd:
return startsWith( toLower( testCase.name ), m_name );
case WildcardAtBothEnds:
return contains( toLower( testCase.name ), m_name );
}
}
private:
std::string m_name;
WildcardPosition m_wildcard;
};
class TagPattern : public Pattern {
public:
TagPattern( std::string const& tag ) : m_tag( toLower( tag ) ) {}
virtual ~TagPattern();
virtual bool matches( TestCaseInfo const& testCase ) const {
return testCase.tags.find( m_tag ) != testCase.tags.end();
}
private:
std::string m_tag;
};
class ExcludedPattern : public Pattern {
public:
ExcludedPattern( Ptr<Pattern> const& underlyingPattern ) : m_underlyingPattern( underlyingPattern ) {}
virtual ~ExcludedPattern();
virtual bool matches( TestCaseInfo const& testCase ) const { return !m_underlyingPattern->matches( testCase ); }
private:
Ptr<Pattern> m_underlyingPattern;
};
struct Filter {
std::vector<Ptr<Pattern> > m_patterns;
bool matches( TestCaseInfo const& testCase ) const {
// All patterns in a filter must match for the filter to be a match
for( std::vector<Ptr<Pattern> >::const_iterator it = m_patterns.begin(), itEnd = m_patterns.end(); it != itEnd; ++it )
if( !(*it)->matches( testCase ) )
return false;
return true;
}
};
public:
bool hasFilters() const {
return !m_filters.empty();
}
bool matches( TestCaseInfo const& testCase ) const {
// A TestSpec matches if any filter matches
for( std::vector<Filter>::const_iterator it = m_filters.begin(), itEnd = m_filters.end(); it != itEnd; ++it )
if( it->matches( testCase ) )
return true;
return false;
}
private:
std::vector<Filter> m_filters;
friend class TestSpecParser;
};
}
#ifdef __clang__
#pragma clang diagnostic pop
#endif
#endif // TWOBLUECUBES_CATCH_TEST_SPEC_HPP_INCLUDED

View File

@ -13,7 +13,7 @@
#pragma clang diagnostic ignored "-Wpadded"
#endif
#include "catch_test_spec.h"
#include "catch_test_spec.hpp"
namespace Catch {

View File

@ -1,2 +1,2 @@
// This file is only here to verify (to the extent possible) the self sufficiency of the header
#include "catch_test_spec.h"
#include "catch_test_spec.hpp"

View File

@ -93,7 +93,6 @@
26DACF2F17206D3400A21326 /* catch_text.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = catch_text.h; sourceTree = "<group>"; };
26E1B7D119213BC900812682 /* CmdLineTests.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CmdLineTests.cpp; path = ../../../SelfTest/CmdLineTests.cpp; sourceTree = "<group>"; };
4A084F1C15DACEEA0027E631 /* catch_test_case_info.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = catch_test_case_info.hpp; sourceTree = "<group>"; };
4A084F1D15DAD15F0027E631 /* catch_test_spec.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = catch_test_spec.h; sourceTree = "<group>"; };
4A3D7DD01503869D005F9203 /* catch_matchers.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = catch_matchers.hpp; sourceTree = "<group>"; };
4A45DA2316161EF9004F8D6B /* catch_console_colour.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = catch_console_colour.cpp; path = ../../../SelfTest/SurrogateCpps/catch_console_colour.cpp; sourceTree = "<group>"; };
4A45DA2616161F1F004F8D6B /* catch_ptr.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = catch_ptr.cpp; path = ../../../SelfTest/SurrogateCpps/catch_ptr.cpp; sourceTree = "<group>"; };
@ -333,7 +332,6 @@
isa = PBXGroup;
children = (
4A6D0C5F149B3E3D00DB3EAA /* catch_section.hpp */,
261488FA184C81130041FBEB /* catch_test_spec.hpp */,
263FD06017AF8DF200988A20 /* catch_timer.hpp */,
4A4B0F9C15CEFA8300AE2392 /* catch_impl.hpp */,
4A4B0F9715CE6CFB00AE2392 /* catch_registry_hub.hpp */,
@ -388,6 +386,7 @@
4AC91CBF155C381600DC5117 /* Test execution */ = {
isa = PBXGroup;
children = (
261488FA184C81130041FBEB /* catch_test_spec.hpp */,
2656C2221925EC6F0040DB02 /* catch_tags.h */,
2656C2231925EC6F0040DB02 /* catch_tags.hpp */,
2656C21F1925E5100040DB02 /* catch_test_spec_parser.hpp */,
@ -396,7 +395,6 @@
4A6D0C61149B3E3D00DB3EAA /* catch_test_case_info.h */,
4A7ADB4314F631E10094FE10 /* catch_totals.hpp */,
4AB77CB71553B72B00857BF0 /* catch_section_info.hpp */,
4A084F1D15DAD15F0027E631 /* catch_test_spec.h */,
26948287179EF7F900ED166E /* catch_test_case_tracker.hpp */,
);
name = "Test execution";