Fixup template type argument inference for vector matchers

This commit is contained in:
Martin Hořeňovský 2020-04-21 19:09:45 +02:00
parent cfb6956698
commit f4fc2dab2c
No known key found for this signature in database
GPG Key ID: DE48307B8B0D381A
7 changed files with 75 additions and 16 deletions

View File

@ -151,7 +151,7 @@ namespace Matchers {
// The following functions create the actual matcher objects. // The following functions create the actual matcher objects.
// This allows the types to be inferred // This allows the types to be inferred
template<typename T, typename AllocComp, typename AllocMatch = AllocComp> template<typename T, typename AllocComp = std::allocator<T>, typename AllocMatch = AllocComp>
Vector::ContainsMatcher<T, AllocComp, AllocMatch> Contains( std::vector<T, AllocComp> const& comparator ) { Vector::ContainsMatcher<T, AllocComp, AllocMatch> Contains( std::vector<T, AllocComp> const& comparator ) {
return Vector::ContainsMatcher<T, AllocComp, AllocMatch>( comparator ); return Vector::ContainsMatcher<T, AllocComp, AllocMatch>( comparator );
} }
@ -161,17 +161,17 @@ namespace Matchers {
return Vector::ContainsElementMatcher<T, Alloc>( comparator ); return Vector::ContainsElementMatcher<T, Alloc>( comparator );
} }
template<typename T, typename AllocComp, typename AllocMatch = AllocComp> template<typename T, typename AllocComp = std::allocator<T>, typename AllocMatch = AllocComp>
Vector::EqualsMatcher<T, AllocComp, AllocMatch> Equals( std::vector<T, AllocComp> const& comparator ) { Vector::EqualsMatcher<T, AllocComp, AllocMatch> Equals( std::vector<T, AllocComp> const& comparator ) {
return Vector::EqualsMatcher<T, AllocComp, AllocMatch>( comparator ); return Vector::EqualsMatcher<T, AllocComp, AllocMatch>( comparator );
} }
template<typename T, typename AllocComp, typename AllocMatch = AllocComp> template<typename T, typename AllocComp = std::allocator<T>, typename AllocMatch = AllocComp>
Vector::ApproxMatcher<T, AllocComp, AllocMatch> Approx( std::vector<T, AllocComp> const& comparator ) { Vector::ApproxMatcher<T, AllocComp, AllocMatch> Approx( std::vector<T, AllocComp> const& comparator ) {
return Vector::ApproxMatcher<T, AllocComp, AllocMatch>( comparator ); return Vector::ApproxMatcher<T, AllocComp, AllocMatch>( comparator );
} }
template<typename T, typename AllocComp, typename AllocMatch = AllocComp> template<typename T, typename AllocComp = std::allocator<T>, typename AllocMatch = AllocComp>
Vector::UnorderedEqualsMatcher<T, AllocComp, AllocMatch> UnorderedEquals(std::vector<T, AllocComp> const& target) { Vector::UnorderedEqualsMatcher<T, AllocComp, AllocMatch> UnorderedEquals(std::vector<T, AllocComp> const& target) {
return Vector::UnorderedEqualsMatcher<T, AllocComp, AllocMatch>( target ); return Vector::UnorderedEqualsMatcher<T, AllocComp, AllocMatch>( target );
} }

View File

