1
0
mirror of https://github.com/catchorg/Catch2.git synced 2025-01-16 15:18:00 +00:00

Compare commits

...

5 Commits

Author SHA1 Message Date
Martin Hořeňovský
2e480b6e56
Use StringRef for CasedString::caseSensitivitySuffix return type 2020-08-18 21:02:34 +02:00
Martin Hořeňovský
f16be402f7
Make XmlEncoding tests slightly more efficient 2020-08-18 21:02:31 +02:00
Martin Hořeňovský
e418e75c74
Turn CaseSensitive into proper enum class 2020-08-18 21:02:30 +02:00
Martin Hořeňovský
6a46b344c0
Split out CaseSensitive enum out of catch_common.hpp
Only very few places actually use it, so there is no need to have
it be central to everywhere.
2020-08-18 21:02:25 +02:00
Martin Hořeňovský
e7eb749815
Split the NonCopyable helper out of catch_common.hpp 2020-08-18 21:02:23 +02:00
21 changed files with 98 additions and 66 deletions

View File

@ -38,11 +38,13 @@ set(INTERNAL_HEADERS
${SOURCES_DIR}/matchers/internal/catch_matchers_impl.hpp
${SOURCES_DIR}/internal/catch_console_width.hpp
${SOURCES_DIR}/internal/catch_container_nonmembers.hpp
${SOURCES_DIR}/internal/catch_noncopyable.hpp
${SOURCES_DIR}/catch_approx.hpp
${SOURCES_DIR}/internal/catch_assertion_handler.hpp
${SOURCES_DIR}/catch_assertion_info.hpp
${SOURCES_DIR}/catch_assertion_result.hpp
${SOURCES_DIR}/internal/catch_test_macro_impl.hpp
${SOURCES_DIR}/internal/catch_case_sensitive.hpp
${SOURCES_DIR}/internal/catch_clara.hpp
${SOURCES_DIR}/internal/catch_commandline.hpp
${SOURCES_DIR}/internal/catch_common.hpp

View File

@ -39,6 +39,7 @@
#include <catch2/generators/catch_generators_all.hpp>
#include <catch2/interfaces/catch_interfaces_all.hpp>
#include <catch2/internal/catch_assertion_handler.hpp>
#include <catch2/internal/catch_case_sensitive.hpp>
#include <catch2/internal/catch_clara.hpp>
#include <catch2/internal/catch_commandline.hpp>
#include <catch2/internal/catch_common.hpp>
@ -60,6 +61,7 @@
#include <catch2/internal/catch_list.hpp>
#include <catch2/internal/catch_message_info.hpp>
#include <catch2/internal/catch_meta.hpp>
#include <catch2/internal/catch_noncopyable.hpp>
#include <catch2/internal/catch_option.hpp>
#include <catch2/internal/catch_output_redirect.hpp>
#include <catch2/internal/catch_platform.hpp>

View File

@ -18,13 +18,15 @@
#include <catch2/internal/catch_singletons.hpp>
#include <catch2/internal/catch_enum_values_registry.hpp>
#include <catch2/catch_test_case_info.hpp>
#include <catch2/internal/catch_noncopyable.hpp>
namespace Catch {
namespace {
class RegistryHub : public IRegistryHub, public IMutableRegistryHub,
private NonCopyable {
class RegistryHub : public IRegistryHub,
public IMutableRegistryHub,
private Detail::NonCopyable {
public: // IRegistryHub
RegistryHub() = default;

View File

@ -9,12 +9,14 @@
#define TWOBLUECUBES_CATCH_RUNNER_HPP_INCLUDED
#include <catch2/internal/catch_commandline.hpp>
#include <catch2/internal/catch_noncopyable.hpp>
#include <catch2/catch_config.hpp>
#include <catch2/internal/catch_unique_ptr.hpp>
#include <catch2/internal/catch_compiler_capabilities.hpp>
namespace Catch {
class Session : NonCopyable {
class Session : Detail::NonCopyable {
public:
Session();

View File

@ -9,6 +9,7 @@
#define TWOBLUECUBES_CATCH_TEST_CASE_INFO_H_INCLUDED
#include <catch2/internal/catch_common.hpp>
#include <catch2/internal/catch_noncopyable.hpp>
#include <catch2/internal/catch_stringref.hpp>
#include <catch2/internal/catch_test_registry.hpp>
#include <catch2/internal/catch_unique_ptr.hpp>
@ -44,7 +45,7 @@ namespace Catch {
};
struct TestCaseInfo : NonCopyable {
struct TestCaseInfo : Detail::NonCopyable {
TestCaseInfo(std::string const& _className,
NameAndTags const& _tags,

View File

@ -8,7 +8,7 @@
#ifndef TWOBLUECUBES_CATCH_INTERFACES_CONFIG_H_INCLUDED
#define TWOBLUECUBES_CATCH_INTERFACES_CONFIG_H_INCLUDED
#include <catch2/internal/catch_common.hpp>
#include <catch2/internal/catch_noncopyable.hpp>
#include <chrono>
#include <iosfwd>
@ -53,7 +53,7 @@ namespace Catch {
class TestSpec;
struct IConfig : NonCopyable {
struct IConfig : Detail::NonCopyable {
virtual ~IConfig();

View File

@ -8,7 +8,6 @@
#ifndef TWOBLUECUBES_CATCH_INTERFACES_REGISTRY_HUB_H_INCLUDED
#define TWOBLUECUBES_CATCH_INTERFACES_REGISTRY_HUB_H_INCLUDED
#include <catch2/internal/catch_common.hpp>
#include <catch2/internal/catch_unique_ptr.hpp>
#include <string>
@ -25,6 +24,7 @@ namespace Catch {
struct ITagAliasRegistry;
struct ITestInvoker;
struct IMutableEnumValuesRegistry;
struct SourceLineInfo;
class StartupExceptionRegistry;

View File

@ -0,0 +1,10 @@
#ifndef CATCH_CASE_SENSITIVE_HPP_INCLUDED
#define CATCH_CASE_SENSITIVE_HPP_INCLUDED
namespace Catch {
enum class CaseSensitive { Yes, No };
} // namespace Catch
#endif // CATCH_CASE_SENSITIVE_HPP_INCLUDED

View File

@ -30,6 +30,8 @@
# endif
#endif
#include <catch2/internal/catch_noncopyable.hpp>
#include <cassert>
#include <cctype>
#include <memory>
@ -286,15 +288,7 @@ namespace Catch {
}
#endif // CLARA_CONFIG_OPTIONAL_TYPE
struct NonCopyable {
NonCopyable() = default;
NonCopyable( NonCopyable const& ) = delete;
NonCopyable( NonCopyable&& ) = delete;
NonCopyable& operator=( NonCopyable const& ) = delete;
NonCopyable& operator=( NonCopyable&& ) = delete;
};
struct BoundRef : NonCopyable {
struct BoundRef : Catch::Detail::NonCopyable {
virtual ~BoundRef() = default;
virtual auto isContainer() const -> bool { return false; }
virtual auto isFlag() const -> bool { return false; }

View File

@ -27,20 +27,6 @@ std::ostream& operator<<(std::ostream&, Catch_global_namespace_dummy);
namespace Catch {
struct CaseSensitive { enum Choice {
Yes,
No
}; };
class NonCopyable {
NonCopyable( NonCopyable const& ) = delete;
NonCopyable( NonCopyable && ) = delete;
NonCopyable& operator = ( NonCopyable const& ) = delete;
NonCopyable& operator = ( NonCopyable && ) = delete;
protected:
NonCopyable() noexcept = default;
};
struct SourceLineInfo {
SourceLineInfo() = delete;

View File

@ -6,12 +6,12 @@
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
*/
#include <catch2/internal/catch_context.hpp>
#include <catch2/internal/catch_common.hpp>
#include <catch2/internal/catch_noncopyable.hpp>
#include <catch2/internal/catch_random_number_generator.hpp>
namespace Catch {
class Context : public IMutableContext, NonCopyable {
class Context : public IMutableContext, private Detail::NonCopyable {
public: // IContext
IResultCapture* getResultCapture() override {

View File

@ -0,0 +1,21 @@
#ifndef CATCH_NONCOPYABLE_HPP_INCLUDED
#define CATCH_NONCOPYABLE_HPP_INCLUDED
namespace Catch {
namespace Detail {
//! Deriving classes become noncopyable and nonmovable
class NonCopyable {
NonCopyable( NonCopyable const& ) = delete;
NonCopyable( NonCopyable&& ) = delete;
NonCopyable& operator=( NonCopyable const& ) = delete;
NonCopyable& operator=( NonCopyable&& ) = delete;
protected:
NonCopyable() noexcept = default;
};
} // namespace Detail
} // namespace Catch
#endif // CATCH_NONCOPYABLE_HPP_INCLUDED

View File

@ -9,6 +9,7 @@
#define TWOBLUECUBES_CATCH_SECTION_H_INCLUDED
#include <catch2/internal/catch_compiler_capabilities.hpp>
#include <catch2/internal/catch_noncopyable.hpp>
#include <catch2/catch_section_info.hpp>
#include <catch2/catch_timer.hpp>
#include <catch2/catch_totals.hpp>
@ -17,7 +18,7 @@
namespace Catch {
class Section : NonCopyable {
class Section : Detail::NonCopyable {
public:
Section( SectionInfo&& info );
~Section();

View File

@ -9,7 +9,7 @@
#ifndef TWOBLUECUBES_CATCH_STREAM_H_INCLUDED
#define TWOBLUECUBES_CATCH_STREAM_H_INCLUDED
#include <catch2/internal/catch_common.hpp>
#include <catch2/internal/catch_noncopyable.hpp>
#include <iosfwd>
#include <cstddef>
@ -30,7 +30,7 @@ namespace Catch {
auto makeStream( StringRef const &filename ) -> IStream const*;
class ReusableStringStream : NonCopyable {
class ReusableStringStream : Detail::NonCopyable {
std::size_t m_index;
std::ostream* m_oss;
public:

View File

@ -9,6 +9,7 @@
#define TWOBLUECUBES_CATCH_TEST_REGISTRY_HPP_INCLUDED
#include <catch2/internal/catch_common.hpp>
#include <catch2/internal/catch_noncopyable.hpp>
#include <catch2/interfaces/catch_interfaces_testcase.hpp>
#include <catch2/internal/catch_compiler_capabilities.hpp>
#include <catch2/internal/catch_stringref.hpp>
@ -52,7 +53,7 @@ struct NameAndTags {
StringRef tags;
};
struct AutoReg : NonCopyable {
struct AutoReg : Detail::NonCopyable {
AutoReg( Detail::unique_ptr<ITestInvoker> invoker, SourceLineInfo const& lineInfo, StringRef const& classOrMethod, NameAndTags const& nameAndTags ) noexcept;
};

View File

@ -12,7 +12,7 @@
namespace Catch {
WildcardPattern::WildcardPattern( std::string const& pattern,
CaseSensitive::Choice caseSensitivity )
CaseSensitive caseSensitivity )
: m_caseSensitivity( caseSensitivity ),
m_pattern( normaliseString( pattern ) )
{

View File

@ -8,8 +8,9 @@
#ifndef TWOBLUECUBES_CATCH_WILDCARD_PATTERN_HPP_INCLUDED
#define TWOBLUECUBES_CATCH_WILDCARD_PATTERN_HPP_INCLUDED
#include <catch2/internal/catch_common.hpp>
#include <catch2/internal/catch_case_sensitive.hpp>
#include <string>
namespace Catch
{
@ -23,13 +24,13 @@ namespace Catch
public:
WildcardPattern( std::string const& pattern, CaseSensitive::Choice caseSensitivity );
WildcardPattern( std::string const& pattern, CaseSensitive caseSensitivity );
virtual ~WildcardPattern() = default;
virtual bool matches( std::string const& str ) const;
private:
std::string normaliseString( std::string const& str ) const;
CaseSensitive::Choice m_caseSensitivity;
CaseSensitive m_caseSensitivity;
WildcardPosition m_wildcard = NoWildcard;
std::string m_pattern;
};

View File

@ -11,6 +11,13 @@
#include <catch2/internal/catch_stream.hpp>
#include <catch2/internal/catch_compiler_capabilities.hpp>
// FixMe: Without this include (and something inside it), MSVC goes crazy
// and reports that calls to XmlEncode's op << are ambiguous between
// the declaration and definition.
// It also has to be in the header.
#include <catch2/internal/catch_common.hpp>
#include <vector>
namespace Catch {

View File

@ -12,7 +12,7 @@
namespace Catch {
namespace Matchers {
CasedString::CasedString( std::string const& str, CaseSensitive::Choice caseSensitivity )
CasedString::CasedString( std::string const& str, CaseSensitive caseSensitivity )
: m_caseSensitivity( caseSensitivity ),
m_str( adjustString( str ) )
{}
@ -21,10 +21,10 @@ namespace Matchers {
? toLower( str )
: str;
}
std::string CasedString::caseSensitivitySuffix() const {
return m_caseSensitivity == CaseSensitive::No
? " (case insensitive)"
: std::string();
StringRef CasedString::caseSensitivitySuffix() const {
return m_caseSensitivity == CaseSensitive::Yes
? StringRef()
: " (case insensitive)"_sr;
}
@ -74,11 +74,11 @@ namespace Matchers {
RegexMatcher::RegexMatcher(std::string regex, CaseSensitive::Choice caseSensitivity): m_regex(std::move(regex)), m_caseSensitivity(caseSensitivity) {}
RegexMatcher::RegexMatcher(std::string regex, CaseSensitive caseSensitivity): m_regex(std::move(regex)), m_caseSensitivity(caseSensitivity) {}
bool RegexMatcher::match(std::string const& matchee) const {
auto flags = std::regex::ECMAScript; // ECMAScript is the default syntax option anyway
if (m_caseSensitivity == CaseSensitive::Choice::No) {
if (m_caseSensitivity == CaseSensitive::No) {
flags |= std::regex::icase;
}
auto reg = std::regex(m_regex, flags);
@ -86,24 +86,24 @@ namespace Matchers {
}
std::string RegexMatcher::describe() const {
return "matches " + ::Catch::Detail::stringify(m_regex) + ((m_caseSensitivity == CaseSensitive::Choice::Yes)? " case sensitively" : " case insensitively");
return "matches " + ::Catch::Detail::stringify(m_regex) + ((m_caseSensitivity == CaseSensitive::Yes)? " case sensitively" : " case insensitively");
}
StringEqualsMatcher Equals( std::string const& str, CaseSensitive::Choice caseSensitivity ) {
StringEqualsMatcher Equals( std::string const& str, CaseSensitive caseSensitivity ) {
return StringEqualsMatcher( CasedString( str, caseSensitivity) );
}
StringContainsMatcher Contains( std::string const& str, CaseSensitive::Choice caseSensitivity ) {
StringContainsMatcher Contains( std::string const& str, CaseSensitive caseSensitivity ) {
return StringContainsMatcher( CasedString( str, caseSensitivity) );
}
EndsWithMatcher EndsWith( std::string const& str, CaseSensitive::Choice caseSensitivity ) {
EndsWithMatcher EndsWith( std::string const& str, CaseSensitive caseSensitivity ) {
return EndsWithMatcher( CasedString( str, caseSensitivity) );
}
StartsWithMatcher StartsWith( std::string const& str, CaseSensitive::Choice caseSensitivity ) {
StartsWithMatcher StartsWith( std::string const& str, CaseSensitive caseSensitivity ) {
return StartsWithMatcher( CasedString( str, caseSensitivity) );
}
RegexMatcher Matches(std::string const& regex, CaseSensitive::Choice caseSensitivity) {
RegexMatcher Matches(std::string const& regex, CaseSensitive caseSensitivity) {
return RegexMatcher(regex, caseSensitivity);
}

View File

@ -9,6 +9,8 @@
#define TWOBLUECUBES_CATCH_MATCHERS_STRING_H_INCLUDED
#include <catch2/matchers/catch_matchers.hpp>
#include <catch2/internal/catch_case_sensitive.hpp>
#include <catch2/internal/catch_stringref.hpp>
#include <string>
@ -16,11 +18,11 @@ namespace Catch {
namespace Matchers {
struct CasedString {
CasedString( std::string const& str, CaseSensitive::Choice caseSensitivity );
CasedString( std::string const& str, CaseSensitive caseSensitivity );
std::string adjustString( std::string const& str ) const;
std::string caseSensitivitySuffix() const;
StringRef caseSensitivitySuffix() const;
CaseSensitive::Choice m_caseSensitivity;
CaseSensitive m_caseSensitivity;
std::string m_str;
};
@ -50,25 +52,25 @@ namespace Matchers {
};
struct RegexMatcher final : MatcherBase<std::string> {
RegexMatcher( std::string regex, CaseSensitive::Choice caseSensitivity );
RegexMatcher( std::string regex, CaseSensitive caseSensitivity );
bool match( std::string const& matchee ) const override;
std::string describe() const override;
private:
std::string m_regex;
CaseSensitive::Choice m_caseSensitivity;
CaseSensitive m_caseSensitivity;
};
//! Creates matcher that accepts strings that are exactly equal to `str`
StringEqualsMatcher Equals( std::string const& str, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes );
StringEqualsMatcher Equals( std::string const& str, CaseSensitive caseSensitivity = CaseSensitive::Yes );
//! Creates matcher that accepts strings that contain `str`
StringContainsMatcher Contains( std::string const& str, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes );
StringContainsMatcher Contains( std::string const& str, CaseSensitive caseSensitivity = CaseSensitive::Yes );
//! Creates matcher that accepts strings that _end_ with `str`
EndsWithMatcher EndsWith( std::string const& str, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes );
EndsWithMatcher EndsWith( std::string const& str, CaseSensitive caseSensitivity = CaseSensitive::Yes );
//! Creates matcher that accepts strings that _start_ with `str`
StartsWithMatcher StartsWith( std::string const& str, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes );
StartsWithMatcher StartsWith( std::string const& str, CaseSensitive caseSensitivity = CaseSensitive::Yes );
//! Creates matcher that accepts strings matching `regex`
RegexMatcher Matches( std::string const& regex, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes );
RegexMatcher Matches( std::string const& regex, CaseSensitive caseSensitivity = CaseSensitive::Yes );
} // namespace Matchers
} // namespace Catch

View File

@ -1,10 +1,10 @@
#include <catch2/catch_test_macros.hpp>
#include <catch2/internal/catch_xmlwriter.hpp>
#include <sstream>
#include <catch2/internal/catch_stream.hpp>
inline std::string encode( std::string const& str, Catch::XmlEncode::ForWhat forWhat = Catch::XmlEncode::ForTextNodes ) {
std::ostringstream oss;
static std::string encode( std::string const& str, Catch::XmlEncode::ForWhat forWhat = Catch::XmlEncode::ForTextNodes ) {
Catch::ReusableStringStream oss;
oss << Catch::XmlEncode( str, forWhat );
return oss.str();
}