Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
authorMartin Hořeňovský2020-03-09 11:13:07 +0100
committerMartin Hořeňovský2020-03-27 10:24:08 +0100
commit3a3efebd163f19dc8b9d8bbed4ab5309fc752867 (patch)
treeffc252431075ae2357b53d75caf2b27f96d03fbb /tests
parentf52a58e857967124bedf5370b5b03f799c1db0b2 (diff)
downloadcatch3-3a3efebd163f19dc8b9d8bbed4ab5309fc752867.tar.gz
Add IsEmpty and SizeIs matchers for ranges/containers
`SizeIs` can accept both `size_t` and a matcher. In the first case, it checks whether the size of the range is equal to specified size. In the second case, it checks whether the provided matcher accepts the size of the range.
Diffstat (limited to 'tests')
-rw-r--r--tests/SelfTest/Baselines/automake.sw.approved.txt2
-rw-r--r--tests/SelfTest/Baselines/compact.sw.approved.txt17
-rw-r--r--tests/SelfTest/Baselines/console.std.approved.txt4
-rw-r--r--tests/SelfTest/Baselines/console.sw.approved.txt131
-rw-r--r--tests/SelfTest/Baselines/junit.sw.approved.txt8
-rw-r--r--tests/SelfTest/Baselines/sonarqube.sw.approved.txt6
-rw-r--r--tests/SelfTest/Baselines/tap.sw.approved.txt36
-rw-r--r--tests/SelfTest/Baselines/teamcity.sw.approved.txt4
-rw-r--r--tests/SelfTest/Baselines/xml.sw.approved.txt164
-rw-r--r--tests/SelfTest/UsageTests/MatchersRanges.tests.cpp112
10 files changed, 476 insertions, 8 deletions
diff --git a/tests/SelfTest/Baselines/automake.sw.approved.txt b/tests/SelfTest/Baselines/automake.sw.approved.txt
index aee52e51..e67937c7 100644
--- a/tests/SelfTest/Baselines/automake.sw.approved.txt
+++ b/tests/SelfTest/Baselines/automake.sw.approved.txt
@@ -81,6 +81,7 @@ Nor would this
:test-result: PASS Arbitrary predicate matcher
:test-result: PASS Assertions then sections
:test-result: PASS Basic use of the Contains range matcher
+:test-result: PASS Basic use of the Empty range matcher
:test-result: PASS CAPTURE can deal with complex expressions
:test-result: PASS CAPTURE can deal with complex expressions involving commas
:test-result: PASS CAPTURE parses string and character constants
@@ -218,6 +219,7 @@ Message from section two
:test-result: PASS Tracker
:test-result: PASS Trim strings
:test-result: FAIL Unexpected exceptions can be translated
+:test-result: PASS Usage of the SizeIs range matcher
:test-result: PASS Use a custom approx
:test-result: PASS Variadic macros
:test-result: PASS Vector Approx matcher
diff --git a/tests/SelfTest/Baselines/compact.sw.approved.txt b/tests/SelfTest/Baselines/compact.sw.approved.txt
index 74bf50b7..8ae9d726 100644
--- a/tests/SelfTest/Baselines/compact.sw.approved.txt
+++ b/tests/SelfTest/Baselines/compact.sw.approved.txt
@@ -256,6 +256,14 @@ MatchersRanges.tests.cpp:<line number>: passed: in, !Contains(8) for: { 1, 2, 3,
MatchersRanges.tests.cpp:<line number>: passed: in, Contains(MoveOnlyTestElement{ 2 }) for: { 1, 2, 3 } contains element 2
MatchersRanges.tests.cpp:<line number>: passed: in, !Contains(MoveOnlyTestElement{ 9 }) for: { 1, 2, 3 } not contains element 9
MatchersRanges.tests.cpp:<line number>: passed: in, Contains(Catch::Matchers::WithinAbs(0.5, 0.5)) for: { 1.0, 2.0, 3.0, 0.0 } contains element matching is within 0.5 of 0.5
+MatchersRanges.tests.cpp:<line number>: passed: empty_array, IsEmpty() for: { } is empty
+MatchersRanges.tests.cpp:<line number>: passed: non_empty_array, !IsEmpty() for: { 0.0 } not is empty
+MatchersRanges.tests.cpp:<line number>: passed: empty_vec, IsEmpty() for: { } is empty
+MatchersRanges.tests.cpp:<line number>: passed: non_empty_vec, !IsEmpty() for: { 'a', 'b', 'c' } not is empty
+MatchersRanges.tests.cpp:<line number>: passed: inner_lists_are_empty, !IsEmpty() for: { { } } not is empty
+MatchersRanges.tests.cpp:<line number>: passed: inner_lists_are_empty.front(), IsEmpty() for: { } is empty
+MatchersRanges.tests.cpp:<line number>: passed: has_empty{}, !IsEmpty() for: {?} not is empty
+MatchersRanges.tests.cpp:<line number>: passed: unrelated::ADL_empty{}, IsEmpty() for: {?} is empty
Message.tests.cpp:<line number>: passed: with 7 messages: 'a := 1' and 'b := 2' and 'c := 3' and 'a + b := 3' and 'a+b := 3' and 'c > b := true' and 'a == 1 := true'
Message.tests.cpp:<line number>: passed: with 7 messages: 'std::vector<int>{1, 2, 3}[0, 1, 2] := 3' and 'std::vector<int>{1, 2, 3}[(0, 1)] := 2' and 'std::vector<int>{1, 2, 3}[0] := 1' and '(helper_1436<int, int>{12, -12}) := { 12, -12 }' and '(helper_1436<int, int>(-12, 12)) := { -12, 12 }' and '(1, 2) := 2' and '(2, 3) := 3'
Message.tests.cpp:<line number>: passed: with 11 messages: '("comma, in string", "escaped, \", ") := "escaped, ", "' and '"single quote in string,'," := "single quote in string,',"' and '"some escapes, \\,\\\\" := "some escapes, \,\\"' and '"some, ), unmatched, } prenheses {[<" := "some, ), unmatched, } prenheses {[<"' and ''"' := '"'' and ''\'' := '''' and '',' := ','' and ''}' := '}'' and '')' := ')'' and ''(' := '('' and ''{' := '{''
@@ -1563,6 +1571,15 @@ StringManip.tests.cpp:<line number>: passed: trim(StringRef(whitespace_at_both_e
==
There is no extra whitespace here
Exception.tests.cpp:<line number>: failed: unexpected exception with message: '3.14'
+MatchersRanges.tests.cpp:<line number>: passed: empty_vec, SizeIs(0) for: { } has size == 0
+MatchersRanges.tests.cpp:<line number>: passed: empty_vec, !SizeIs(2) for: { } not has size == 2
+MatchersRanges.tests.cpp:<line number>: passed: empty_vec, SizeIs(Lt(2)) for: { } size matches is less than 2
+MatchersRanges.tests.cpp:<line number>: passed: arr, SizeIs(2) for: { 0, 0 } has size == 2
+MatchersRanges.tests.cpp:<line number>: passed: arr, SizeIs( Lt(3)) for: { 0, 0 } size matches is less than 3
+MatchersRanges.tests.cpp:<line number>: passed: arr, !SizeIs(!Lt(3)) for: { 0, 0 } not size matches not is less than 3
+MatchersRanges.tests.cpp:<line number>: passed: map, SizeIs(3) for: { {?}, {?}, {?} } has size == 3
+MatchersRanges.tests.cpp:<line number>: passed: unrelated::ADL_size{}, SizeIs(12) for: {?} has size == 12
+MatchersRanges.tests.cpp:<line number>: passed: has_size{}, SizeIs(13) for: {?} has size == 13
Approx.tests.cpp:<line number>: passed: d == approx( 1.23 ) for: 1.23 == Approx( 1.23 )
Approx.tests.cpp:<line number>: passed: d == approx( 1.22 ) for: 1.23 == Approx( 1.22 )
Approx.tests.cpp:<line number>: passed: d == approx( 1.24 ) for: 1.23 == Approx( 1.24 )
diff --git a/tests/SelfTest/Baselines/console.std.approved.txt b/tests/SelfTest/Baselines/console.std.approved.txt
index 339d9b0d..ab80cb77 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: 329 | 255 passed | 70 failed | 4 failed as expected
-assertions: 1851 | 1699 passed | 131 failed | 21 failed as expected
+test cases: 331 | 257 passed | 70 failed | 4 failed as expected
+assertions: 1868 | 1716 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 ad53af5d..0df71623 100644
--- a/tests/SelfTest/Baselines/console.sw.approved.txt
+++ b/tests/SelfTest/Baselines/console.sw.approved.txt
@@ -2051,6 +2051,67 @@ with expansion:
{ 1.0, 2.0, 3.0, 0.0 } contains element matching is within 0.5 of 0.5
-------------------------------------------------------------------------------
+Basic use of the Empty range matcher
+ Simple, std-provided containers
+-------------------------------------------------------------------------------
+MatchersRanges.tests.cpp:<line number>
+...............................................................................
+
+MatchersRanges.tests.cpp:<line number>: PASSED:
+ REQUIRE_THAT( empty_array, IsEmpty() )
+with expansion:
+ { } is empty
+
+MatchersRanges.tests.cpp:<line number>: PASSED:
+ REQUIRE_THAT( non_empty_array, !IsEmpty() )
+with expansion:
+ { 0.0 } not is empty
+
+MatchersRanges.tests.cpp:<line number>: PASSED:
+ REQUIRE_THAT( empty_vec, IsEmpty() )
+with expansion:
+ { } is empty
+
+MatchersRanges.tests.cpp:<line number>: PASSED:
+ REQUIRE_THAT( non_empty_vec, !IsEmpty() )
+with expansion:
+ { 'a', 'b', 'c' } not is empty
+
+MatchersRanges.tests.cpp:<line number>: PASSED:
+ REQUIRE_THAT( inner_lists_are_empty, !IsEmpty() )
+with expansion:
+ { { } } not is empty
+
+MatchersRanges.tests.cpp:<line number>: PASSED:
+ REQUIRE_THAT( inner_lists_are_empty.front(), IsEmpty() )
+with expansion:
+ { } is empty
+
+-------------------------------------------------------------------------------
+Basic use of the Empty range matcher
+ Type with empty
+-------------------------------------------------------------------------------
+MatchersRanges.tests.cpp:<line number>
+...............................................................................
+
+MatchersRanges.tests.cpp:<line number>: PASSED:
+ REQUIRE_THAT( has_empty{}, !IsEmpty() )
+with expansion:
+ {?} not is empty
+
+-------------------------------------------------------------------------------
+Basic use of the Empty range matcher
+ Type requires ADL found empty free function
+-------------------------------------------------------------------------------
+MatchersRanges.tests.cpp:<line number>
+...............................................................................
+
+MatchersRanges.tests.cpp:<line number>: PASSED:
+ REQUIRE_THAT( unrelated::ADL_empty{}, IsEmpty() )
+with expansion:
+ {?} is empty
+
+-------------------------------------------------------------------------------
CAPTURE can deal with complex expressions
-------------------------------------------------------------------------------
Message.tests.cpp:<line number>
@@ -11380,6 +11441,72 @@ due to unexpected exception with message:
3.14
-------------------------------------------------------------------------------
+Usage of the SizeIs range matcher
+ Some with stdlib containers
+-------------------------------------------------------------------------------
+MatchersRanges.tests.cpp:<line number>
+...............................................................................
+
+MatchersRanges.tests.cpp:<line number>: PASSED:
+ REQUIRE_THAT( empty_vec, SizeIs(0) )
+with expansion:
+ { } has size == 0
+
+MatchersRanges.tests.cpp:<line number>: PASSED:
+ REQUIRE_THAT( empty_vec, !SizeIs(2) )
+with expansion:
+ { } not has size == 2
+
+MatchersRanges.tests.cpp:<line number>: PASSED:
+ REQUIRE_THAT( empty_vec, SizeIs(Lt(2)) )
+with expansion:
+ { } size matches is less than 2
+
+MatchersRanges.tests.cpp:<line number>: PASSED:
+ REQUIRE_THAT( arr, SizeIs(2) )
+with expansion:
+ { 0, 0 } has size == 2
+
+MatchersRanges.tests.cpp:<line number>: PASSED:
+ REQUIRE_THAT( arr, SizeIs( Lt(3)) )
+with expansion:
+ { 0, 0 } size matches is less than 3
+
+MatchersRanges.tests.cpp:<line number>: PASSED:
+ REQUIRE_THAT( arr, !SizeIs(!Lt(3)) )
+with expansion:
+ { 0, 0 } not size matches not is less than 3
+
+MatchersRanges.tests.cpp:<line number>: PASSED:
+ REQUIRE_THAT( map, SizeIs(3) )
+with expansion:
+ { {?}, {?}, {?} } has size == 3
+
+-------------------------------------------------------------------------------
+Usage of the SizeIs range matcher
+ Type requires ADL found size free function
+-------------------------------------------------------------------------------
+MatchersRanges.tests.cpp:<line number>
+...............................................................................
+
+MatchersRanges.tests.cpp:<line number>: PASSED:
+ REQUIRE_THAT( unrelated::ADL_size{}, SizeIs(12) )
+with expansion:
+ {?} has size == 12
+
+-------------------------------------------------------------------------------
+Usage of the SizeIs range matcher
+ Type has size member
+-------------------------------------------------------------------------------
+MatchersRanges.tests.cpp:<line number>
+...............................................................................
+
+MatchersRanges.tests.cpp:<line number>: PASSED:
+ REQUIRE_THAT( has_size{}, SizeIs(13) )
+with expansion:
+ {?} has size == 13
+
+-------------------------------------------------------------------------------
Use a custom approx
-------------------------------------------------------------------------------
Approx.tests.cpp:<line number>
@@ -14498,6 +14625,6 @@ Misc.tests.cpp:<line number>
Misc.tests.cpp:<line number>: PASSED:
===============================================================================
-test cases: 329 | 239 passed | 86 failed | 4 failed as expected
-assertions: 1868 | 1699 passed | 148 failed | 21 failed as expected
+test cases: 331 | 241 passed | 86 failed | 4 failed as expected
+assertions: 1885 | 1716 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 c1dedc83..08e14692 100644
--- a/tests/SelfTest/Baselines/junit.sw.approved.txt
+++ b/tests/SelfTest/Baselines/junit.sw.approved.txt
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuitesloose text artifact
>
- <testsuite name="<exe-name>" errors="17" failures="132" tests="1869" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
+ <testsuite name="<exe-name>" errors="17" failures="132" tests="1886" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
<properties>
<property name="filters" value="~[!nonportable]~[!benchmark]~[approvals] *"/>
<property name="random-seed" value="1"/>
@@ -348,6 +348,9 @@ Exception.tests.cpp:<line number>
<testcase classname="<exe-name>.global" name="Basic use of the Contains range matcher/Can handle type that requires ADL-found free function begin and end" time="{duration}"/>
<testcase classname="<exe-name>.global" name="Basic use of the Contains range matcher/Initialization with move only types" time="{duration}"/>
<testcase classname="<exe-name>.global" name="Basic use of the Contains range matcher/Matching using matcher" time="{duration}"/>
+ <testcase classname="<exe-name>.global" name="Basic use of the Empty range matcher/Simple, std-provided containers" time="{duration}"/>
+ <testcase classname="<exe-name>.global" name="Basic use of the Empty range matcher/Type with empty" time="{duration}"/>
+ <testcase classname="<exe-name>.global" name="Basic use of the Empty range matcher/Type requires ADL found empty free function" time="{duration}"/>
<testcase classname="<exe-name>.global" name="CAPTURE can deal with complex expressions" time="{duration}"/>
<testcase classname="<exe-name>.global" name="CAPTURE can deal with complex expressions involving commas" time="{duration}"/>
<testcase classname="<exe-name>.global" name="CAPTURE parses string and character constants" time="{duration}"/>
@@ -1249,6 +1252,9 @@ FAILED:
Exception.tests.cpp:<line number>
</error>
</testcase>
+ <testcase classname="<exe-name>.global" name="Usage of the SizeIs range matcher/Some with stdlib containers" time="{duration}"/>
+ <testcase classname="<exe-name>.global" name="Usage of the SizeIs range matcher/Type requires ADL found size free function" time="{duration}"/>
+ <testcase classname="<exe-name>.global" name="Usage of the SizeIs range matcher/Type has size member" time="{duration}"/>
<testcase classname="<exe-name>.global" name="Use a custom approx" time="{duration}"/>
<testcase classname="<exe-name>.global" name="Variadic macros/Section with one argument" time="{duration}"/>
<testcase classname="<exe-name>.global" name="Vector Approx matcher/Empty vector is roughly equal to an empty vector" time="{duration}"/>
diff --git a/tests/SelfTest/Baselines/sonarqube.sw.approved.txt b/tests/SelfTest/Baselines/sonarqube.sw.approved.txt
index b89ec533..c50a6876 100644
--- a/tests/SelfTest/Baselines/sonarqube.sw.approved.txt
+++ b/tests/SelfTest/Baselines/sonarqube.sw.approved.txt
@@ -1222,6 +1222,12 @@ Matchers.tests.cpp:<line number>
<testCase name="Basic use of the Contains range matcher/Can handle type that requires ADL-found free function begin and end" duration="{duration}"/>
<testCase name="Basic use of the Contains range matcher/Initialization with move only types" duration="{duration}"/>
<testCase name="Basic use of the Contains range matcher/Matching using matcher" duration="{duration}"/>
+ <testCase name="Basic use of the Empty range matcher/Simple, std-provided containers" duration="{duration}"/>
+ <testCase name="Basic use of the Empty range matcher/Type with empty" duration="{duration}"/>
+ <testCase name="Basic use of the Empty range matcher/Type requires ADL found empty free function" duration="{duration}"/>
+ <testCase name="Usage of the SizeIs range matcher/Some with stdlib containers" duration="{duration}"/>
+ <testCase name="Usage of the SizeIs range matcher/Type requires ADL found size free function" duration="{duration}"/>
+ <testCase name="Usage of the SizeIs range matcher/Type has size member" duration="{duration}"/>
</file>
<file path="tests/<exe-name>/UsageTests/Message.tests.cpp">
<testCase name="#1455 - INFO and WARN can start with a linebreak" duration="{duration}"/>
diff --git a/tests/SelfTest/Baselines/tap.sw.approved.txt b/tests/SelfTest/Baselines/tap.sw.approved.txt
index 61876cff..fc186d97 100644
--- a/tests/SelfTest/Baselines/tap.sw.approved.txt
+++ b/tests/SelfTest/Baselines/tap.sw.approved.txt
@@ -510,6 +510,22 @@ ok {test-number} - in, Contains(MoveOnlyTestElement{ 2 }) for: { 1, 2, 3 } conta
ok {test-number} - in, !Contains(MoveOnlyTestElement{ 9 }) for: { 1, 2, 3 } not contains element 9
# Basic use of the Contains range matcher
ok {test-number} - in, Contains(Catch::Matchers::WithinAbs(0.5, 0.5)) for: { 1.0, 2.0, 3.0, 0.0 } contains element matching is within 0.5 of 0.5
+# Basic use of the Empty range matcher
+ok {test-number} - empty_array, IsEmpty() for: { } is empty
+# Basic use of the Empty range matcher
+ok {test-number} - non_empty_array, !IsEmpty() for: { 0.0 } not is empty
+# Basic use of the Empty range matcher
+ok {test-number} - empty_vec, IsEmpty() for: { } is empty
+# Basic use of the Empty range matcher
+ok {test-number} - non_empty_vec, !IsEmpty() for: { 'a', 'b', 'c' } not is empty
+# Basic use of the Empty range matcher
+ok {test-number} - inner_lists_are_empty, !IsEmpty() for: { { } } not is empty
+# Basic use of the Empty range matcher
+ok {test-number} - inner_lists_are_empty.front(), IsEmpty() for: { } is empty
+# Basic use of the Empty range matcher
+ok {test-number} - has_empty{}, !IsEmpty() for: {?} not is empty
+# Basic use of the Empty range matcher
+ok {test-number} - unrelated::ADL_empty{}, IsEmpty() for: {?} is empty
# CAPTURE can deal with complex expressions
ok {test-number} - with 7 messages: 'a := 1' and 'b := 2' and 'c := 3' and 'a + b := 3' and 'a+b := 3' and 'c > b := true' and 'a == 1 := true'
# CAPTURE can deal with complex expressions involving commas
@@ -2973,6 +2989,24 @@ ok {test-number} - trim(StringRef(trailing_whitespace)) == StringRef(no_whitespa
ok {test-number} - trim(StringRef(whitespace_at_both_ends)) == StringRef(no_whitespace) for: There is no extra whitespace here == There is no extra whitespace here
# Unexpected exceptions can be translated
not ok {test-number} - unexpected exception with message: '3.14'
+# Usage of the SizeIs range matcher
+ok {test-number} - empty_vec, SizeIs(0) for: { } has size == 0
+# Usage of the SizeIs range matcher
+ok {test-number} - empty_vec, !SizeIs(2) for: { } not has size == 2
+# Usage of the SizeIs range matcher
+ok {test-number} - empty_vec, SizeIs(Lt(2)) for: { } size matches is less than 2
+# Usage of the SizeIs range matcher
+ok {test-number} - arr, SizeIs(2) for: { 0, 0 } has size == 2
+# Usage of the SizeIs range matcher
+ok {test-number} - arr, SizeIs( Lt(3)) for: { 0, 0 } size matches is less than 3
+# Usage of the SizeIs range matcher
+ok {test-number} - arr, !SizeIs(!Lt(3)) for: { 0, 0 } not size matches not is less than 3
+# Usage of the SizeIs range matcher
+ok {test-number} - map, SizeIs(3) for: { {?}, {?}, {?} } has size == 3
+# Usage of the SizeIs range matcher
+ok {test-number} - unrelated::ADL_size{}, SizeIs(12) for: {?} has size == 12
+# Usage of the SizeIs range matcher
+ok {test-number} - has_size{}, SizeIs(13) for: {?} has size == 13
# Use a custom approx
ok {test-number} - d == approx( 1.23 ) for: 1.23 == Approx( 1.23 )
# Use a custom approx
@@ -3728,5 +3762,5 @@ ok {test-number} - q3 == 23. for: 23.0 == 23.0
ok {test-number} -
# xmlentitycheck
ok {test-number} -
-1..1860
+1..1877
diff --git a/tests/SelfTest/Baselines/teamcity.sw.approved.txt b/tests/SelfTest/Baselines/teamcity.sw.approved.txt
index b0566b41..a48b4612 100644
--- a/tests/SelfTest/Baselines/teamcity.sw.approved.txt
+++ b/tests/SelfTest/Baselines/teamcity.sw.approved.txt
@@ -195,6 +195,8 @@ Exception.tests.cpp:<line number>|nunexpected exception with message:|n "unexpe
##teamcity[testFinished name='Assertions then sections' duration="{duration}"]
##teamcity[testStarted name='Basic use of the Contains range matcher']
##teamcity[testFinished name='Basic use of the Contains range matcher' duration="{duration}"]
+##teamcity[testStarted name='Basic use of the Empty range matcher']
+##teamcity[testFinished name='Basic use of the Empty range matcher' duration="{duration}"]
##teamcity[testStarted name='CAPTURE can deal with complex expressions']
##teamcity[testFinished name='CAPTURE can deal with complex expressions' duration="{duration}"]
##teamcity[testStarted name='CAPTURE can deal with complex expressions involving commas']
@@ -539,6 +541,8 @@ Exception.tests.cpp:<line number>|nunexpected exception with message:|n "For so
##teamcity[testStarted name='Unexpected exceptions can be translated']
Exception.tests.cpp:<line number>|nunexpected exception with message:|n "3.14"']
##teamcity[testFinished name='Unexpected exceptions can be translated' duration="{duration}"]
+##teamcity[testStarted name='Usage of the SizeIs range matcher']
+##teamcity[testFinished name='Usage of the SizeIs range matcher' duration="{duration}"]
##teamcity[testStarted name='Use a custom approx']
##teamcity[testFinished name='Use a custom approx' duration="{duration}"]
##teamcity[testStarted name='Variadic macros']
diff --git a/tests/SelfTest/Baselines/xml.sw.approved.txt b/tests/SelfTest/Baselines/xml.sw.approved.txt
index 31f16fc0..0a9a0255 100644
--- a/tests/SelfTest/Baselines/xml.sw.approved.txt
+++ b/tests/SelfTest/Baselines/xml.sw.approved.txt
@@ -2295,6 +2295,82 @@ Nor would this
</Section>
<OverallResult success="true"/>
</TestCase>
+ <TestCase name="Basic use of the Empty range matcher" tags="[empty][matchers][templated]" filename="tests/<exe-name>/UsageTests/MatchersRanges.tests.cpp" >
+ <Section name="Simple, std-provided containers" filename="tests/<exe-name>/UsageTests/MatchersRanges.tests.cpp" >
+ <Expression success="true" type="REQUIRE_THAT" filename="tests/<exe-name>/UsageTests/MatchersRanges.tests.cpp" >
+ <Original>
+ empty_array, IsEmpty()
+ </Original>
+ <Expanded>
+ { } is empty
+ </Expanded>
+ </Expression>
+ <Expression success="true" type="REQUIRE_THAT" filename="tests/<exe-name>/UsageTests/MatchersRanges.tests.cpp" >
+ <Original>
+ non_empty_array, !IsEmpty()
+ </Original>
+ <Expanded>
+ { 0.0 } not is empty
+ </Expanded>
+ </Expression>
+ <Expression success="true" type="REQUIRE_THAT" filename="tests/<exe-name>/UsageTests/MatchersRanges.tests.cpp" >
+ <Original>
+ empty_vec, IsEmpty()
+ </Original>
+ <Expanded>
+ { } is empty
+ </Expanded>
+ </Expression>
+ <Expression success="true" type="REQUIRE_THAT" filename="tests/<exe-name>/UsageTests/MatchersRanges.tests.cpp" >
+ <Original>
+ non_empty_vec, !IsEmpty()
+ </Original>
+ <Expanded>
+ { 'a', 'b', 'c' } not is empty
+ </Expanded>
+ </Expression>
+ <Expression success="true" type="REQUIRE_THAT" filename="tests/<exe-name>/UsageTests/MatchersRanges.tests.cpp" >
+ <Original>
+ inner_lists_are_empty, !IsEmpty()
+ </Original>
+ <Expanded>
+ { { } } not is empty
+ </Expanded>
+ </Expression>
+ <Expression success="true" type="REQUIRE_THAT" filename="tests/<exe-name>/UsageTests/MatchersRanges.tests.cpp" >
+ <Original>
+ inner_lists_are_empty.front(), IsEmpty()
+ </Original>
+ <Expanded>
+ { } is empty
+ </Expanded>
+ </Expression>
+ <OverallResults successes="6" failures="0" expectedFailures="0"/>
+ </Section>
+ <Section name="Type with empty" filename="tests/<exe-name>/UsageTests/MatchersRanges.tests.cpp" >
+ <Expression success="true" type="REQUIRE_THAT" filename="tests/<exe-name>/UsageTests/MatchersRanges.tests.cpp" >
+ <Original>
+ has_empty{}, !IsEmpty()
+ </Original>
+ <Expanded>
+ {?} not is empty
+ </Expanded>
+ </Expression>
+ <OverallResults successes="1" failures="0" expectedFailures="0"/>
+ </Section>
+ <Section name="Type requires ADL found empty free function" filename="tests/<exe-name>/UsageTests/MatchersRanges.tests.cpp" >
+ <Expression success="true" type="REQUIRE_THAT" filename="tests/<exe-name>/UsageTests/MatchersRanges.tests.cpp" >
+ <Original>
+ unrelated::ADL_empty{}, IsEmpty()
+ </Original>
+ <Expanded>
+ {?} is empty
+ </Expanded>
+ </Expression>
+ <OverallResults successes="1" failures="0" expectedFailures="0"/>
+ </Section>
+ <OverallResult success="true"/>
+ </TestCase>
<TestCase name="CAPTURE can deal with complex expressions" tags="[capture][messages]" filename="tests/<exe-name>/UsageTests/Message.tests.cpp" >
<Info>
a := 1
@@ -13749,6 +13825,90 @@ There is no extra whitespace here
</Exception>
<OverallResult success="false"/>
</TestCase>
+ <TestCase name="Usage of the SizeIs range matcher" tags="[matchers][size][templated]" filename="tests/<exe-name>/UsageTests/MatchersRanges.tests.cpp" >
+ <Section name="Some with stdlib containers" filename="tests/<exe-name>/UsageTests/MatchersRanges.tests.cpp" >
+ <Expression success="true" type="REQUIRE_THAT" filename="tests/<exe-name>/UsageTests/MatchersRanges.tests.cpp" >
+ <Original>
+ empty_vec, SizeIs(0)
+ </Original>
+ <Expanded>
+ { } has size == 0
+ </Expanded>
+ </Expression>
+ <Expression success="true" type="REQUIRE_THAT" filename="tests/<exe-name>/UsageTests/MatchersRanges.tests.cpp" >
+ <Original>
+ empty_vec, !SizeIs(2)
+ </Original>
+ <Expanded>
+ { } not has size == 2
+ </Expanded>
+ </Expression>
+ <Expression success="true" type="REQUIRE_THAT" filename="tests/<exe-name>/UsageTests/MatchersRanges.tests.cpp" >
+ <Original>
+ empty_vec, SizeIs(Lt(2))
+ </Original>
+ <Expanded>
+ { } size matches is less than 2
+ </Expanded>
+ </Expression>
+ <Expression success="true" type="REQUIRE_THAT" filename="tests/<exe-name>/UsageTests/MatchersRanges.tests.cpp" >
+ <Original>
+ arr, SizeIs(2)
+ </Original>
+ <Expanded>
+ { 0, 0 } has size == 2
+ </Expanded>
+ </Expression>
+ <Expression success="true" type="REQUIRE_THAT" filename="tests/<exe-name>/UsageTests/MatchersRanges.tests.cpp" >
+ <Original>
+ arr, SizeIs( Lt(3))
+ </Original>
+ <Expanded>
+ { 0, 0 } size matches is less than 3
+ </Expanded>
+ </Expression>
+ <Expression success="true" type="REQUIRE_THAT" filename="tests/<exe-name>/UsageTests/MatchersRanges.tests.cpp" >
+ <Original>
+ arr, !SizeIs(!Lt(3))
+ </Original>
+ <Expanded>
+ { 0, 0 } not size matches not is less than 3
+ </Expanded>
+ </Expression>
+ <Expression success="true" type="REQUIRE_THAT" filename="tests/<exe-name>/UsageTests/MatchersRanges.tests.cpp" >
+ <Original>
+ map, SizeIs(3)
+ </Original>
+ <Expanded>
+ { {?}, {?}, {?} } has size == 3
+ </Expanded>
+ </Expression>
+ <OverallResults successes="7" failures="0" expectedFailures="0"/>
+ </Section>
+ <Section name="Type requires ADL found size free function" filename="tests/<exe-name>/UsageTests/MatchersRanges.tests.cpp" >
+ <Expression success="true" type="REQUIRE_THAT" filename="tests/<exe-name>/UsageTests/MatchersRanges.tests.cpp" >
+ <Original>
+ unrelated::ADL_size{}, SizeIs(12)
+ </Original>
+ <Expanded>
+ {?} has size == 12
+ </Expanded>
+ </Expression>
+ <OverallResults successes="1" failures="0" expectedFailures="0"/>
+ </Section>
+ <Section name="Type has size member" filename="tests/<exe-name>/UsageTests/MatchersRanges.tests.cpp" >
+ <Expression success="true" type="REQUIRE_THAT" filename="tests/<exe-name>/UsageTests/MatchersRanges.tests.cpp" >
+ <Original>
+ has_size{}, SizeIs(13)
+ </Original>
+ <Expanded>
+ {?} has size == 13
+ </Expanded>
+ </Expression>
+ <OverallResults successes="1" failures="0" expectedFailures="0"/>
+ </Section>
+ <OverallResult success="true"/>
+ </TestCase>
<TestCase name="Use a custom approx" tags="[Approx][custom]" filename="tests/<exe-name>/UsageTests/Approx.tests.cpp" >
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/UsageTests/Approx.tests.cpp" >
<Original>
@@ -17381,7 +17541,7 @@ loose text artifact
</Section>
<OverallResult success="true"/>
</TestCase>
- <OverallResults successes="1699" failures="149" expectedFailures="21"/>
+ <OverallResults successes="1716" failures="149" expectedFailures="21"/>
</Group>
- <OverallResults successes="1699" failures="148" expectedFailures="21"/>
+ <OverallResults successes="1716" failures="148" expectedFailures="21"/>
</Catch>
diff --git a/tests/SelfTest/UsageTests/MatchersRanges.tests.cpp b/tests/SelfTest/UsageTests/MatchersRanges.tests.cpp
index 7cf5590b..d958ac86 100644
--- a/tests/SelfTest/UsageTests/MatchersRanges.tests.cpp
+++ b/tests/SelfTest/UsageTests/MatchersRanges.tests.cpp
@@ -2,14 +2,17 @@
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#include <catch2/catch_test_macros.hpp>
+#include <catch2/matchers/catch_matchers_container_properties.hpp>
#include <catch2/matchers/catch_matchers_contains.hpp>
#include <catch2/matchers/catch_matchers_floating.hpp>
#include <array>
#include <cmath>
#include <list>
+#include <map>
#include <vector>
+namespace {
namespace unrelated {
class needs_ADL_begin {
std::array<int, 5> elements{ {1, 2, 3, 4, 5} };
@@ -27,6 +30,7 @@ namespace unrelated {
return rhs.End();
}
};
+} // end unrelated namespace
} // end anon namespace
struct MoveOnlyTestElement {
@@ -105,3 +109,111 @@ TEST_CASE("Basic use of the Contains range matcher", "[matchers][templated][cont
REQUIRE_THAT(in, Contains(Catch::Matchers::WithinAbs(0.5, 0.5)));
}
}
+
+namespace {
+
+ struct has_empty {
+ bool empty() const { return false; }
+ };
+
+namespace unrelated {
+ struct ADL_empty {
+ bool Empty() const { return true; }
+
+ friend bool empty(ADL_empty e) {
+ return e.Empty();
+ }
+ };
+
+} // end namespace unrelated
+} // end unnamed namespace
+
+TEST_CASE("Basic use of the Empty range matcher", "[matchers][templated][empty]") {
+ using Catch::Matchers::IsEmpty;
+ SECTION("Simple, std-provided containers") {
+ std::array<int, 0> empty_array{};
+ std::array<double, 1> non_empty_array{};
+ REQUIRE_THAT(empty_array, IsEmpty());
+ REQUIRE_THAT(non_empty_array, !IsEmpty());
+
+ std::vector<std::string> empty_vec;
+ std::vector<char> non_empty_vec{ 'a', 'b', 'c' };
+ REQUIRE_THAT(empty_vec, IsEmpty());
+ REQUIRE_THAT(non_empty_vec, !IsEmpty());
+
+ std::list<std::list<std::list<int>>> inner_lists_are_empty;
+ inner_lists_are_empty.push_back({});
+ REQUIRE_THAT(inner_lists_are_empty, !IsEmpty());
+ REQUIRE_THAT(inner_lists_are_empty.front(), IsEmpty());
+ }
+ SECTION("Type with empty") {
+ REQUIRE_THAT(has_empty{}, !IsEmpty());
+ }
+ SECTION("Type requires ADL found empty free function") {
+ REQUIRE_THAT(unrelated::ADL_empty{}, IsEmpty());
+ }
+}
+
+namespace {
+ class LessThanMatcher final : public Catch::Matchers::MatcherBase<size_t> {
+ size_t m_target;
+ public:
+ explicit LessThanMatcher(size_t target):
+ m_target(target)
+ {}