@ -1529,6 +1529,7 @@ Approx.tests.cpp:<line number>: passed: approx( d ) != 1.25 for: Approx( 1.23 )
VariadicMacros.tests.cpp:<line number>: passed: with 1 message: 'no assertions' VariadicMacros.tests.cpp:<line number>: passed: with 1 message: 'no assertions'
Matchers.tests.cpp:<line number>: passed: empty, Approx(empty) for: { } is approx: { } Matchers.tests.cpp:<line number>: passed: empty, Approx(empty) for: { } is approx: { }
Matchers.tests.cpp:<line number>: passed: v1, Approx(v1) for: { 1.0, 2.0, 3.0 } is approx: { 1.0, 2.0, 3.0 } Matchers.tests.cpp:<line number>: passed: v1, Approx(v1) for: { 1.0, 2.0, 3.0 } is approx: { 1.0, 2.0, 3.0 }
Matchers.tests.cpp:<line number>: passed: v1, Approx<double>({ 1., 2., 3. }) for: { 1.0, 2.0, 3.0 } is approx: { 1.0, 2.0, 3.0 }
Matchers.tests.cpp:<line number>: 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:<line number>: 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:<line number>: passed: v1, !Approx(v2) for: { 1.0, 2.0, 3.0 } not is approx: { 1.5, 2.5, 3.5 } Matchers.tests.cpp:<line number>: passed: v1, !Approx(v2) for: { 1.0, 2.0, 3.0 } not is approx: { 1.5, 2.5, 3.5 }
Matchers.tests.cpp:<line number>: passed: v1, Approx(v2).margin(0.5) for: { 1.0, 2.0, 3.0 } is approx: { 1.5, 2.5, 3.5 } Matchers.tests.cpp:<line number>: 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:<line number>: passed: v, VectorContains(1) for: { 1, 2, 3 }
Matchers.tests.cpp:<line number>: passed: v, VectorContains(2) for: { 1, 2, 3 } Contains: 2 Matchers.tests.cpp:<line number>: passed: v, VectorContains(2) for: { 1, 2, 3 } Contains: 2
Matchers.tests.cpp:<line number>: passed: v5, (VectorContains<int, CustomAllocator<int>>(2)) for: { 1, 2, 3 } Contains: 2 Matchers.tests.cpp:<line number>: passed: v5, (VectorContains<int, CustomAllocator<int>>(2)) for: { 1, 2, 3 } Contains: 2
Matchers.tests.cpp:<line number>: passed: v, Contains(v2) for: { 1, 2, 3 } Contains: { 1, 2 } Matchers.tests.cpp:<line number>: passed: v, Contains(v2) for: { 1, 2, 3 } Contains: { 1, 2 }
Matchers.tests.cpp:<line number>: passed: v, Contains<int>({ 1, 2 }) for: { 1, 2, 3 } Contains: { 1, 2 }
Matchers.tests.cpp:<line number>: passed: v5, (Contains<int, std::allocator<int>, CustomAllocator<int>>(v2)) for: { 1, 2, 3 } Contains: { 1, 2 } Matchers.tests.cpp:<line number>: passed: v5, (Contains<int, std::allocator<int>, CustomAllocator<int>>(v2)) for: { 1, 2, 3 } Contains: { 1, 2 }
Matchers.tests.cpp:<line number>: passed: v, Contains(v2) for: { 1, 2, 3 } Contains: { 1, 2, 3 } Matchers.tests.cpp:<line number>: passed: v, Contains(v2) for: { 1, 2, 3 } Contains: { 1, 2, 3 }
Matchers.tests.cpp:<line number>: passed: v, Contains(empty) for: { 1, 2, 3 } Contains: { } Matchers.tests.cpp:<line number>: passed: v, Contains(empty) for: { 1, 2, 3 } Contains: { }
@ -1549,10 +1551,12 @@ Matchers.tests.cpp:<line number>: passed: v5, Contains(v6) for: { 1, 2, 3 } Cont
Matchers.tests.cpp:<line number>: passed: v, VectorContains(1) && VectorContains(2) for: { 1, 2, 3 } ( Contains: 1 and Contains: 2 ) Matchers.tests.cpp:<line number>: passed: v, VectorContains(1) && VectorContains(2) for: { 1, 2, 3 } ( Contains: 1 and Contains: 2 )
Matchers.tests.cpp:<line number>: passed: v, Equals(v) for: { 1, 2, 3 } Equals: { 1, 2, 3 } Matchers.tests.cpp:<line number>: passed: v, Equals(v) for: { 1, 2, 3 } Equals: { 1, 2, 3 }
Matchers.tests.cpp:<line number>: passed: empty, Equals(empty) for: { } Equals: { } Matchers.tests.cpp:<line number>: passed: empty, Equals(empty) for: { } Equals: { }
Matchers.tests.cpp:<line number>: passed: v, Equals<int>({ 1, 2, 3 }) for: { 1, 2, 3 } Equals: { 1, 2, 3 }
Matchers.tests.cpp:<line number>: passed: v, Equals(v2) for: { 1, 2, 3 } Equals: { 1, 2, 3 } Matchers.tests.cpp:<line number>: passed: v, Equals(v2) for: { 1, 2, 3 } Equals: { 1, 2, 3 }
Matchers.tests.cpp:<line number>: passed: v5, (Equals<int, std::allocator<int>, CustomAllocator<int>>(v2)) for: { 1, 2, 3 } Equals: { 1, 2, 3 } Matchers.tests.cpp:<line number>: passed: v5, (Equals<int, std::allocator<int>, CustomAllocator<int>>(v2)) for: { 1, 2, 3 } Equals: { 1, 2, 3 }
Matchers.tests.cpp:<line number>: passed: v5, Equals(v6) for: { 1, 2, 3 } Equals: { 1, 2, 3 } Matchers.tests.cpp:<line number>: passed: v5, Equals(v6) for: { 1, 2, 3 } Equals: { 1, 2, 3 }
Matchers.tests.cpp:<line number>: passed: v, UnorderedEquals(v) for: { 1, 2, 3 } UnorderedEquals: { 1, 2, 3 } Matchers.tests.cpp:<line number>: passed: v, UnorderedEquals(v) for: { 1, 2, 3 } UnorderedEquals: { 1, 2, 3 }
Matchers.tests.cpp:<line number>: passed: v, UnorderedEquals<int>({ 3, 2, 1 }) for: { 1, 2, 3 } UnorderedEquals: { 3, 2, 1 }
Matchers.tests.cpp:<line number>: passed: empty, UnorderedEquals(empty) for: { } UnorderedEquals: { } Matchers.tests.cpp:<line number>: passed: empty, UnorderedEquals(empty) for: { } UnorderedEquals: { }
Matchers.tests.cpp:<line number>: passed: permuted, UnorderedEquals(v) for: { 1, 3, 2 } UnorderedEquals: { 1, 2, 3 } Matchers.tests.cpp:<line number>: passed: permuted, UnorderedEquals(v) for: { 1, 3, 2 } UnorderedEquals: { 1, 2, 3 }
Matchers.tests.cpp:<line number>: passed: permuted, UnorderedEquals(v) for: { 2, 3, 1 } UnorderedEquals: { 1, 2, 3 } Matchers.tests.cpp:<line number>: passed: permuted, UnorderedEquals(v) for: { 2, 3, 1 } UnorderedEquals: { 1, 2, 3 }

