mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-29 16:53:30 +01:00
Unify ITagAliasRegistry and TagAliasRegistry
This commit is contained in:
parent
cfe859e0f3
commit
cf4d84a349
@ -216,7 +216,6 @@ set(INTERFACE_HEADERS
|
|||||||
${SOURCES_DIR}/interfaces/catch_interfaces_registry_hub.hpp
|
${SOURCES_DIR}/interfaces/catch_interfaces_registry_hub.hpp
|
||||||
${SOURCES_DIR}/interfaces/catch_interfaces_reporter.hpp
|
${SOURCES_DIR}/interfaces/catch_interfaces_reporter.hpp
|
||||||
${SOURCES_DIR}/interfaces/catch_interfaces_reporter_factory.hpp
|
${SOURCES_DIR}/interfaces/catch_interfaces_reporter_factory.hpp
|
||||||
${SOURCES_DIR}/interfaces/catch_interfaces_tag_alias_registry.hpp
|
|
||||||
${SOURCES_DIR}/interfaces/catch_interfaces_testcase.hpp
|
${SOURCES_DIR}/interfaces/catch_interfaces_testcase.hpp
|
||||||
)
|
)
|
||||||
set(INTERFACE_SOURCES
|
set(INTERFACE_SOURCES
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
#include <catch2/internal/catch_stringref.hpp>
|
#include <catch2/internal/catch_stringref.hpp>
|
||||||
#include <catch2/internal/catch_string_manip.hpp>
|
#include <catch2/internal/catch_string_manip.hpp>
|
||||||
#include <catch2/internal/catch_test_spec_parser.hpp>
|
#include <catch2/internal/catch_test_spec_parser.hpp>
|
||||||
#include <catch2/interfaces/catch_interfaces_tag_alias_registry.hpp>
|
#include <catch2/internal/catch_tag_alias_registry.hpp>
|
||||||
#include <catch2/internal/catch_getenv.hpp>
|
#include <catch2/internal/catch_getenv.hpp>
|
||||||
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
@ -123,7 +123,7 @@ namespace Catch {
|
|||||||
|
|
||||||
// Bazel support can modify the test specs, so parsing has to happen
|
// Bazel support can modify the test specs, so parsing has to happen
|
||||||
// after reading Bazel env vars.
|
// after reading Bazel env vars.
|
||||||
TestSpecParser parser( ITagAliasRegistry::get() );
|
TestSpecParser parser( TagAliasRegistry::get() );
|
||||||
if ( !m_data.testsOrTags.empty() ) {
|
if ( !m_data.testsOrTags.empty() ) {
|
||||||
m_hasTestFilters = true;
|
m_hasTestFilters = true;
|
||||||
for ( auto const& testOrTags : m_data.testsOrTags ) {
|
for ( auto const& testOrTags : m_data.testsOrTags ) {
|
||||||
|
@ -41,7 +41,7 @@ namespace Catch {
|
|||||||
ExceptionTranslatorRegistry const& getExceptionTranslatorRegistry() const override {
|
ExceptionTranslatorRegistry const& getExceptionTranslatorRegistry() const override {
|
||||||
return m_exceptionTranslatorRegistry;
|
return m_exceptionTranslatorRegistry;
|
||||||
}
|
}
|
||||||
ITagAliasRegistry const& getTagAliasRegistry() const override {
|
TagAliasRegistry const& getTagAliasRegistry() const override {
|
||||||
return m_tagAliasRegistry;
|
return m_tagAliasRegistry;
|
||||||
}
|
}
|
||||||
StartupExceptionRegistry const& getStartupExceptionRegistry() const override {
|
StartupExceptionRegistry const& getStartupExceptionRegistry() const override {
|
||||||
|
@ -29,7 +29,6 @@
|
|||||||
#include <catch2/interfaces/catch_interfaces_registry_hub.hpp>
|
#include <catch2/interfaces/catch_interfaces_registry_hub.hpp>
|
||||||
#include <catch2/interfaces/catch_interfaces_reporter.hpp>
|
#include <catch2/interfaces/catch_interfaces_reporter.hpp>
|
||||||
#include <catch2/interfaces/catch_interfaces_reporter_factory.hpp>
|
#include <catch2/interfaces/catch_interfaces_reporter_factory.hpp>
|
||||||
#include <catch2/interfaces/catch_interfaces_tag_alias_registry.hpp>
|
|
||||||
#include <catch2/interfaces/catch_interfaces_testcase.hpp>
|
#include <catch2/interfaces/catch_interfaces_testcase.hpp>
|
||||||
|
|
||||||
#endif // CATCH_INTERFACES_ALL_HPP_INCLUDED
|
#endif // CATCH_INTERFACES_ALL_HPP_INCLUDED
|
||||||
|
@ -21,7 +21,7 @@ namespace Catch {
|
|||||||
class IExceptionTranslator;
|
class IExceptionTranslator;
|
||||||
class ReporterRegistry;
|
class ReporterRegistry;
|
||||||
class IReporterFactory;
|
class IReporterFactory;
|
||||||
class ITagAliasRegistry;
|
class TagAliasRegistry;
|
||||||
class ITestInvoker;
|
class ITestInvoker;
|
||||||
class EnumValuesRegistry;
|
class EnumValuesRegistry;
|
||||||
struct SourceLineInfo;
|
struct SourceLineInfo;
|
||||||
@ -37,7 +37,7 @@ namespace Catch {
|
|||||||
|
|
||||||
virtual ReporterRegistry const& getReporterRegistry() const = 0;
|
virtual ReporterRegistry const& getReporterRegistry() const = 0;
|
||||||
virtual ITestCaseRegistry const& getTestCaseRegistry() const = 0;
|
virtual ITestCaseRegistry const& getTestCaseRegistry() const = 0;
|
||||||
virtual ITagAliasRegistry const& getTagAliasRegistry() const = 0;
|
virtual TagAliasRegistry const& getTagAliasRegistry() const = 0;
|
||||||
virtual ExceptionTranslatorRegistry const& getExceptionTranslatorRegistry() const = 0;
|
virtual ExceptionTranslatorRegistry const& getExceptionTranslatorRegistry() const = 0;
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,29 +0,0 @@
|
|||||||
|
|
||||||
// Copyright Catch2 Authors
|
|
||||||
// Distributed under the Boost Software License, Version 1.0.
|
|
||||||
// (See accompanying file LICENSE.txt or copy at
|
|
||||||
// https://www.boost.org/LICENSE_1_0.txt)
|
|
||||||
|
|
||||||
// SPDX-License-Identifier: BSL-1.0
|
|
||||||
#ifndef CATCH_INTERFACES_TAG_ALIAS_REGISTRY_HPP_INCLUDED
|
|
||||||
#define CATCH_INTERFACES_TAG_ALIAS_REGISTRY_HPP_INCLUDED
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
namespace Catch {
|
|
||||||
|
|
||||||
struct TagAlias;
|
|
||||||
|
|
||||||
class ITagAliasRegistry {
|
|
||||||
public:
|
|
||||||
virtual ~ITagAliasRegistry(); // = default
|
|
||||||
// Nullptr if not present
|
|
||||||
virtual TagAlias const* find( std::string const& alias ) const = 0;
|
|
||||||
virtual std::string expandAliases( std::string const& unexpandedTestSpec ) const = 0;
|
|
||||||
|
|
||||||
static ITagAliasRegistry const& get();
|
|
||||||
};
|
|
||||||
|
|
||||||
} // end namespace Catch
|
|
||||||
|
|
||||||
#endif // CATCH_INTERFACES_TAG_ALIAS_REGISTRY_HPP_INCLUDED
|
|
@ -11,13 +11,21 @@
|
|||||||
#include <catch2/interfaces/catch_interfaces_registry_hub.hpp>
|
#include <catch2/interfaces/catch_interfaces_registry_hub.hpp>
|
||||||
#include <catch2/internal/catch_string_manip.hpp>
|
#include <catch2/internal/catch_string_manip.hpp>
|
||||||
|
|
||||||
namespace Catch {
|
#include <map>
|
||||||
|
|
||||||
TagAliasRegistry::~TagAliasRegistry() {}
|
namespace Catch {
|
||||||
|
struct TagAliasRegistry::TagAliasRegistryImpl {
|
||||||
|
std::map<std::string, TagAlias> registry;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
TagAliasRegistry::TagAliasRegistry():
|
||||||
|
m_impl( Detail::make_unique<TagAliasRegistryImpl>() ){}
|
||||||
|
TagAliasRegistry::~TagAliasRegistry() = default;
|
||||||
|
|
||||||
TagAlias const* TagAliasRegistry::find( std::string const& alias ) const {
|
TagAlias const* TagAliasRegistry::find( std::string const& alias ) const {
|
||||||
auto it = m_registry.find( alias );
|
auto it = m_impl->registry.find( alias );
|
||||||
if( it != m_registry.end() )
|
if( it != m_impl->registry.end() )
|
||||||
return &(it->second);
|
return &(it->second);
|
||||||
else
|
else
|
||||||
return nullptr;
|
return nullptr;
|
||||||
@ -25,7 +33,7 @@ namespace Catch {
|
|||||||
|
|
||||||
std::string TagAliasRegistry::expandAliases( std::string const& unexpandedTestSpec ) const {
|
std::string TagAliasRegistry::expandAliases( std::string const& unexpandedTestSpec ) const {
|
||||||
std::string expandedTestSpec = unexpandedTestSpec;
|
std::string expandedTestSpec = unexpandedTestSpec;
|
||||||
for( auto const& registryKvp : m_registry ) {
|
for( auto const& registryKvp : m_impl->registry ) {
|
||||||
std::size_t pos = expandedTestSpec.find( registryKvp.first );
|
std::size_t pos = expandedTestSpec.find( registryKvp.first );
|
||||||
if( pos != std::string::npos ) {
|
if( pos != std::string::npos ) {
|
||||||
expandedTestSpec = expandedTestSpec.substr( 0, pos ) +
|
expandedTestSpec = expandedTestSpec.substr( 0, pos ) +
|
||||||
@ -40,15 +48,13 @@ namespace Catch {
|
|||||||
CATCH_ENFORCE( startsWith(alias, "[@") && endsWith(alias, ']'),
|
CATCH_ENFORCE( startsWith(alias, "[@") && endsWith(alias, ']'),
|
||||||
"error: tag alias, '" << alias << "' is not of the form [@alias name].\n" << lineInfo );
|
"error: tag alias, '" << alias << "' is not of the form [@alias name].\n" << lineInfo );
|
||||||
|
|
||||||
CATCH_ENFORCE( m_registry.insert(std::make_pair(alias, TagAlias(tag, lineInfo))).second,
|
CATCH_ENFORCE( m_impl->registry.insert(std::make_pair(alias, TagAlias(tag, lineInfo))).second,
|
||||||
"error: tag alias, '" << alias << "' already registered.\n"
|
"error: tag alias, '" << alias << "' already registered.\n"
|
||||||
<< "\tFirst seen at: " << find(alias)->lineInfo << "\n"
|
<< "\tFirst seen at: " << find(alias)->lineInfo << "\n"
|
||||||
<< "\tRedefined at: " << lineInfo );
|
<< "\tRedefined at: " << lineInfo );
|
||||||
}
|
}
|
||||||
|
|
||||||
ITagAliasRegistry::~ITagAliasRegistry() = default;
|
TagAliasRegistry const& TagAliasRegistry::get() {
|
||||||
|
|
||||||
ITagAliasRegistry const& ITagAliasRegistry::get() {
|
|
||||||
return getRegistryHub().getTagAliasRegistry();
|
return getRegistryHub().getTagAliasRegistry();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,24 +8,30 @@
|
|||||||
#ifndef CATCH_TAG_ALIAS_REGISTRY_HPP_INCLUDED
|
#ifndef CATCH_TAG_ALIAS_REGISTRY_HPP_INCLUDED
|
||||||
#define CATCH_TAG_ALIAS_REGISTRY_HPP_INCLUDED
|
#define CATCH_TAG_ALIAS_REGISTRY_HPP_INCLUDED
|
||||||
|
|
||||||
#include <catch2/interfaces/catch_interfaces_tag_alias_registry.hpp>
|
|
||||||
#include <catch2/catch_tag_alias.hpp>
|
#include <catch2/catch_tag_alias.hpp>
|
||||||
|
#include <catch2/internal/catch_unique_ptr.hpp>
|
||||||
|
|
||||||
#include <map>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace Catch {
|
namespace Catch {
|
||||||
struct SourceLineInfo;
|
struct SourceLineInfo;
|
||||||
|
|
||||||
class TagAliasRegistry : public ITagAliasRegistry {
|
class TagAliasRegistry {
|
||||||
|
struct TagAliasRegistryImpl;
|
||||||
|
Detail::unique_ptr<TagAliasRegistryImpl> m_impl;
|
||||||
public:
|
public:
|
||||||
~TagAliasRegistry() override;
|
TagAliasRegistry();
|
||||||
TagAlias const* find( std::string const& alias ) const override;
|
~TagAliasRegistry(); // = default;
|
||||||
std::string expandAliases( std::string const& unexpandedTestSpec ) const override;
|
|
||||||
|
//! Nullptr if not present
|
||||||
|
TagAlias const* find( std::string const& alias ) const;
|
||||||
|
//! Returns the test spec but with expanded aliases
|
||||||
|
std::string expandAliases( std::string const& unexpandedTestSpec ) const;
|
||||||
void add( std::string const& alias, std::string const& tag, SourceLineInfo const& lineInfo );
|
void add( std::string const& alias, std::string const& tag, SourceLineInfo const& lineInfo );
|
||||||
|
|
||||||
|
static TagAliasRegistry const& get();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::map<std::string, TagAlias> m_registry;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // end namespace Catch
|
} // end namespace Catch
|
||||||
|
@ -8,13 +8,13 @@
|
|||||||
#include <catch2/internal/catch_test_spec_parser.hpp>
|
#include <catch2/internal/catch_test_spec_parser.hpp>
|
||||||
|
|
||||||
#include <catch2/internal/catch_string_manip.hpp>
|
#include <catch2/internal/catch_string_manip.hpp>
|
||||||
#include <catch2/interfaces/catch_interfaces_tag_alias_registry.hpp>
|
#include <catch2/internal/catch_tag_alias_registry.hpp>
|
||||||
#include <catch2/internal/catch_move_and_forward.hpp>
|
#include <catch2/internal/catch_move_and_forward.hpp>
|
||||||
|
|
||||||
|
|
||||||
namespace Catch {
|
namespace Catch {
|
||||||
|
|
||||||
TestSpecParser::TestSpecParser( ITagAliasRegistry const& tagAliases ) : m_tagAliases( &tagAliases ) {}
|
TestSpecParser::TestSpecParser( TagAliasRegistry const& tagAliases ) : m_tagAliases( &tagAliases ) {}
|
||||||
|
|
||||||
TestSpecParser& TestSpecParser::parse( std::string const& arg ) {
|
TestSpecParser& TestSpecParser::parse( std::string const& arg ) {
|
||||||
m_mode = None;
|
m_mode = None;
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
|
|
||||||
namespace Catch {
|
namespace Catch {
|
||||||
|
|
||||||
class ITagAliasRegistry;
|
class TagAliasRegistry;
|
||||||
|
|
||||||
class TestSpecParser {
|
class TestSpecParser {
|
||||||
enum Mode{ None, Name, QuotedName, Tag, EscapedName };
|
enum Mode{ None, Name, QuotedName, Tag, EscapedName };
|
||||||
@ -35,10 +35,10 @@ namespace Catch {
|
|||||||
std::vector<std::size_t> m_escapeChars;
|
std::vector<std::size_t> m_escapeChars;
|
||||||
TestSpec::Filter m_currentFilter;
|
TestSpec::Filter m_currentFilter;
|
||||||
TestSpec m_testSpec;
|
TestSpec m_testSpec;
|
||||||
ITagAliasRegistry const* m_tagAliases = nullptr;
|
TagAliasRegistry const* m_tagAliases = nullptr;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
TestSpecParser( ITagAliasRegistry const& tagAliases );
|
TestSpecParser( TagAliasRegistry const& tagAliases );
|
||||||
|
|
||||||
TestSpecParser& parse( std::string const& arg );
|
TestSpecParser& parse( std::string const& arg );
|
||||||
TestSpec testSpec();
|
TestSpec testSpec();
|
||||||
|
@ -63,7 +63,6 @@ internal_headers = [
|
|||||||
'interfaces/catch_interfaces_registry_hub.hpp',
|
'interfaces/catch_interfaces_registry_hub.hpp',
|
||||||
'interfaces/catch_interfaces_reporter.hpp',
|
'interfaces/catch_interfaces_reporter.hpp',
|
||||||
'interfaces/catch_interfaces_reporter_factory.hpp',
|
'interfaces/catch_interfaces_reporter_factory.hpp',
|
||||||
'interfaces/catch_interfaces_tag_alias_registry.hpp',
|
|
||||||
'interfaces/catch_interfaces_testcase.hpp',
|
'interfaces/catch_interfaces_testcase.hpp',
|
||||||
'internal/catch_assertion_handler.hpp',
|
'internal/catch_assertion_handler.hpp',
|
||||||
'internal/catch_case_insensitive_comparisons.hpp',
|
'internal/catch_case_insensitive_comparisons.hpp',
|
||||||
|
@ -9,12 +9,12 @@
|
|||||||
#include <helpers/parse_test_spec.hpp>
|
#include <helpers/parse_test_spec.hpp>
|
||||||
|
|
||||||
#include <catch2/internal/catch_test_spec_parser.hpp>
|
#include <catch2/internal/catch_test_spec_parser.hpp>
|
||||||
#include <catch2/interfaces/catch_interfaces_tag_alias_registry.hpp>
|
#include <catch2/internal/catch_tag_alias_registry.hpp>
|
||||||
|
|
||||||
namespace Catch {
|
namespace Catch {
|
||||||
|
|
||||||
TestSpec parseTestSpec( std::string const& arg ) {
|
TestSpec parseTestSpec( std::string const& arg ) {
|
||||||
return TestSpecParser( ITagAliasRegistry::get() )
|
return TestSpecParser( TagAliasRegistry::get() )
|
||||||
.parse( arg )
|
.parse( arg )
|
||||||
.testSpec();
|
.testSpec();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user