From f4fc2dab2c5bb8cab11b0a0dde8a8421076c30f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Ho=C5=99e=C5=88ovsk=C3=BD?= Date: Tue, 21 Apr 2020 19:09:45 +0200 Subject: [PATCH] Fixup template type argument inference for vector matchers --- include/internal/catch_matchers_vector.h | 8 ++-- .../Baselines/compact.sw.approved.txt | 4 ++ .../Baselines/console.std.approved.txt | 2 +- .../Baselines/console.sw.approved.txt | 22 ++++++++- .../SelfTest/Baselines/junit.sw.approved.txt | 2 +- .../SelfTest/Baselines/xml.sw.approved.txt | 46 ++++++++++++++++--- .../SelfTest/UsageTests/Matchers.tests.cpp | 7 ++- 7 files changed, 75 insertions(+), 16 deletions(-) diff --git a/include/internal/catch_matchers_vector.h b/include/internal/catch_matchers_vector.h index 084130f5..15a6ac99 100644 --- a/include/internal/catch_matchers_vector.h +++ b/include/internal/catch_matchers_vector.h @@ -151,7 +151,7 @@ namespace Matchers { // The following functions create the actual matcher objects. // This allows the types to be inferred - template + template, typename AllocMatch = AllocComp> Vector::ContainsMatcher Contains( std::vector const& comparator ) { return Vector::ContainsMatcher( comparator ); } @@ -161,17 +161,17 @@ namespace Matchers { return Vector::ContainsElementMatcher( comparator ); } - template + template, typename AllocMatch = AllocComp> Vector::EqualsMatcher Equals( std::vector const& comparator ) { return Vector::EqualsMatcher( comparator ); } - template + template, typename AllocMatch = AllocComp> Vector::ApproxMatcher Approx( std::vector const& comparator ) { return Vector::ApproxMatcher( comparator ); } - template + template, typename AllocMatch = AllocComp> Vector::UnorderedEqualsMatcher UnorderedEquals(std::vector const& target) { return Vector::UnorderedEqualsMatcher( target ); } diff --git a/projects/SelfTest/Baselines/compact.sw.approved.txt b/projects/SelfTest/Baselines/compact.sw.approved.txt index 4bf889a5..08390525 100644 --- a/projects/SelfTest/Baselines/compact.sw.approved.txt +++ b/projects/SelfTest/Baselines/compact.sw.approved.txt @@ -1529,6 +1529,7 @@ Approx.tests.cpp:: passed: approx( d ) != 1.25 for: Approx( 1.23 ) VariadicMacros.tests.cpp:: passed: with 1 message: 'no assertions' Matchers.tests.cpp:: passed: empty, Approx(empty) for: { } is approx: { } Matchers.tests.cpp:: passed: v1, Approx(v1) for: { 1.0, 2.0, 3.0 } is approx: { 1.0, 2.0, 3.0 } +Matchers.tests.cpp:: passed: v1, Approx({ 1., 2., 3. }) for: { 1.0, 2.0, 3.0 } is approx: { 1.0, 2.0, 3.0 } Matchers.tests.cpp:: passed: v1, !Approx(temp) for: { 1.0, 2.0, 3.0 } not is approx: { 1.0, 2.0, 3.0, 4.0 } Matchers.tests.cpp:: passed: v1, !Approx(v2) for: { 1.0, 2.0, 3.0 } not is approx: { 1.5, 2.5, 3.5 } Matchers.tests.cpp:: passed: v1, Approx(v2).margin(0.5) for: { 1.0, 2.0, 3.0 } is approx: { 1.5, 2.5, 3.5 } @@ -1540,6 +1541,7 @@ Matchers.tests.cpp:: passed: v, VectorContains(1) for: { 1, 2, 3 } Matchers.tests.cpp:: passed: v, VectorContains(2) for: { 1, 2, 3 } Contains: 2 Matchers.tests.cpp:: passed: v5, (VectorContains>(2)) for: { 1, 2, 3 } Contains: 2 Matchers.tests.cpp:: passed: v, Contains(v2) for: { 1, 2, 3 } Contains: { 1, 2 } +Matchers.tests.cpp:: passed: v, Contains({ 1, 2 }) for: { 1, 2, 3 } Contains: { 1, 2 } Matchers.tests.cpp:: passed: v5, (Contains, CustomAllocator>(v2)) for: { 1, 2, 3 } Contains: { 1, 2 } Matchers.tests.cpp:: passed: v, Contains(v2) for: { 1, 2, 3 } Contains: { 1, 2, 3 } Matchers.tests.cpp:: passed: v, Contains(empty) for: { 1, 2, 3 } Contains: { } @@ -1549,10 +1551,12 @@ Matchers.tests.cpp:: passed: v5, Contains(v6) for: { 1, 2, 3 } Cont Matchers.tests.cpp:: passed: v, VectorContains(1) && VectorContains(2) for: { 1, 2, 3 } ( Contains: 1 and Contains: 2 ) Matchers.tests.cpp:: passed: v, Equals(v) for: { 1, 2, 3 } Equals: { 1, 2, 3 } Matchers.tests.cpp:: passed: empty, Equals(empty) for: { } Equals: { } +Matchers.tests.cpp:: passed: v, Equals({ 1, 2, 3 }) for: { 1, 2, 3 } Equals: { 1, 2, 3 } Matchers.tests.cpp:: passed: v, Equals(v2) for: { 1, 2, 3 } Equals: { 1, 2, 3 } Matchers.tests.cpp:: passed: v5, (Equals, CustomAllocator>(v2)) for: { 1, 2, 3 } Equals: { 1, 2, 3 } Matchers.tests.cpp:: passed: v5, Equals(v6) for: { 1, 2, 3 } Equals: { 1, 2, 3 } Matchers.tests.cpp:: passed: v, UnorderedEquals(v) for: { 1, 2, 3 } UnorderedEquals: { 1, 2, 3 } +Matchers.tests.cpp:: passed: v, UnorderedEquals({ 3, 2, 1 }) for: { 1, 2, 3 } UnorderedEquals: { 3, 2, 1 } Matchers.tests.cpp:: passed: empty, UnorderedEquals(empty) for: { } UnorderedEquals: { } Matchers.tests.cpp:: passed: permuted, UnorderedEquals(v) for: { 1, 3, 2 } UnorderedEquals: { 1, 2, 3 } Matchers.tests.cpp:: passed: permuted, UnorderedEquals(v) for: { 2, 3, 1 } UnorderedEquals: { 1, 2, 3 } diff --git a/projects/SelfTest/Baselines/console.std.approved.txt b/projects/SelfTest/Baselines/console.std.approved.txt index f53b62ac..0b403c42 100644 --- a/projects/SelfTest/Baselines/console.std.approved.txt +++ b/projects/SelfTest/Baselines/console.std.approved.txt @@ -1381,5 +1381,5 @@ due to unexpected exception with message: =============================================================================== test cases: 310 | 236 passed | 70 failed | 4 failed as expected -assertions: 1695 | 1543 passed | 131 failed | 21 failed as expected +assertions: 1699 | 1547 passed | 131 failed | 21 failed as expected diff --git a/projects/SelfTest/Baselines/console.sw.approved.txt b/projects/SelfTest/Baselines/console.sw.approved.txt index 4d51f103..bcf66625 100644 --- a/projects/SelfTest/Baselines/console.sw.approved.txt +++ b/projects/SelfTest/Baselines/console.sw.approved.txt @@ -11177,6 +11177,11 @@ Matchers.tests.cpp:: PASSED: with expansion: { 1.0, 2.0, 3.0 } is approx: { 1.0, 2.0, 3.0 } +Matchers.tests.cpp:: PASSED: + REQUIRE_THAT( v1, Approx({ 1., 2., 3. }) ) +with expansion: + { 1.0, 2.0, 3.0 } is approx: { 1.0, 2.0, 3.0 } + ------------------------------------------------------------------------------- Vector Approx matcher Vectors with elements @@ -11276,6 +11281,11 @@ Matchers.tests.cpp:: PASSED: with expansion: { 1, 2, 3 } Contains: { 1, 2 } +Matchers.tests.cpp:: PASSED: + CHECK_THAT( v, Contains({ 1, 2 }) ) +with expansion: + { 1, 2, 3 } Contains: { 1, 2 } + Matchers.tests.cpp:: PASSED: CHECK_THAT( v5, (Contains, CustomAllocator>(v2)) ) with expansion: @@ -11335,6 +11345,11 @@ Matchers.tests.cpp:: PASSED: with expansion: { } Equals: { } +Matchers.tests.cpp:: PASSED: + CHECK_THAT( v, Equals({ 1, 2, 3 }) ) +with expansion: + { 1, 2, 3 } Equals: { 1, 2, 3 } + Matchers.tests.cpp:: PASSED: CHECK_THAT( v, Equals(v2) ) with expansion: @@ -11362,6 +11377,11 @@ Matchers.tests.cpp:: PASSED: with expansion: { 1, 2, 3 } UnorderedEquals: { 1, 2, 3 } +Matchers.tests.cpp:: PASSED: + CHECK_THAT( v, UnorderedEquals({ 3, 2, 1 }) ) +with expansion: + { 1, 2, 3 } UnorderedEquals: { 3, 2, 1 } + Matchers.tests.cpp:: PASSED: CHECK_THAT( empty, UnorderedEquals(empty) ) with expansion: @@ -13544,5 +13564,5 @@ Misc.tests.cpp:: PASSED: =============================================================================== test cases: 310 | 220 passed | 86 failed | 4 failed as expected -assertions: 1712 | 1543 passed | 148 failed | 21 failed as expected +assertions: 1716 | 1547 passed | 148 failed | 21 failed as expected diff --git a/projects/SelfTest/Baselines/junit.sw.approved.txt b/projects/SelfTest/Baselines/junit.sw.approved.txt index 448aa069..47341280 100644 --- a/projects/SelfTest/Baselines/junit.sw.approved.txt +++ b/projects/SelfTest/Baselines/junit.sw.approved.txt @@ -1,7 +1,7 @@ - + diff --git a/projects/SelfTest/Baselines/xml.sw.approved.txt b/projects/SelfTest/Baselines/xml.sw.approved.txt index fa7a1676..a2eb1eed 100644 --- a/projects/SelfTest/Baselines/xml.sw.approved.txt +++ b/projects/SelfTest/Baselines/xml.sw.approved.txt @@ -13624,9 +13624,17 @@ There is no extra whitespace here { 1.0, 2.0, 3.0 } is approx: { 1.0, 2.0, 3.0 } - + + + v1, Approx<double>({ 1., 2., 3. }) + + + { 1.0, 2.0, 3.0 } is approx: { 1.0, 2.0, 3.0 } + + + - +
@@ -13744,6 +13752,14 @@ There is no extra whitespace here { 1, 2, 3 } Contains: { 1, 2 } + + + v, Contains<int>({ 1, 2 }) + + + { 1, 2, 3 } Contains: { 1, 2 } + + v5, (Contains<int, std::allocator<int>, CustomAllocator<int>>(v2)) @@ -13792,7 +13808,7 @@ There is no extra whitespace here { 1, 2, 3 } Contains: { 1, 2 } - +
@@ -13822,6 +13838,14 @@ There is no extra whitespace here { } Equals: { } + + + v, Equals<int>({ 1, 2, 3 }) + + + { 1, 2, 3 } Equals: { 1, 2, 3 } + + v, Equals(v2) @@ -13846,7 +13870,7 @@ There is no extra whitespace here { 1, 2, 3 } Equals: { 1, 2, 3 } - +
@@ -13857,6 +13881,14 @@ There is no extra whitespace here { 1, 2, 3 } UnorderedEquals: { 1, 2, 3 } + + + v, UnorderedEquals<int>({ 3, 2, 1 }) + + + { 1, 2, 3 } UnorderedEquals: { 3, 2, 1 } + + empty, UnorderedEquals(empty) @@ -13897,7 +13929,7 @@ There is no extra whitespace here { 1, 3, 2 } UnorderedEquals: { 1, 2, 3 } - +
@@ -16207,7 +16239,7 @@ loose text artifact
- + - + diff --git a/projects/SelfTest/UsageTests/Matchers.tests.cpp b/projects/SelfTest/UsageTests/Matchers.tests.cpp index e7a1d542..c4a8ebf9 100644 --- a/projects/SelfTest/UsageTests/Matchers.tests.cpp +++ b/projects/SelfTest/UsageTests/Matchers.tests.cpp @@ -288,6 +288,7 @@ namespace { namespace MatchersTests { } SECTION("Contains (vector)") { CHECK_THAT(v, Contains(v2)); + CHECK_THAT(v, Contains({ 1, 2 })); CHECK_THAT(v5, (Contains, CustomAllocator>(v2))); v2.push_back(3); // now exactly matches @@ -307,10 +308,10 @@ namespace { namespace MatchersTests { // Same vector CHECK_THAT(v, Equals(v)); - CHECK_THAT(empty, Equals(empty)); // Different vector with same elements + CHECK_THAT(v, Equals({ 1, 2, 3 })); v2.push_back(3); CHECK_THAT(v, Equals(v2)); @@ -321,6 +322,7 @@ namespace { namespace MatchersTests { } SECTION("UnorderedEquals") { CHECK_THAT(v, UnorderedEquals(v)); + CHECK_THAT(v, UnorderedEquals({ 3, 2, 1 })); CHECK_THAT(empty, UnorderedEquals(empty)); auto permuted = v; @@ -580,6 +582,7 @@ namespace { namespace MatchersTests { std::vector v1({1., 2., 3.}); SECTION("A vector is approx equal to itself") { REQUIRE_THAT(v1, Approx(v1)); + REQUIRE_THAT(v1, Approx({ 1., 2., 3. })); } std::vector v2({1.5, 2.5, 3.5}); SECTION("Different length") { @@ -614,7 +617,7 @@ namespace { namespace MatchersTests { REQUIRE_THROWS_MATCHES(throwsSpecialException(2), SpecialException, !Message("DerivedException::what")); REQUIRE_THROWS_MATCHES(throwsSpecialException(2), SpecialException, Message("SpecialException::what")); } - + TEST_CASE("Composed matchers are distinct", "[matchers][composed]") { auto m1 = Contains("string"); auto m2 = Contains("random");