View File

@ -1381,5 +1381,5 @@ due to unexpected exception with message:
=============================================================================== ===============================================================================
test cases: 310 | 236 passed | 70 failed | 4 failed as expected 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

View File

@ -11177,6 +11177,11 @@ Matchers.tests.cpp:<line number>: PASSED:
with expansion: with expansion:
{ 1.0, 2.0, 3.0 } is approx: { 1.0, 2.0, 3.0 } { 1.0, 2.0, 3.0 } is approx: { 1.0, 2.0, 3.0 }
Matchers.tests.cpp:<line number>: PASSED:
REQUIRE_THAT( v1, Approx<double>({ 1., 2., 3. }) )
with expansion:
{ 1.0, 2.0, 3.0 } is approx: { 1.0, 2.0, 3.0 }
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Vector Approx matcher Vector Approx matcher
Vectors with elements Vectors with elements
@ -11276,6 +11281,11 @@ Matchers.tests.cpp:<line number>: PASSED:
with expansion: with expansion:
{ 1, 2, 3 } Contains: { 1, 2 } { 1, 2, 3 } Contains: { 1, 2 }
Matchers.tests.cpp:<line number>: PASSED:
CHECK_THAT( v, Contains<int>({ 1, 2 }) )
with expansion:
{ 1, 2, 3 } Contains: { 1, 2 }
Matchers.tests.cpp:<line number>: PASSED: Matchers.tests.cpp:<line number>: PASSED:
CHECK_THAT( v5, (Contains<int, std::allocator<int>, CustomAllocator<int>>(v2)) ) CHECK_THAT( v5, (Contains<int, std::allocator<int>, CustomAllocator<int>>(v2)) )
with expansion: with expansion:
@ -11335,6 +11345,11 @@ Matchers.tests.cpp:<line number>: PASSED:
with expansion: with expansion:
{ } Equals: { } { } Equals: { }
Matchers.tests.cpp:<line number>: PASSED:
CHECK_THAT( v, Equals<int>({ 1, 2, 3 }) )
with expansion:
{ 1, 2, 3 } Equals: { 1, 2, 3 }
Matchers.tests.cpp:<line number>: PASSED: Matchers.tests.cpp:<line number>: PASSED:
CHECK_THAT( v, Equals(v2) ) CHECK_THAT( v, Equals(v2) )
with expansion: with expansion:
@ -11362,6 +11377,11 @@ Matchers.tests.cpp:<line number>: PASSED:
with expansion: with expansion:
{ 1, 2, 3 } UnorderedEquals: { 1, 2, 3 } { 1, 2, 3 } UnorderedEquals: { 1, 2, 3 }
Matchers.tests.cpp:<line number>: PASSED:
CHECK_THAT( v, UnorderedEquals<int>({ 3, 2, 1 }) )
with expansion:
{ 1, 2, 3 } UnorderedEquals: { 3, 2, 1 }
Matchers.tests.cpp:<line number>: PASSED: Matchers.tests.cpp:<line number>: PASSED:
CHECK_THAT( empty, UnorderedEquals(empty) ) CHECK_THAT( empty, UnorderedEquals(empty) )
with expansion: with expansion:
@ -13544,5 +13564,5 @@ Misc.tests.cpp:<line number>: PASSED:
=============================================================================== ===============================================================================
test cases: 310 | 220 passed | 86 failed | 4 failed as expected 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

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<testsuitesloose text artifact <testsuitesloose text artifact
> >
<testsuite name="<exe-name>" errors="17" failures="132" tests="1713" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}"> <testsuite name="<exe-name>" errors="17" failures="132" tests="1717" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
<properties> <properties>
<property name="filters" value="~[!nonportable]~[!benchmark]~[approvals]"/> <property name="filters" value="~[!nonportable]~[!benchmark]~[approvals]"/>
<property name="random-seed" value="1"/> <property name="random-seed" value="1"/>

