From f7d7aa9eb2dd612fa976edd658407551129d9e49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Ho=C5=99e=C5=88ovsk=C3=BD?= Date: Sat, 28 Mar 2020 22:01:17 +0100 Subject: [PATCH] Fix and extend tests for composing generic matchers --- .../matchers/catch_matchers_templated.hpp | 3 +- .../Baselines/compact.sw.approved.txt | 20 ++++---- .../Baselines/console.std.approved.txt | 2 +- .../Baselines/console.sw.approved.txt | 48 ++++++++++++++----- .../SelfTest/Baselines/junit.sw.approved.txt | 2 +- tests/SelfTest/Baselines/tap.sw.approved.txt | 26 ++++++---- tests/SelfTest/Baselines/xml.sw.approved.txt | 28 ++++++++--- tests/SelfTest/UsageTests/Matchers.tests.cpp | 38 +++++++++++---- 8 files changed, 120 insertions(+), 47 deletions(-) diff --git a/src/catch2/matchers/catch_matchers_templated.hpp b/src/catch2/matchers/catch_matchers_templated.hpp index 7e2ac37c..71e3ce1b 100644 --- a/src/catch2/matchers/catch_matchers_templated.hpp +++ b/src/catch2/matchers/catch_matchers_templated.hpp @@ -41,7 +41,7 @@ namespace Matchers { template std::array array_cat(void const* lhs, std::array && rhs) { - std::array arr{lhs}; + std::array arr{ {lhs} }; std::copy_n(rhs.begin(), N, arr.begin() + 1); return arr; } @@ -129,6 +129,7 @@ namespace Matchers { } std::array m_matchers; + }; diff --git a/tests/SelfTest/Baselines/compact.sw.approved.txt b/tests/SelfTest/Baselines/compact.sw.approved.txt index 8ae9d726..95bb91ee 100644 --- a/tests/SelfTest/Baselines/compact.sw.approved.txt +++ b/tests/SelfTest/Baselines/compact.sw.approved.txt @@ -283,14 +283,18 @@ ToStringGeneral.tests.cpp:: passed: c == i for: 2 == 2 ToStringGeneral.tests.cpp:: passed: c == i for: 3 == 3 ToStringGeneral.tests.cpp:: passed: c == i for: 4 == 4 ToStringGeneral.tests.cpp:: passed: c == i for: 5 == 5 -Matchers.tests.cpp:: passed: with 1 message: 'std::is_same< decltype(MatcherA() && MatcherB() && MatcherC()), Catch::Matchers::Detail::MatchAllOfGeneric >::value' -Matchers.tests.cpp:: 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:: passed: with 1 message: 'std::is_same< decltype(MatcherA() && MatcherB() && MatcherC() && MatcherD()), Catch::Matchers::Detail::MatchAllOfGeneric >::value' -Matchers.tests.cpp:: 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:: passed: with 1 message: 'std::is_same< decltype(MatcherA() || MatcherB() || MatcherC()), Catch::Matchers::Detail::MatchAnyOfGeneric >::value' -Matchers.tests.cpp:: 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:: passed: with 1 message: 'std::is_same< decltype(MatcherA() || MatcherB() || MatcherC() || MatcherD()), Catch::Matchers::Detail::MatchAnyOfGeneric >::value' -Matchers.tests.cpp:: 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:: passed: with 1 message: 'std::is_same< decltype((MatcherA() && MatcherB()) && MatcherC()), Catch::Matchers::Detail::MatchAllOfGeneric >::value' +Matchers.tests.cpp:: 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:: passed: with 1 message: 'std::is_same< decltype(MatcherA() && (MatcherB() && MatcherC())), Catch::Matchers::Detail::MatchAllOfGeneric >::value' +Matchers.tests.cpp:: 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:: passed: with 1 message: 'std::is_same< decltype((MatcherA() && MatcherB()) && (MatcherC() && MatcherD())), Catch::Matchers::Detail::MatchAllOfGeneric >::value' +Matchers.tests.cpp:: 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:: passed: with 1 message: 'std::is_same< decltype((MatcherA() || MatcherB()) || MatcherC()), Catch::Matchers::Detail::MatchAnyOfGeneric >::value' +Matchers.tests.cpp:: 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:: passed: with 1 message: 'std::is_same< decltype(MatcherA() || (MatcherB() || MatcherC())), Catch::Matchers::Detail::MatchAnyOfGeneric >::value' +Matchers.tests.cpp:: 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:: passed: with 1 message: 'std::is_same< decltype((MatcherA() || MatcherB()) || (MatcherC() || MatcherD())), Catch::Matchers::Detail::MatchAnyOfGeneric >::value' +Matchers.tests.cpp:: 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:: passed: with 1 message: 'std::is_same< decltype(!MatcherA()), Catch::Matchers::Detail::MatchNotOfGeneric >::value' Matchers.tests.cpp:: passed: 0, !MatcherA() for: 0 not equals: (int) 1 or (float) 1.0f Matchers.tests.cpp:: passed: with 1 message: 'std::is_same< decltype(!!MatcherA()), MatcherA const& >::value' diff --git a/tests/SelfTest/Baselines/console.std.approved.txt b/tests/SelfTest/Baselines/console.std.approved.txt index ab80cb77..234837e4 100644 --- a/tests/SelfTest/Baselines/console.std.approved.txt +++ b/tests/SelfTest/Baselines/console.std.approved.txt @@ -1381,5 +1381,5 @@ due to unexpected exception with message: =============================================================================== test cases: 331 | 257 passed | 70 failed | 4 failed as expected -assertions: 1868 | 1716 passed | 131 failed | 21 failed as expected +assertions: 1872 | 1720 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 0df71623..9516b0b8 100644 --- a/tests/SelfTest/Baselines/console.sw.approved.txt +++ b/tests/SelfTest/Baselines/console.sw.approved.txt @@ -2287,23 +2287,34 @@ Matchers.tests.cpp: Matchers.tests.cpp:: PASSED: with message: - std::is_same< decltype(MatcherA() && MatcherB() && MatcherC()), Catch:: + std::is_same< decltype((MatcherA() && MatcherB()) && MatcherC()), Catch:: Matchers::Detail::MatchAllOfGeneric >::value Matchers.tests.cpp:: PASSED: - REQUIRE_THAT( 1, MatcherA() && MatcherB() && MatcherC() ) + 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:: PASSED: with message: - std::is_same< decltype(MatcherA() && MatcherB() && MatcherC() && MatcherD()), - Catch::Matchers::Detail::MatchAllOfGeneric >::value + std::is_same< decltype(MatcherA() && (MatcherB() && MatcherC())), Catch:: + Matchers::Detail::MatchAllOfGeneric >::value Matchers.tests.cpp:: PASSED: - REQUIRE_THAT( 1, MatcherA() && MatcherB() && MatcherC() && MatcherD() ) + 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:: PASSED: +with message: + std::is_same< decltype((MatcherA() && MatcherB()) && (MatcherC() && MatcherD + ())), Catch::Matchers::Detail::MatchAllOfGeneric >::value + +Matchers.tests.cpp:: 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 ) @@ -2316,23 +2327,34 @@ Matchers.tests.cpp: Matchers.tests.cpp:: PASSED: with message: - std::is_same< decltype(MatcherA() || MatcherB() || MatcherC()), Catch:: + std::is_same< decltype((MatcherA() || MatcherB()) || MatcherC()), Catch:: Matchers::Detail::MatchAnyOfGeneric >::value Matchers.tests.cpp:: PASSED: - REQUIRE_THAT( 1, MatcherA() || MatcherB() || MatcherC() ) + 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:: PASSED: with message: - std::is_same< decltype(MatcherA() || MatcherB() || MatcherC() || MatcherD()), - Catch::Matchers::Detail::MatchAnyOfGeneric >::value + std::is_same< decltype(MatcherA() || (MatcherB() || MatcherC())), Catch:: + Matchers::Detail::MatchAnyOfGeneric >::value Matchers.tests.cpp:: PASSED: - REQUIRE_THAT( 1, MatcherA() || MatcherB() || MatcherC() || MatcherD() ) + 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:: PASSED: +with message: + std::is_same< decltype((MatcherA() || MatcherB()) || (MatcherC() || MatcherD + ())), Catch::Matchers::Detail::MatchAnyOfGeneric >::value + +Matchers.tests.cpp:: 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 ) @@ -14626,5 +14648,5 @@ Misc.tests.cpp:: PASSED: =============================================================================== test cases: 331 | 241 passed | 86 failed | 4 failed as expected -assertions: 1885 | 1716 passed | 148 failed | 21 failed as expected +assertions: 1889 | 1720 passed | 148 failed | 21 failed as expected diff --git a/tests/SelfTest/Baselines/junit.sw.approved.txt b/tests/SelfTest/Baselines/junit.sw.approved.txt index 08e14692..de0e9c6b 100644 --- a/tests/SelfTest/Baselines/junit.sw.approved.txt +++ b/tests/SelfTest/Baselines/junit.sw.approved.txt @@ -1,7 +1,7 @@ - + diff --git a/tests/SelfTest/Baselines/tap.sw.approved.txt b/tests/SelfTest/Baselines/tap.sw.approved.txt index fc186d97..0168d313 100644 --- a/tests/SelfTest/Baselines/tap.sw.approved.txt +++ b/tests/SelfTest/Baselines/tap.sw.approved.txt @@ -565,21 +565,29 @@ ok {test-number} - c == i for: 4 == 4 # Character pretty printing ok {test-number} - c == i for: 5 == 5 # Combining MatchAllOfGeneric does not nest -ok {test-number} - with 1 message: 'std::is_same< decltype(MatcherA() && MatcherB() && MatcherC()), Catch::Matchers::Detail::MatchAllOfGeneric >::value' +ok {test-number} - with 1 message: 'std::is_same< decltype((MatcherA() && MatcherB()) && MatcherC()), Catch::Matchers::Detail::MatchAllOfGeneric >::value' # Combining MatchAllOfGeneric does not nest -ok {test-number} - 1, MatcherA() && MatcherB() && MatcherC() for: 1 ( equals: (int) 1 or (float) 1.0f and equals: (long long) 1 and equals: (T) 1 ) +ok {test-number} - 1, (MatcherA() && MatcherB()) && MatcherC() for: 1 ( equals: (int) 1 or (float) 1.0f and equals: (long long) 1 and equals: (T) 1 ) # Combining MatchAllOfGeneric does not nest -ok {test-number} - with 1 message: 'std::is_same< decltype(MatcherA() && MatcherB() && MatcherC() && MatcherD()), Catch::Matchers::Detail::MatchAllOfGeneric >::value' +ok {test-number} - with 1 message: 'std::is_same< decltype(MatcherA() && (MatcherB() && MatcherC())), Catch::Matchers::Detail::MatchAllOfGeneric >::value' # Combining MatchAllOfGeneric does not nest -ok {test-number} - 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 ) +ok {test-number} - 1, MatcherA() && (MatcherB() && MatcherC()) for: 1 ( equals: (int) 1 or (float) 1.0f and equals: (long long) 1 and equals: (T) 1 ) +# Combining MatchAllOfGeneric does not nest +ok {test-number} - with 1 message: 'std::is_same< decltype((MatcherA() && MatcherB()) && (MatcherC() && MatcherD())), Catch::Matchers::Detail::MatchAllOfGeneric >::value' +# Combining MatchAllOfGeneric does not nest +ok {test-number} - 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 ) # Combining MatchAnyOfGeneric does not nest -ok {test-number} - with 1 message: 'std::is_same< decltype(MatcherA() || MatcherB() || MatcherC()), Catch::Matchers::Detail::MatchAnyOfGeneric >::value' +ok {test-number} - with 1 message: 'std::is_same< decltype((MatcherA() || MatcherB()) || MatcherC()), Catch::Matchers::Detail::MatchAnyOfGeneric >::value' # Combining MatchAnyOfGeneric does not nest -ok {test-number} - 1, MatcherA() || MatcherB() || MatcherC() for: 1 ( equals: (int) 1 or (float) 1.0f or equals: (long long) 1 or equals: (T) 1 ) +ok {test-number} - 1, (MatcherA() || MatcherB()) || MatcherC() for: 1 ( equals: (int) 1 or (float) 1.0f or equals: (long long) 1 or equals: (T) 1 ) # Combining MatchAnyOfGeneric does not nest -ok {test-number} - with 1 message: 'std::is_same< decltype(MatcherA() || MatcherB() || MatcherC() || MatcherD()), Catch::Matchers::Detail::MatchAnyOfGeneric >::value' +ok {test-number} - with 1 message: 'std::is_same< decltype(MatcherA() || (MatcherB() || MatcherC())), Catch::Matchers::Detail::MatchAnyOfGeneric >::value' # Combining MatchAnyOfGeneric does not nest -ok {test-number} - 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 ) +ok {test-number} - 1, MatcherA() || (MatcherB() || MatcherC()) for: 1 ( equals: (int) 1 or (float) 1.0f or equals: (long long) 1 or equals: (T) 1 ) +# Combining MatchAnyOfGeneric does not nest +ok {test-number} - with 1 message: 'std::is_same< decltype((MatcherA() || MatcherB()) || (MatcherC() || MatcherD())), Catch::Matchers::Detail::MatchAnyOfGeneric >::value' +# Combining MatchAnyOfGeneric does not nest +ok {test-number} - 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 ) # Combining MatchNotOfGeneric does not nest ok {test-number} - with 1 message: 'std::is_same< decltype(!MatcherA()), Catch::Matchers::Detail::MatchNotOfGeneric >::value' # Combining MatchNotOfGeneric does not nest @@ -3762,5 +3770,5 @@ ok {test-number} - q3 == 23. for: 23.0 == 23.0 ok {test-number} - # xmlentitycheck ok {test-number} - -1..1877 +1..1881 diff --git a/tests/SelfTest/Baselines/xml.sw.approved.txt b/tests/SelfTest/Baselines/xml.sw.approved.txt index 0a9a0255..b1c59382 100644 --- a/tests/SelfTest/Baselines/xml.sw.approved.txt +++ b/tests/SelfTest/Baselines/xml.sw.approved.txt @@ -2613,7 +2613,7 @@ Nor would this - 1, MatcherA() && MatcherB() && MatcherC() + 1, (MatcherA() && MatcherB()) && MatcherC() 1 ( equals: (int) 1 or (float) 1.0f and equals: (long long) 1 and equals: (T) 1 ) @@ -2621,7 +2621,15 @@ Nor would this - 1, MatcherA() && MatcherB() && MatcherC() && MatcherD() + 1, MatcherA() && (MatcherB() && MatcherC()) + + + 1 ( equals: (int) 1 or (float) 1.0f and equals: (long long) 1 and equals: (T) 1 ) + + + + + 1, (MatcherA() && MatcherB()) && (MatcherC() && MatcherD()) 1 ( equals: (int) 1 or (float) 1.0f and equals: (long long) 1 and equals: (T) 1 and equals: true ) @@ -2632,7 +2640,7 @@ Nor would this - 1, MatcherA() || MatcherB() || MatcherC() + 1, (MatcherA() || MatcherB()) || MatcherC() 1 ( equals: (int) 1 or (float) 1.0f or equals: (long long) 1 or equals: (T) 1 ) @@ -2640,7 +2648,15 @@ Nor would this - 1, MatcherA() || MatcherB() || MatcherC() || MatcherD() + 1, MatcherA() || (MatcherB() || MatcherC()) + + + 1 ( equals: (int) 1 or (float) 1.0f or equals: (long long) 1 or equals: (T) 1 ) + + + + + 1, (MatcherA() || MatcherB()) || (MatcherC() || MatcherD()) 1 ( equals: (int) 1 or (float) 1.0f or equals: (long long) 1 or equals: (T) 1 or equals: true ) @@ -17541,7 +17557,7 @@ loose text artifact - + - + diff --git a/tests/SelfTest/UsageTests/Matchers.tests.cpp b/tests/SelfTest/UsageTests/Matchers.tests.cpp index 15c6e4cf..2efc4397 100644 --- a/tests/SelfTest/UsageTests/Matchers.tests.cpp +++ b/tests/SelfTest/UsageTests/Matchers.tests.cpp @@ -678,35 +678,57 @@ namespace { namespace MatchersTests { } TEST_CASE("Combining MatchAnyOfGeneric does not nest", "[matchers][templated]") { + // MatchAnyOfGeneric LHS + some matcher RHS STATIC_REQUIRE(std::is_same< - decltype(MatcherA() || MatcherB() || MatcherC()), + decltype((MatcherA() || MatcherB()) || MatcherC()), Catch::Matchers::Detail::MatchAnyOfGeneric >::value); - REQUIRE_THAT(1, MatcherA() || MatcherB() || MatcherC()); + REQUIRE_THAT(1, (MatcherA() || MatcherB()) || MatcherC()); + // some matcher LHS + MatchAnyOfGeneric RHS STATIC_REQUIRE(std::is_same< - decltype(MatcherA() || MatcherB() || MatcherC() || MatcherD()), + decltype(MatcherA() || (MatcherB() || MatcherC())), + Catch::Matchers::Detail::MatchAnyOfGeneric + >::value); + + REQUIRE_THAT(1, MatcherA() || (MatcherB() || MatcherC())); + + + // MatchAnyOfGeneric LHS + MatchAnyOfGeneric RHS + STATIC_REQUIRE(std::is_same< + decltype((MatcherA() || MatcherB()) || (MatcherC() || MatcherD())), Catch::Matchers::Detail::MatchAnyOfGeneric >::value); - REQUIRE_THAT(1, MatcherA() || MatcherB() || MatcherC() || MatcherD()); + REQUIRE_THAT(1, (MatcherA() || MatcherB()) || (MatcherC() || MatcherD())); } TEST_CASE("Combining MatchAllOfGeneric does not nest", "[matchers][templated]") { + // MatchAllOfGeneric lhs + some matcher RHS STATIC_REQUIRE(std::is_same< - decltype(MatcherA() && MatcherB() && MatcherC()), + decltype((MatcherA() && MatcherB()) && MatcherC()), Catch::Matchers::Detail::MatchAllOfGeneric >::value); - REQUIRE_THAT(1, MatcherA() && MatcherB() && MatcherC()); + REQUIRE_THAT(1, (MatcherA() && MatcherB()) && MatcherC()); + // some matcher LHS + MatchAllOfGeneric RSH STATIC_REQUIRE(std::is_same< - decltype(MatcherA() && MatcherB() && MatcherC() && MatcherD()), + decltype(MatcherA() && (MatcherB() && MatcherC())), + Catch::Matchers::Detail::MatchAllOfGeneric + >::value); + + REQUIRE_THAT(1, MatcherA() && (MatcherB() && MatcherC())); + + + // MatchAllOfGeneric LHS + MatchAllOfGeneric RHS + STATIC_REQUIRE(std::is_same< + decltype((MatcherA() && MatcherB()) && (MatcherC() && MatcherD())), Catch::Matchers::Detail::MatchAllOfGeneric >::value); - REQUIRE_THAT(1, MatcherA() && MatcherB() && MatcherC() && MatcherD()); + REQUIRE_THAT(1, (MatcherA() && MatcherB()) && (MatcherC() && MatcherD())); } TEST_CASE("Combining MatchNotOfGeneric does not nest", "[matchers][templated]") {