diff options
| author | melak47 | 2020-02-16 11:19:10 +0100 |
|---|---|---|
| committer | GitHub | 2020-02-16 11:19:10 +0100 |
| commit | 17c4b2d0932ba944743b3c1e578352080af8c137 (patch) | |
| tree | d4af4ea94e8e25a624634c4750871d7d221d66d0 | |
| parent | db1a0465dc39e8aed36852984c14072192750b1d (diff) | |
| download | catch3-17c4b2d0932ba944743b3c1e578352080af8c137.tar.gz | |
Feature: generic matchers (#1843)
This commit extends the Matchers feature with the ability to have type-independent (e.g. templated) matchers. This is done by adding a new base type that Matchers can extend, `MatcherGenericBase`, and overloads of operators `!`, `&&` and `||` that handle matchers extending `MatcherGenericBase` in a special manner.
These new matchers can also take their arguments as values and non-const references.
Closes #1307
Closes #1553
Closes #1554
Co-authored-by: Martin Hořeňovský <martin.horenovsky@gmail.com>
| -rw-r--r-- | src/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | src/catch2/catch_capture_matchers.cpp | 2 | ||||
| -rw-r--r-- | src/catch2/catch_capture_matchers.h | 12 | ||||
| -rw-r--r-- | src/catch2/catch_matchers_templates.cpp | 32 | ||||
| -rw-r--r-- | src/catch2/catch_matchers_templates.hpp | 262 | ||||
| -rw-r--r-- | tests/SelfTest/Baselines/automake.sw.approved.txt | 8 | ||||
| -rw-r--r-- | tests/SelfTest/Baselines/compact.sw.approved.txt | 35 | ||||
| -rw-r--r-- | tests/SelfTest/Baselines/console.std.approved.txt | 4 | ||||
| -rw-r--r-- | tests/SelfTest/Baselines/console.sw.approved.txt | 233 | ||||
| -rw-r--r-- | tests/SelfTest/Baselines/junit.sw.approved.txt | 10 | ||||
| -rw-r--r-- | tests/SelfTest/Baselines/sonarqube.sw.approved.txt | 8 | ||||
| -rw-r--r-- | tests/SelfTest/Baselines/tap.sw.approved.txt | 72 | ||||
| -rw-r--r-- | tests/SelfTest/Baselines/teamcity.sw.approved.txt | 16 | ||||
| -rw-r--r-- | tests/SelfTest/Baselines/xml.sw.approved.txt | 212 | ||||
| -rw-r--r-- | tests/SelfTest/UsageTests/Matchers.tests.cpp | 300 |
15 files changed, 1192 insertions, 16 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a3e5b53d..9e5db746 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -77,6 +77,7 @@ set(INTERNAL_HEADERS ${SOURCES_DIR}/catch_matchers_floating.h ${SOURCES_DIR}/catch_matchers_generic.hpp ${SOURCES_DIR}/catch_matchers_string.h + ${SOURCES_DIR}/catch_matchers_templates.hpp ${SOURCES_DIR}/catch_matchers_vector.h ${SOURCES_DIR}/catch_message.h ${SOURCES_DIR}/catch_meta.hpp @@ -159,6 +160,7 @@ set(IMPL_SOURCES ${SOURCES_DIR}/catch_matchers_floating.cpp ${SOURCES_DIR}/catch_matchers_generic.cpp ${SOURCES_DIR}/catch_matchers_string.cpp + ${SOURCES_DIR}/catch_matchers_templates.cpp ${SOURCES_DIR}/catch_message.cpp ${SOURCES_DIR}/catch_output_redirect.cpp ${SOURCES_DIR}/catch_registry_hub.cpp diff --git a/src/catch2/catch_capture_matchers.cpp b/src/catch2/catch_capture_matchers.cpp index ad51baca..7ce35ef6 100644 --- a/src/catch2/catch_capture_matchers.cpp +++ b/src/catch2/catch_capture_matchers.cpp @@ -17,7 +17,7 @@ namespace Catch { // the Equals matcher (so the header does not mention matchers) void handleExceptionMatchExpr( AssertionHandler& handler, StringMatcher const& matcher, StringRef const& matcherString ) { std::string exceptionMessage = Catch::translateActiveException(); - MatchExpr<std::string, StringMatcher const&> expr( exceptionMessage, matcher, matcherString ); + MatchExpr<std::string, StringMatcher const&> expr( std::move(exceptionMessage), matcher, matcherString ); handler.handleExpr( expr ); } diff --git a/src/catch2/catch_capture_matchers.h b/src/catch2/catch_capture_matchers.h index 3f883a39..7ff23628 100644 --- a/src/catch2/catch_capture_matchers.h +++ b/src/catch2/catch_capture_matchers.h @@ -16,13 +16,13 @@ namespace Catch { template<typename ArgT, typename MatcherT> class MatchExpr : public ITransientExpression { - ArgT const& m_arg; + ArgT && m_arg; MatcherT m_matcher; StringRef m_matcherString; public: - MatchExpr( ArgT const& arg, MatcherT const& matcher, StringRef const& matcherString ) - : ITransientExpression{ true, matcher.match( arg ) }, - m_arg( arg ), + MatchExpr( ArgT && arg, MatcherT const& matcher, StringRef const& matcherString ) + : ITransientExpression{ true, matcher.match( arg ) }, // not forwarding arg here on purpose + m_arg( std::forward<ArgT>(arg) ), m_matcher( matcher ), m_matcherString( matcherString ) {} @@ -42,8 +42,8 @@ namespace Catch { void handleExceptionMatchExpr( AssertionHandler& handler, StringMatcher const& matcher, StringRef const& matcherString ); template<typename ArgT, typename MatcherT> - auto makeMatchExpr( ArgT const& arg, MatcherT const& matcher, StringRef const& matcherString ) -> MatchExpr<ArgT, MatcherT> { - return MatchExpr<ArgT, MatcherT>( arg, matcher, matcherString ); + auto makeMatchExpr( ArgT && arg, MatcherT const& matcher, StringRef const& matcherString ) -> MatchExpr<ArgT, MatcherT> { + return MatchExpr<ArgT, MatcherT>( std::forward<ArgT>(arg), matcher, matcherString ); } } // namespace Catch diff --git a/src/catch2/catch_matchers_templates.cpp b/src/catch2/catch_matchers_templates.cpp new file mode 100644 index 00000000..16b4a685 --- /dev/null +++ b/src/catch2/catch_matchers_templates.cpp @@ -0,0 +1,32 @@ +#include <catch2/catch_matchers_templates.hpp> + +namespace Catch { +namespace Matchers { + namespace Impl { + MatcherGenericBase::~MatcherGenericBase() {} + + std::string describe_multi_matcher(StringRef combine, std::string const* descriptions_begin, std::string const* descriptions_end) { + std::string description; + std::size_t combined_size = 4; + for ( auto desc = descriptions_begin; desc != descriptions_end; ++desc ) { + combined_size += desc->size(); + } + combined_size += (descriptions_end - descriptions_begin - 1) * combine.size(); + + description.reserve(combined_size); + + description += "( "; + bool first = true; + for( auto desc = descriptions_begin; desc != descriptions_end; ++desc ) { + if( first ) + first = false; + else + description += combine; + description += *desc; + } + description += " )"; + return description; + } + } +} // namespace Matchers +} // namespace Catch diff --git a/src/catch2/catch_matchers_templates.hpp b/src/catch2/catch_matchers_templates.hpp new file mode 100644 index 00000000..e1387db6 --- /dev/null +++ b/src/catch2/catch_matchers_templates.hpp @@ -0,0 +1,262 @@ +#ifndef TWOBLUECUBES_CATCH_MATCHERS_TEMPLATES_HPP_INCLUDED +#define TWOBLUECUBES_CATCH_MATCHERS_TEMPLATES_HPP_INCLUDED + +#include <catch2/catch_common.h> +#include <catch2/catch_matchers.h> +#include <catch2/catch_stringref.h> + +#include <array> +#include <algorithm> +#include <memory> +#include <string> +#include <type_traits> +#include <utility> + +namespace Catch { +namespace Matchers { + namespace Impl { + + template<typename... MatcherTs> struct MatchAllOfGeneric; + template<typename... MatcherTs> struct MatchAnyOfGeneric; + template<typename MatcherT> struct MatchNotOfGeneric; + + struct MatcherGenericBase : MatcherUntypedBase { + virtual ~MatcherGenericBase(); + }; + + template<std::size_t N, std::size_t M> + std::array<void const*, N + M> array_cat(std::array<void const*, N> && lhs, std::array<void const*, M> && rhs) { + std::array<void const*, N + M> arr{}; + std::copy_n(lhs.begin(), N, arr.begin()); + std::copy_n(rhs.begin(), M, arr.begin() + N); + return arr; + } + + template<std::size_t N> + std::array<void const*, N+1> array_cat(std::array<void const*, N> && lhs, void const* rhs) { + std::array<void const*, N+1> arr{}; + std::copy_n(lhs.begin(), N, arr.begin()); + arr[N] = rhs; + return arr; + } + + template<std::size_t N> + std::array<void const*, N+1> array_cat(void const* lhs, std::array<void const*, N> && rhs) { + std::array<void const*, N+1> arr{lhs}; + std::copy_n(rhs.begin(), N, arr.begin() + 1); + return arr; + } + + #ifdef CATCH_CPP17_OR_GREATER + + using std::conjunction; + + #else // CATCH_CPP17_OR_GREATER + + template<typename... Cond> + struct conjunction : std::true_type {}; + + template<typename Cond, typename... Rest> + struct conjunction<Cond, Rest...> : std::integral_constant<bool, Cond::value && conjunction<Rest...>::value> {}; + + #endif // CATCH_CPP17_OR_GREATER + + template<typename T> + using is_generic_matcher = std::is_base_of< + Catch::Matchers::Impl::MatcherGenericBase, + typename std::remove_cv<typename std::remove_reference<T>::type>::type + >; + + template<typename... Ts> + using are_generic_matchers = conjunction<is_generic_matcher<Ts>...>; + + template<typename T> + using is_matcher = std::is_base_of< + Catch::Matchers::Impl::MatcherUntypedBase, + typename std::remove_cv<typename std::remove_reference<T>::type>::type + >; + + + template<std::size_t N, typename Arg> + bool match_all_of(Arg&&, std::array<void const*, N> const&, std::index_sequence<>) { + return true; + } + + template<typename T, typename... MatcherTs, std::size_t N, typename Arg, std::size_t Idx, std::size_t... Indices> + bool match_all_of(Arg&& arg, std::array<void const*, N> const& matchers, std::index_sequence<Idx, Indices...>) { + return static_cast<T const*>(matchers[Idx])->match(arg) && match_all_of<MatcherTs...>(arg, matchers, std::index_sequence<Indices...>{}); + } + + + template<std::size_t N, typename Arg> + bool match_any_of(Arg&&, std::array<void const*, N> const&, std::index_sequence<>) { + return false; + } + + template<typename T, typename... MatcherTs, std::size_t N, typename Arg, std::size_t Idx, std::size_t... Indices> + bool match_any_of(Arg&& arg, std::array<void const*, N> const& matchers, std::index_sequence<Idx, Indices...>) { + return static_cast<T const*>(matchers[Idx])->match(arg) || match_any_of<MatcherTs...>(arg, matchers, std::index_sequence<Indices...>{}); + } + + std::string describe_multi_matcher(StringRef combine, std::string const* descriptions_begin, std::string const* descriptions_end); + + template<typename... MatcherTs, std::size_t... Idx> + std::string describe_multi_matcher(StringRef combine, std::array<void const*, sizeof...(MatcherTs)> const& matchers, std::index_sequence<Idx...>) { + std::array<std::string, sizeof...(MatcherTs)> descriptions {{ + static_cast<MatcherTs const*>(matchers[Idx])->toString()... + }}; + + return describe_multi_matcher(combine, descriptions.data(), descriptions.data() + descriptions.size()); + } + + + template<typename... MatcherTs> + struct MatchAllOfGeneric : MatcherGenericBase { + MatchAllOfGeneric(MatcherTs const&... matchers) : m_matchers{std::addressof(matchers)...} {} + explicit MatchAllOfGeneric(std::array<void const*, sizeof...(MatcherTs)> matchers) : m_matchers{matchers} {} + + template<typename Arg> + bool match(Arg&& arg) const { + return match_all_of<MatcherTs...>(arg, m_matchers, std::index_sequence_for<MatcherTs...>{}); + } + + std::string describe() const override { + return describe_multi_matcher<MatcherTs...>(" and "_sr, m_matchers, std::index_sequence_for<MatcherTs...>{}); + } + + std::array<void const*, sizeof...(MatcherTs)> m_matchers; + }; + + + template<typename... MatcherTs> + struct MatchAnyOfGeneric : MatcherGenericBase { + MatchAnyOfGeneric(MatcherTs const&... matchers) : m_matchers{std::addressof(matchers)...} {} + explicit MatchAnyOfGeneric(std::array<void const*, sizeof...(MatcherTs)> matchers) : m_matchers{matchers} {} + + template<typename Arg> + bool match(Arg&& arg) const { + return match_any_of<MatcherTs...>(arg, m_matchers, std::index_sequence_for<MatcherTs...>{}); + } + + std::string describe() const override { + return describe_multi_matcher<MatcherTs...>(" or "_sr, m_matchers, std::index_sequence_for<MatcherTs...>{}); + } + + std::array<void const*, sizeof...(MatcherTs)> m_matchers; + }; + + + template<typename MatcherT> + struct MatchNotOfGeneric : MatcherGenericBase { + explicit MatchNotOfGeneric(MatcherT const& matcher) : m_matcher{matcher} {} + + template<typename Arg> + bool match(Arg&& arg) const { + return !m_matcher.match(arg); + } + + std::string describe() const override { + return "not " + m_matcher.toString(); + } + + MatcherT const& m_matcher; + }; + + // compose only generic matchers + template<typename MatcherLHS, typename MatcherRHS> + typename std::enable_if<are_generic_matchers<MatcherLHS, MatcherRHS>::value, MatchAllOfGeneric<MatcherLHS, MatcherRHS>>::type + operator && (MatcherLHS const& lhs, MatcherRHS const& rhs) { + return {lhs, rhs}; + } + + template<typename MatcherLHS, typename MatcherRHS> + typename std::enable_if<are_generic_matchers<MatcherLHS, MatcherRHS>::value, MatchAnyOfGeneric<MatcherLHS, MatcherRHS>>::type + operator || (MatcherLHS const& lhs, MatcherRHS const& rhs) { + return {lhs, rhs}; + } + + template<typename MatcherT> + typename std::enable_if<is_generic_matcher<MatcherT>::value, MatchNotOfGeneric<MatcherT>>::type + operator ! (MatcherT const& matcher) { + return MatchNotOfGeneric<MatcherT>{matcher}; + } + + + // compose mixed generic and non-generic matchers + template<typename MatcherLHS, typename ArgRHS> + typename std::enable_if<is_generic_matcher<MatcherLHS>::value, MatchAllOfGeneric<MatcherLHS, MatcherBase<ArgRHS>>>::type + operator && (MatcherLHS const& lhs, MatcherBase<ArgRHS> const& rhs) { + return {lhs, rhs}; + } + + template<typename ArgLHS, typename MatcherRHS> + typename std::enable_if<is_generic_matcher<MatcherRHS>::value, MatchAllOfGeneric<MatcherBase<ArgLHS>, MatcherRHS>>::type + operator && (MatcherBase<ArgLHS> const& lhs, MatcherRHS const& rhs) { + return {lhs, rhs}; + } + + template<typename MatcherLHS, typename ArgRHS> + typename std::enable_if<is_generic_matcher<MatcherLHS>::value, MatchAnyOfGeneric<MatcherLHS, MatcherBase<ArgRHS>>>::type + operator || (MatcherLHS const& lhs, MatcherBase<ArgRHS> const& rhs) { + return {lhs, rhs}; + } + + template<typename ArgLHS, typename MatcherRHS> + typename std::enable_if<is_generic_matcher<MatcherRHS>::value, MatchAnyOfGeneric<MatcherBase<ArgLHS>, MatcherRHS>>::type + operator || (MatcherBase<ArgLHS> const& lhs, MatcherRHS const& rhs) { + return {lhs, rhs}; + } + + + // avoid deep nesting of matcher templates + template<typename... MatchersLHS, typename... MatchersRHS> + MatchAllOfGeneric<MatchersLHS..., MatchersRHS...> + operator && (MatchAllOfGeneric<MatchersLHS...> && lhs, MatchAllOfGeneric<MatchersRHS...> && rhs) { + return MatchAllOfGeneric<MatchersLHS..., MatchersRHS...>{array_cat(std::move(lhs.m_matchers), std::move(rhs.m_matchers))}; + } + + template<typename... MatchersLHS, typename MatcherRHS> + typename std::enable_if<is_matcher<MatcherRHS>::value, MatchAllOfGeneric<MatchersLHS..., MatcherRHS>>::type + operator && (MatchAllOfGeneric<MatchersLHS...> && lhs, MatcherRHS const& rhs) { + return MatchAllOfGeneric<MatchersLHS..., MatcherRHS>{array_cat(std::move(lhs.m_matchers), static_cast<void const*>(&rhs))}; + } + + template<typename MatcherLHS, typename... MatchersRHS> + typename std::enable_if<is_matcher<MatcherLHS>::value, MatchAllOfGeneric<MatcherLHS, MatchersRHS...>>::type + operator && (MatcherLHS const& lhs, MatchAllOfGeneric<MatchersRHS...> && rhs) { + return MatchAllOfGeneric<MatcherLHS, MatchersRHS...>{array_cat(static_cast<void const*>(std::addressof(lhs)), std::move(rhs.m_matchers))}; + } + + template<typename... MatchersLHS, typename... MatchersRHS> + MatchAnyOfGeneric<MatchersLHS..., MatchersRHS...> + operator || (MatchAnyOfGeneric<MatchersLHS...> && lhs, MatchAnyOfGeneric<MatchersRHS...> && rhs) { + return MatchAnyOfGeneric<MatchersLHS..., MatchersRHS...>{array_cat(std::move(lhs.m_matchers), std::move(rhs.m_matchers))}; + } + + template<typename... MatchersLHS, typename MatcherRHS> + typename std::enable_if<is_matcher<MatcherRHS>::value, MatchAnyOfGeneric<MatchersLHS..., MatcherRHS>>::type + operator || (MatchAnyOfGeneric<MatchersLHS...> && lhs, MatcherRHS const& rhs) { + return MatchAnyOfGeneric<MatchersLHS..., MatcherRHS>{array_cat(std::move(lhs.m_matchers), static_cast<void const*>(std::addressof(rhs)))}; + } + + template<typename MatcherLHS, typename... MatchersRHS> + typename std::enable_if<is_matcher<MatcherLHS>::value, MatchAnyOfGeneric<MatcherLHS, MatchersRHS...>>::type + operator || (MatcherLHS const& lhs, MatchAnyOfGeneric<MatchersRHS...> && rhs) { + return MatchAnyOfGeneric<MatcherLHS, MatchersRHS...>{array_cat(static_cast<void const*>(std::addressof(lhs)), std::move(rhs.m_matchers))}; + } + + template<typename MatcherT> + MatcherT const& operator ! (MatchNotOfGeneric<MatcherT> const& matcher) { + return matcher.m_matcher; + } + + } // namespace Impl + +} // namespace Matchers + +using namespace Matchers; +using Matchers::Impl::MatcherGenericBase; + +} // namespace Catch + +#endif //TWOBLUECUBES_CATCH_MATCHERS_TEMPLATES_HPP_INCLUDED diff --git a/tests/SelfTest/Baselines/automake.sw.approved.txt b/tests/SelfTest/Baselines/automake.sw.approved.txt index 035a92f2..db7f4006 100644 --- a/tests/SelfTest/Baselines/automake.sw.approved.txt +++ b/tests/SelfTest/Baselines/automake.sw.approved.txt @@ -85,6 +85,13 @@ Nor would this :test-result: PASS CAPTURE parses string and character constants :test-result: PASS Capture and info messages :test-result: PASS Character pretty printing +:test-result: PASS Combining MatchAllOfGeneric does not nest +:test-result: PASS Combining MatchAnyOfGeneric does not nest +:test-result: PASS Combining MatchNotOfGeneric does not nest +:test-result: PASS Combining concrete matchers does not use templated matchers +:test-result: PASS Combining only templated matchers +:test-result: PASS Combining templated and concrete matchers +:test-result: PASS Combining templated matchers :test-result: PASS Commas in various macros are allowed :test-result: PASS Comparing function pointers :test-result: PASS Comparison ops @@ -147,6 +154,7 @@ Nor would this :test-result: PASS Ordering comparison checks that should succeed :test-result: PASS Our PCG implementation provides expected results for known seeds :test-result: FAIL Output from all sections is reported +:test-result: PASS Overloaded comma or address-of operators are not used :test-result: PASS Parse test names and tags :test-result: PASS Pointers can be compared to null :test-result: PASS Precision of floating point stringification can be set diff --git a/tests/SelfTest/Baselines/compact.sw.approved.txt b/tests/SelfTest/Baselines/compact.sw.approved.txt index 66f75768..0d6cd160 100644 --- a/tests/SelfTest/Baselines/compact.sw.approved.txt +++ b/tests/SelfTest/Baselines/compact.sw.approved.txt @@ -263,6 +263,37 @@ ToStringGeneral.tests.cpp:<line number>: passed: c == i for: 2 == 2 ToStringGeneral.tests.cpp:<line number>: passed: c == i for: 3 == 3 ToStringGeneral.tests.cpp:<line number>: passed: c == i for: 4 == 4 ToStringGeneral.tests.cpp:<line number>: passed: c == i for: 5 == 5 +Matchers.tests.cpp:<line number>: passed: with 1 message: 'std::is_same< decltype(MatcherA() && MatcherB() && MatcherC()), Catch::Matchers::Impl::MatchAllOfGeneric<MatcherA, MatcherB, MatcherC> >::value' +Matchers.tests.cpp:<line number>: passed: 1, MatcherA() && MatcherB() && MatcherC() for: 1 ( equals: (int) 1 or (float) 1.0f and equals: (long long) 1 and equals: (T) 1 ) +Matchers.tests.cpp:<line number>: passed: with 1 message: 'std::is_same< decltype(MatcherA() && MatcherB() && MatcherC() && MatcherD()), Catch::Matchers::Impl::MatchAllOfGeneric<MatcherA, MatcherB, MatcherC, MatcherD> >::value' +Matchers.tests.cpp:<line number>: passed: 1, MatcherA() && MatcherB() && MatcherC() && MatcherD() for: 1 ( equals: (int) 1 or (float) 1.0f and equals: (long long) 1 and equals: (T) 1 and equals: true ) +Matchers.tests.cpp:<line number>: passed: with 1 message: 'std::is_same< decltype(MatcherA() || MatcherB() || MatcherC()), Catch::Matchers::Impl::MatchAnyOfGeneric<MatcherA, MatcherB, MatcherC> >::value' +Matchers.tests.cpp:<line number>: passed: 1, MatcherA() || MatcherB() || MatcherC() for: 1 ( equals: (int) 1 or (float) 1.0f or equals: (long long) 1 or equals: (T) 1 ) +Matchers.tests.cpp:<line number>: passed: with 1 message: 'std::is_same< decltype(MatcherA() || MatcherB() || MatcherC() || MatcherD()), Catch::Matchers::Impl::MatchAnyOfGeneric<MatcherA, MatcherB, MatcherC, MatcherD> >::value' +Matchers.tests.cpp:<line number>: passed: 1, MatcherA() || MatcherB() || MatcherC() || MatcherD() for: 1 ( equals: (int) 1 or (float) 1.0f or equals: (long long) 1 or equals: (T) 1 or equals: true ) +Matchers.tests.cpp:<line number>: passed: with 1 message: 'std::is_same< decltype(!MatcherA()), Catch::Matchers::Impl::MatchNotOfGeneric<MatcherA> >::value' +Matchers.tests.cpp:<line number>: passed: 0, !MatcherA() for: 0 not equals: (int) 1 or (float) 1.0f +Matchers.tests.cpp:<line number>: passed: with 1 message: 'std::is_same< decltype(!!MatcherA()), MatcherA const& >::value' +Matchers.tests.cpp:<line number>: passed: 1, !!MatcherA() for: 1 equals: (int) 1 or (float) 1.0f +Matchers.tests.cpp:<line number>: passed: with 1 message: 'std::is_same< decltype(!!!MatcherA()), Catch::Matchers::Impl::MatchNotOfGeneric<MatcherA> >::value' +Matchers.tests.cpp:<line number>: passed: 0, !!!MatcherA() for: 0 not equals: (int) 1 or (float) 1.0f +Matchers.tests.cpp:<line number>: passed: with 1 message: 'std::is_same< decltype(!!!!MatcherA()), MatcherA const & >::value' +Matchers.tests.cpp:<line number>: passed: 1, !!!!MatcherA() for: 1 equals: (int) 1 or (float) 1.0f +Matchers.tests.cpp:<line number>: passed: with 1 message: 'std::is_same< decltype(StartsWith("foo") || (StartsWith("bar") && EndsWith("bar") && !EndsWith("foo"))), Catch::Matchers::Impl::MatchAnyOf<std::string> >::value' +Matchers.tests.cpp:<line number>: passed: with 1 message: 'std::is_same< decltype(MatcherA() || MatcherB()), Catch::Matchers::Impl::MatchAnyOfGeneric<MatcherA, MatcherB> >::value' +Matchers.tests.cpp:<line number>: passed: 1, MatcherA() || MatcherB() for: 1 ( equals: (int) 1 or (float) 1.0f or equals: (long long) 1 ) +Matchers.tests.cpp:<line number>: passed: with 1 message: 'std::is_same< decltype(MatcherA() && MatcherB()), Catch::Matchers::Impl::MatchAllOfGeneric<MatcherA, MatcherB> >::value' +Matchers.tests.cpp:<line number>: passed: 1, MatcherA() && MatcherB() for: 1 ( equals: (int) 1 or (float) 1.0f and equals: (long long) 1 ) +Matchers.tests.cpp:<line number>: passed: with 1 message: 'std::is_same< decltype(MatcherA() || !MatcherB()), Catch::Matchers::Impl::MatchAnyOfGeneric<MatcherA, Catch::Matchers::Impl::MatchNotOfGeneric<MatcherB>> >::value' +Matchers.tests.cpp:<line number>: passed: 1, MatcherA() || !MatcherB() for: 1 ( equals: (int) 1 or (float) 1.0f or not equals: (long long) 1 ) +Matchers.tests.cpp:<line number>: passed: vec, Predicate<std::vector<int>>([](auto const& vec) { return std::all_of(vec.begin(), vec.end(), [](int elem) { return elem % 2 == 1; }); }, "All elements are odd") && !EqualsRange(a) for: { 1, 3, 5 } ( matches predicate: "All elements are odd" and not Equals: { 5, 3, 1 } ) +Matchers.tests.cpp:<line number>: passed: str, StartsWith("foo") && EqualsRange(arr) && EndsWith("bar") for: "foobar" ( starts with: "foo" and Equals: { 'f', 'o', 'o', 'b', 'a', 'r' } and ends with: "bar" ) +Matchers.tests.cpp:<line number>: passed: str, StartsWith("foo") && !EqualsRange(bad_arr) && EndsWith("bar") for: "foobar" ( starts with: "foo" and not Equals: { 'o', 'o', 'f', 'b', 'a', 'r' } and ends with: "bar" ) +Matchers.tests.cpp:<line number>: passed: str, EqualsRange(arr) && StartsWith("foo") && EndsWith("bar") for: "foobar" ( Equals: { 'f', 'o', 'o', 'b', 'a', 'r' } and starts with: "foo" and ends with: "bar" ) +Matchers.tests.cpp:<line number>: passed: str, !EqualsRange(bad_arr) && StartsWith("foo") && EndsWith("bar") for: "foobar" ( not Equals: { 'o', 'o', 'f', 'b', 'a', 'r' } and starts with: "foo" and ends with: "bar" ) +Matchers.tests.cpp:<line number>: passed: str, EqualsRange(bad_arr) || (StartsWith("foo") && EndsWith("bar")) for: "foobar" ( Equals: { 'o', 'o', 'f', 'b', 'a', 'r' } or ( starts with: "foo" and ends with: "bar" ) ) +Matchers.tests.cpp:<line number>: passed: str, (StartsWith("foo") && EndsWith("bar")) || EqualsRange(bad_arr) for: "foobar" ( ( starts with: "foo" and ends with: "bar" ) or Equals: { 'o', 'o', 'f', 'b', 'a', 'r' } ) +Matchers.tests.cpp:<line number>: passed: container, EqualsRange(a) || EqualsRange(b) || EqualsRange(c) for: { 1, 2, 3 } ( Equals: { 1, 2, 3 } or Equals: { 0, 1, 2 } or Equals: { 4, 5, 6 } ) Tricky.tests.cpp:<line number>: passed: std::vector<constructor_throws>{constructor_throws{}, constructor_throws{}} Tricky.tests.cpp:<line number>: passed: std::vector<constructor_throws>{constructor_throws{}, constructor_throws{}} Tricky.tests.cpp:<line number>: passed: std::vector<int>{1, 2, 3} == std::vector<int>{1, 2, 3} @@ -883,6 +914,10 @@ RandomNumberGeneration.tests.cpp:<line number>: passed: rng() == 0x<hex digits> 4261393167 (0x<hex digits>) Message.tests.cpp:<line number>: failed: explicitly with 1 message: 'Message from section one' Message.tests.cpp:<line number>: failed: explicitly with 1 message: 'Message from section two' +Matchers.tests.cpp:<line number>: passed: (EvilMatcher(), EvilMatcher()), EvilCommaOperatorUsed +Matchers.tests.cpp:<line number>: passed: &EvilMatcher(), EvilAddressOfOperatorUsed +Matchers.tests.cpp:<line number>: passed: EvilMatcher() || EvilMatcher() && !EvilMatcher() +Matchers.tests.cpp:<line number>: passed: (EvilMatcher() && EvilMatcher()) || !EvilMatcher() CmdLine.tests.cpp:<line number>: passed: spec.hasFilters() == false for: false == false CmdLine.tests.cpp:<line number>: passed: spec.matches( *tcA ) == false for: false == false CmdLine.tests.cpp:<line number>: passed: spec.matches( *tcB ) == false for: false == false diff --git a/tests/SelfTest/Baselines/console.std.approved.txt b/tests/SelfTest/Baselines/console.std.approved.txt index d714a7f4..7056db0b 100644 --- a/tests/SelfTest/Baselines/console.std.approved.txt +++ b/tests/SelfTest/Baselines/console.std.approved.txt @@ -1380,6 +1380,6 @@ due to unexpected exception with message: Why would you throw a std::string? =============================================================================== -test cases: 320 | 246 passed | 70 failed | 4 failed as expected -assertions: 1792 | 1640 passed | 131 failed | 21 failed as expected +test cases: 328 | 254 passed | 70 failed | 4 failed as expected +assertions: 1827 | 1675 passed | 131 failed | 21 failed as expected diff --git a/tests/SelfTest/Baselines/console.sw.approved.txt b/tests/SelfTest/Baselines/console.sw.approved.txt index e6d9c48d..595acde6 100644 --- a/tests/SelfTest/Baselines/console.sw.approved.txt +++ b/tests/SelfTest/Baselines/console.sw.approved.txt @@ -2117,6 +2117,217 @@ with expansion: 5 == 5 ------------------------------------------------------------------------------- +Combining MatchAllOfGeneric does not nest +------------------------------------------------------------------------------- +Matchers.tests.cpp:<line number> +............................................................................... + +Matchers.tests.cpp:<line number>: PASSED: +with message: + std::is_same< decltype(MatcherA() && MatcherB() && MatcherC()), Catch:: + Matchers::Impl::MatchAllOfGeneric<MatcherA, MatcherB, MatcherC> >::value + +Matchers.tests.cpp:<line number>: PASSED: + REQUIRE_THAT( 1, MatcherA() && MatcherB() && MatcherC() ) +with expansion: + 1 ( equals: (int) 1 or (float) 1.0f and equals: (long long) 1 and equals: (T) + 1 ) + +Matchers.tests.cpp:<line number>: PASSED: +with message: + std::is_same< decltype(MatcherA() && MatcherB() && MatcherC() && MatcherD()), + Catch::Matchers::Impl::MatchAllOfGeneric<MatcherA, MatcherB, MatcherC, + MatcherD> >::value + +Matchers.tests.cpp:<line number>: PASSED: + REQUIRE_THAT( 1, MatcherA() && MatcherB() && MatcherC() && MatcherD() ) +with expansion: + 1 ( equals: (int) 1 or (float) 1.0f and equals: (long long) 1 and equals: (T) + 1 and equals: true ) + +------------------------------------------------------------------------------- +Combining MatchAnyOfGeneric does not nest +------------------------------------------------------------------------------- +Matchers.tests.cpp:<line number> +............................................................................... + +Matchers.tests.cpp:<line number>: PASSED: +with message: + std::is_same< decltype(MatcherA() || MatcherB() || MatcherC()), Catch:: + Matchers::Impl::MatchAnyOfGeneric<MatcherA, MatcherB, MatcherC> >::value + +Matchers.tests.cpp:<line number>: PASSED: + REQUIRE_THAT( 1, MatcherA() || MatcherB() || MatcherC() ) +with expansion: + 1 ( equals: (int) 1 or (float) 1.0f or equals: (long long) 1 or equals: (T) 1 + ) + +Matchers.tests.cpp:<line number>: PASSED: +with message: + std::is_same< decltype(MatcherA() || MatcherB() || MatcherC() || MatcherD()), + Catch::Matchers::Impl::MatchAnyOfGeneric<MatcherA, MatcherB, MatcherC, + MatcherD> >::value + +Matchers.tests.cpp:<line number>: PASSED: + REQUIRE_THAT( 1, MatcherA() || MatcherB() || MatcherC() || MatcherD() ) +with expansion: + 1 ( equals: (int) 1 or (float) 1.0f or equals: (long long) 1 or equals: (T) 1 + or equals: true ) + +------------------------------------------------------------------------------- +Combining MatchNotOfGeneric does not nest +------------------------------------------------------------------------------- +Matchers.tests.cpp:<line number> +............................................................................... + +Matchers.tests.cpp:<line number>: PASSED: +with message: + std::is_same< decltype(!MatcherA()), Catch::Matchers::Impl::MatchNotOfGeneric + <MatcherA> >::value + +Matchers.tests.cpp:<line number>: PASSED: + REQUIRE_THAT( 0, !MatcherA() ) +with expansion: + 0 not equals: (int) 1 or (float) 1.0f + +Matchers.tests.cpp:<line number>: PASSED: +with message: + std::is_same< decltype(!!MatcherA()), MatcherA const& >::value + +Matchers.tests.cpp:<line number>: PASSED: + REQUIRE_THAT( 1, !!MatcherA() ) +with expansion: + 1 equals: (int) 1 or (float) 1.0f + +Matchers.tests.cpp:<line number>: PASSED: +with message: + std::is_same< decltype(!!!MatcherA()), Catch::Matchers::Impl:: + MatchNotOfGeneric<MatcherA> >::value + +Matchers.tests.cpp:<line number>: PASSED: + REQUIRE_THAT( 0, !!!MatcherA() ) +with expansion: + 0 not equals: (int) 1 or (float) 1.0f + +Matchers.tests.cpp:<line number>: PASSED: +with message: + std::is_same< decltype(!!!!MatcherA()), MatcherA const & >::value + +Matchers.tests.cpp:<line number>: PASSED: + REQUIRE_THAT( 1, !!!!MatcherA() ) +with expansion: + 1 equals: (int) 1 or (float) 1.0f + +------------------------------------------------------------------------------- +Combining concrete matchers does not use templated matchers +------------------------------------------------------------------------------- +Matchers.tests.cpp:<line number> +............................................................................... + +Matchers.tests.cpp:<line number>: PASSED: +with message: + std::is_same< decltype(StartsWith("foo") || (StartsWith("bar") && EndsWith + ("bar") && !EndsWith("foo"))), Catch::Matchers::Impl::MatchAnyOf<std::string> + >::value |