View File

@ -13624,9 +13624,17 @@ There is no extra whitespace here
{ 1.0, 2.0, 3.0 } is approx: { 1.0, 2.0, 3.0 } { 1.0, 2.0, 3.0 } is approx: { 1.0, 2.0, 3.0 }
</Expanded> </Expanded>
</Expression> </Expression>
<OverallResults successes="1" failures="0" expectedFailures="0"/> <Expression success="true" type="REQUIRE_THAT" filename="projects/<exe-name>/UsageTests/Matchers.tests.cpp" >
<Original>
v1, Approx&lt;double>({ 1., 2., 3. })
</Original>
<Expanded>
{ 1.0, 2.0, 3.0 } is approx: { 1.0, 2.0, 3.0 }
</Expanded>
</Expression>
<OverallResults successes="2" failures="0" expectedFailures="0"/>
</Section> </Section>
<OverallResults successes="1" failures="0" expectedFailures="0"/> <OverallResults successes="2" failures="0" expectedFailures="0"/>
</Section> </Section>
<Section name="Vectors with elements" filename="projects/<exe-name>/UsageTests/Matchers.tests.cpp" > <Section name="Vectors with elements" filename="projects/<exe-name>/UsageTests/Matchers.tests.cpp" >
<Section name="Different length" filename="projects/<exe-name>/UsageTests/Matchers.tests.cpp" > <Section name="Different length" filename="projects/<exe-name>/UsageTests/Matchers.tests.cpp" >
@ -13744,6 +13752,14 @@ There is no extra whitespace here
{ 1, 2, 3 } Contains: { 1, 2 } { 1, 2, 3 } Contains: { 1, 2 }
</Expanded> </Expanded>
</Expression> </Expression>
<Expression success="true" type="CHECK_THAT" filename="projects/<exe-name>/UsageTests/Matchers.tests.cpp" >
<Original>
v, Contains&lt;int>({ 1, 2 })
</Original>
<Expanded>
{ 1, 2, 3 } Contains: { 1, 2 }
</Expanded>
</Expression>
<Expression success="true" type="CHECK_THAT" filename="projects/<exe-name>/UsageTests/Matchers.tests.cpp" > <Expression success="true" type="CHECK_THAT" filename="projects/<exe-name>/UsageTests/Matchers.tests.cpp" >
<Original> <Original>
v5, (Contains&lt;int, std::allocator&lt;int>, CustomAllocator&lt;int>>(v2)) v5, (Contains&lt;int, std::allocator&lt;int>, CustomAllocator&lt;int>>(v2))
@ -13792,7 +13808,7 @@ There is no extra whitespace here
{ 1, 2, 3 } Contains: { 1, 2 } { 1, 2, 3 } Contains: { 1, 2 }
</Expanded> </Expanded>
</Expression> </Expression>
<OverallResults successes="7" failures="0" expectedFailures="0"/> <OverallResults successes="8" failures="0" expectedFailures="0"/>
</Section> </Section>
<Section name="Contains (element), composed" filename="projects/<exe-name>/UsageTests/Matchers.tests.cpp" > <Section name="Contains (element), composed" filename="projects/<exe-name>/UsageTests/Matchers.tests.cpp" >
<Expression success="true" type="CHECK_THAT" filename="projects/<exe-name>/UsageTests/Matchers.tests.cpp" > <Expression success="true" type="CHECK_THAT" filename="projects/<exe-name>/UsageTests/Matchers.tests.cpp" >
@ -13822,6 +13838,14 @@ There is no extra whitespace here
{ } Equals: { } { } Equals: { }
</Expanded> </Expanded>
</Expression> </Expression>
<Expression success="true" type="CHECK_THAT" filename="projects/<exe-name>/UsageTests/Matchers.tests.cpp" >
<Original>
v, Equals&lt;int>({ 1, 2, 3 })
</Original>
<Expanded>
{ 1, 2, 3 } Equals: { 1, 2, 3 }
</Expanded>
</Expression>
<Expression success="true" type="CHECK_THAT" filename="projects/<exe-name>/UsageTests/Matchers.tests.cpp" > <Expression success="true" type="CHECK_THAT" filename="projects/<exe-name>/UsageTests/Matchers.tests.cpp" >
<Original> <Original>
v, Equals(v2) v, Equals(v2)
@ -13846,7 +13870,7 @@ There is no extra whitespace here
{ 1, 2, 3 } Equals: { 1, 2, 3 } { 1, 2, 3 } Equals: { 1, 2, 3 }
</Expanded> </Expanded>
</Expression> </Expression>
<OverallResults successes="5" failures="0" expectedFailures="0"/> <OverallResults successes="6" failures="0" expectedFailures="0"/>
</Section> </Section>
<Section name="UnorderedEquals" filename="projects/<exe-name>/UsageTests/Matchers.tests.cpp" > <Section name="UnorderedEquals" filename="projects/<exe-name>/UsageTests/Matchers.tests.cpp" >
<Expression success="true" type="CHECK_THAT" filename="projects/<exe-name>/UsageTests/Matchers.tests.cpp" > <Expression success="true" type="CHECK_THAT" filename="projects/<exe-name>/UsageTests/Matchers.tests.cpp" >
@ -13857,6 +13881,14 @@ There is no extra whitespace here
{ 1, 2, 3 } UnorderedEquals: { 1, 2, 3 } { 1, 2, 3 } UnorderedEquals: { 1, 2, 3 }
</Expanded> </Expanded>
</Expression> </Expression>
<Expression success="true" type="CHECK_THAT" filename="projects/<exe-name>/UsageTests/Matchers.tests.cpp" >
<Original>
v, UnorderedEquals&lt;int>({ 3, 2, 1 })
</Original>
<Expanded>
{ 1, 2, 3 } UnorderedEquals: { 3, 2, 1 }
</Expanded>
</Expression>
<Expression success="true" type="CHECK_THAT" filename="projects/<exe-name>/UsageTests/Matchers.tests.cpp" > <Expression success="true" type="CHECK_THAT" filename="projects/<exe-name>/UsageTests/Matchers.tests.cpp" >
<Original> <Original>
empty, UnorderedEquals(empty) empty, UnorderedEquals(empty)
@ -13897,7 +13929,7 @@ There is no extra whitespace here
{ 1, 3, 2 } UnorderedEquals: { 1, 2, 3 } { 1, 3, 2 } UnorderedEquals: { 1, 2, 3 }
</Expanded> </Expanded>
</Expression> </Expression>
<OverallResults successes="6" failures="0" expectedFailures="0"/> <OverallResults successes="7" failures="0" expectedFailures="0"/>
</Section> </Section>
<OverallResult success="true"/> <OverallResult success="true"/>
</TestCase> </TestCase>
@ -16207,7 +16239,7 @@ loose text artifact
</Section> </Section>
<OverallResult success="true"/> <OverallResult success="true"/>
</TestCase> </TestCase>
<OverallResults successes="1543" failures="149" expectedFailures="21"/> <OverallResults successes="1547" failures="149" expectedFailures="21"/>
</Group> </Group>
<OverallResults successes="1543" failures="148" expectedFailures="21"/> <OverallResults successes="1547" failures="148" expectedFailures="21"/>
</Catch> </Catch>

