From f52a58e857967124bedf5370b5b03f799c1db0b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Ho=C5=99e=C5=88ovsk=C3=BD?= Date: Thu, 5 Mar 2020 14:40:40 +0100 Subject: [PATCH] Make concrete matchers final Outside of `MatcherBase` and `GenericMatcherBase`, matchers are not designed to be overriden. This means that doing so can easily lead to errors, and matchers are generally fairly simple functionality-wise. so there is not much code reuse to be gained anyway. Thus, Catch2-provided concrete matchers are now final. --- src/catch2/matchers/catch_matchers_exception.hpp | 2 +- src/catch2/matchers/catch_matchers_floating.hpp | 6 +++--- src/catch2/matchers/catch_matchers_generic.hpp | 2 +- src/catch2/matchers/catch_matchers_string.hpp | 10 +++++----- src/catch2/matchers/catch_matchers_vector.hpp | 10 +++++----- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/catch2/matchers/catch_matchers_exception.hpp b/src/catch2/matchers/catch_matchers_exception.hpp index 03389005..74355cd8 100644 --- a/src/catch2/matchers/catch_matchers_exception.hpp +++ b/src/catch2/matchers/catch_matchers_exception.hpp @@ -13,7 +13,7 @@ namespace Catch { namespace Matchers { namespace Exception { -class ExceptionMessageMatcher : public MatcherBase { +class ExceptionMessageMatcher final : public MatcherBase { std::string m_message; public: diff --git a/src/catch2/matchers/catch_matchers_floating.hpp b/src/catch2/matchers/catch_matchers_floating.hpp index cb49cf26..bead3a04 100644 --- a/src/catch2/matchers/catch_matchers_floating.hpp +++ b/src/catch2/matchers/catch_matchers_floating.hpp @@ -16,7 +16,7 @@ namespace Matchers { enum class FloatingPointKind : uint8_t; - struct WithinAbsMatcher : MatcherBase { + struct WithinAbsMatcher final : MatcherBase { WithinAbsMatcher(double target, double margin); bool match(double const& matchee) const override; std::string describe() const override; @@ -25,7 +25,7 @@ namespace Matchers { double m_margin; }; - struct WithinUlpsMatcher : MatcherBase { + struct WithinUlpsMatcher final : MatcherBase { WithinUlpsMatcher(double target, uint64_t ulps, FloatingPointKind baseType); bool match(double const& matchee) const override; std::string describe() const override; @@ -41,7 +41,7 @@ namespace Matchers { // |lhs - rhs| <= epsilon * max(fabs(lhs), fabs(rhs)), then we get // the same result if we do this for floats, as if we do this for // doubles that were promoted from floats. - struct WithinRelMatcher : MatcherBase { + struct WithinRelMatcher final : MatcherBase { WithinRelMatcher(double target, double epsilon); bool match(double const& matchee) const override; std::string describe() const override; diff --git a/src/catch2/matchers/catch_matchers_generic.hpp b/src/catch2/matchers/catch_matchers_generic.hpp index 81e21c42..dcdff771 100644 --- a/src/catch2/matchers/catch_matchers_generic.hpp +++ b/src/catch2/matchers/catch_matchers_generic.hpp @@ -23,7 +23,7 @@ namespace Detail { } template -class PredicateMatcher : public MatcherBase { +class PredicateMatcher final : public MatcherBase { Predicate m_predicate; std::string m_description; public: diff --git a/src/catch2/matchers/catch_matchers_string.hpp b/src/catch2/matchers/catch_matchers_string.hpp index 6e351cd0..7f522b6f 100644 --- a/src/catch2/matchers/catch_matchers_string.hpp +++ b/src/catch2/matchers/catch_matchers_string.hpp @@ -35,24 +35,24 @@ namespace Matchers { std::string m_operation; }; - struct EqualsMatcher : StringMatcherBase { + struct EqualsMatcher final : StringMatcherBase { EqualsMatcher( CasedString const& comparator ); bool match( std::string const& source ) const override; }; - struct ContainsMatcher : StringMatcherBase { + struct ContainsMatcher final : StringMatcherBase { ContainsMatcher( CasedString const& comparator ); bool match( std::string const& source ) const override; }; - struct StartsWithMatcher : StringMatcherBase { + struct StartsWithMatcher final : StringMatcherBase { StartsWithMatcher( CasedString const& comparator ); bool match( std::string const& source ) const override; }; - struct EndsWithMatcher : StringMatcherBase { + struct EndsWithMatcher final : StringMatcherBase { EndsWithMatcher( CasedString const& comparator ); bool match( std::string const& source ) const override; }; - struct RegexMatcher : MatcherBase { + struct RegexMatcher final : MatcherBase { RegexMatcher( std::string regex, CaseSensitive::Choice caseSensitivity ); bool match( std::string const& matchee ) const override; std::string describe() const override; diff --git a/src/catch2/matchers/catch_matchers_vector.hpp b/src/catch2/matchers/catch_matchers_vector.hpp index 24300641..e5d68949 100644 --- a/src/catch2/matchers/catch_matchers_vector.hpp +++ b/src/catch2/matchers/catch_matchers_vector.hpp @@ -18,7 +18,7 @@ namespace Matchers { namespace Vector { template - struct ContainsElementMatcher : MatcherBase> { + struct ContainsElementMatcher final : MatcherBase> { ContainsElementMatcher(T const &comparator) : m_comparator( comparator) {} @@ -39,7 +39,7 @@ namespace Matchers { }; template - struct ContainsMatcher : MatcherBase> { + struct ContainsMatcher final : MatcherBase> { ContainsMatcher(std::vector const &comparator) : m_comparator( comparator ) {} @@ -69,7 +69,7 @@ namespace Matchers { }; template - struct EqualsMatcher : MatcherBase> { + struct EqualsMatcher final : MatcherBase> { EqualsMatcher(std::vector const &comparator) : m_comparator( comparator ) {} @@ -92,7 +92,7 @@ namespace Matchers { }; template - struct ApproxMatcher : MatcherBase> { + struct ApproxMatcher final : MatcherBase> { ApproxMatcher(std::vector const& comparator) : m_comparator( comparator ) {} @@ -128,7 +128,7 @@ namespace Matchers { }; template - struct UnorderedEqualsMatcher : MatcherBase> { + struct UnorderedEqualsMatcher final : MatcherBase> { UnorderedEqualsMatcher(std::vector const& target) : m_target(target) {} bool match(std::vector const& vec) const override { // Note: This is a reimplementation of std::is_permutation,