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.
This commit is contained in:
Martin Hořeňovský 2020-03-05 14:40:40 +01:00
parent 007efc173a
commit f52a58e857
No known key found for this signature in database
GPG Key ID: DE48307B8B0D381A
5 changed files with 15 additions and 15 deletions

View File

@ -13,7 +13,7 @@ namespace Catch {
namespace Matchers {
namespace Exception {
class ExceptionMessageMatcher : public MatcherBase<std::exception> {
class ExceptionMessageMatcher final : public MatcherBase<std::exception> {
std::string m_message;
public:

View File

@ -16,7 +16,7 @@ namespace Matchers {
enum class FloatingPointKind : uint8_t;
struct WithinAbsMatcher : MatcherBase<double> {
struct WithinAbsMatcher final : MatcherBase<double> {
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<double> {
struct WithinUlpsMatcher final : MatcherBase<double> {
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<double> {
struct WithinRelMatcher final : MatcherBase<double> {
WithinRelMatcher(double target, double epsilon);
bool match(double const& matchee) const override;
std::string describe() const override;

View File

@ -23,7 +23,7 @@ namespace Detail {
}
template <typename T, typename Predicate>
class PredicateMatcher : public MatcherBase<T> {
class PredicateMatcher final : public MatcherBase<T> {
Predicate m_predicate;
std::string m_description;
public:

View File

@ -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<std::string> {
struct RegexMatcher final : MatcherBase<std::string> {
RegexMatcher( std::string regex, CaseSensitive::Choice caseSensitivity );
bool match( std::string const& matchee ) const override;
std::string describe() const override;

View File

@ -18,7 +18,7 @@ namespace Matchers {
namespace Vector {
template<typename T>
struct ContainsElementMatcher : MatcherBase<std::vector<T>> {
struct ContainsElementMatcher final : MatcherBase<std::vector<T>> {
ContainsElementMatcher(T const &comparator) : m_comparator( comparator) {}
@ -39,7 +39,7 @@ namespace Matchers {
};
template<typename T>
struct ContainsMatcher : MatcherBase<std::vector<T>> {
struct ContainsMatcher final : MatcherBase<std::vector<T>> {
ContainsMatcher(std::vector<T> const &comparator) : m_comparator( comparator ) {}
@ -69,7 +69,7 @@ namespace Matchers {
};
template<typename T>
struct EqualsMatcher : MatcherBase<std::vector<T>> {
struct EqualsMatcher final : MatcherBase<std::vector<T>> {
EqualsMatcher(std::vector<T> const &comparator) : m_comparator( comparator ) {}
@ -92,7 +92,7 @@ namespace Matchers {
};
template<typename T>
struct ApproxMatcher : MatcherBase<std::vector<T>> {
struct ApproxMatcher final : MatcherBase<std::vector<T>> {
ApproxMatcher(std::vector<T> const& comparator) : m_comparator( comparator ) {}
@ -128,7 +128,7 @@ namespace Matchers {
};
template<typename T>
struct UnorderedEqualsMatcher : MatcherBase<std::vector<T>> {
struct UnorderedEqualsMatcher final : MatcherBase<std::vector<T>> {
UnorderedEqualsMatcher(std::vector<T> const& target) : m_target(target) {}
bool match(std::vector<T> const& vec) const override {
// Note: This is a reimplementation of std::is_permutation,