View File

@ -288,6 +288,7 @@ namespace { namespace MatchersTests {
} }
SECTION("Contains (vector)") { SECTION("Contains (vector)") {
CHECK_THAT(v, Contains(v2)); CHECK_THAT(v, Contains(v2));
CHECK_THAT(v, Contains<int>({ 1, 2 }));
CHECK_THAT(v5, (Contains<int, std::allocator<int>, CustomAllocator<int>>(v2))); CHECK_THAT(v5, (Contains<int, std::allocator<int>, CustomAllocator<int>>(v2)));
v2.push_back(3); // now exactly matches v2.push_back(3); // now exactly matches
@ -307,10 +308,10 @@ namespace { namespace MatchersTests {
// Same vector // Same vector
CHECK_THAT(v, Equals(v)); CHECK_THAT(v, Equals(v));
CHECK_THAT(empty, Equals(empty)); CHECK_THAT(empty, Equals(empty));
// Different vector with same elements // Different vector with same elements
CHECK_THAT(v, Equals<int>({ 1, 2, 3 }));
v2.push_back(3); v2.push_back(3);
CHECK_THAT(v, Equals(v2)); CHECK_THAT(v, Equals(v2));
@ -321,6 +322,7 @@ namespace { namespace MatchersTests {
} }
SECTION("UnorderedEquals") { SECTION("UnorderedEquals") {
CHECK_THAT(v, UnorderedEquals(v)); CHECK_THAT(v, UnorderedEquals(v));
CHECK_THAT(v, UnorderedEquals<int>({ 3, 2, 1 }));
CHECK_THAT(empty, UnorderedEquals(empty)); CHECK_THAT(empty, UnorderedEquals(empty));
auto permuted = v; auto permuted = v;
@ -580,6 +582,7 @@ namespace { namespace MatchersTests {
std::vector<double> v1({1., 2., 3.}); std::vector<double> v1({1., 2., 3.});
SECTION("A vector is approx equal to itself") { SECTION("A vector is approx equal to itself") {
REQUIRE_THAT(v1, Approx(v1)); REQUIRE_THAT(v1, Approx(v1));
REQUIRE_THAT(v1, Approx<double>({ 1., 2., 3. }));
} }
std::vector<double> v2({1.5, 2.5, 3.5}); std::vector<double> v2({1.5, 2.5, 3.5});
SECTION("Different length") { SECTION("Different length") {