diff options
| author | Phil Nash | 2017-02-21 14:19:09 +0000 |
|---|---|---|
| committer | Phil Nash | 2017-02-21 14:19:09 +0000 |
| commit | 4e6938d78e375d9bc3481d7baccb0f84341a4010 (patch) | |
| tree | 48ed622082326e13d1c01729bd82fc6cd147c28e /projects | |
| parent | 1ca8cefa9afa94f8323a9b7c2e67b16894c32fdd (diff) | |
| download | catch3-4e6938d78e375d9bc3481d7baccb0f84341a4010.tar.gz | |
Moved matchers tests into their own file
Diffstat (limited to 'projects')
| -rw-r--r-- | projects/SelfTest/Baselines/console.std.approved.txt | 24 | ||||
| -rw-r--r-- | projects/SelfTest/Baselines/console.sw.approved.txt | 66 | ||||
| -rw-r--r-- | projects/SelfTest/Baselines/junit.sw.approved.txt | 12 | ||||
| -rw-r--r-- | projects/SelfTest/Baselines/xml.sw.approved.txt | 66 | ||||
| -rw-r--r-- | projects/SelfTest/MatchersTests.cpp | 99 | ||||
| -rw-r--r-- | projects/SelfTest/MiscTests.cpp | 91 |
6 files changed, 183 insertions, 175 deletions
diff --git a/projects/SelfTest/Baselines/console.std.approved.txt b/projects/SelfTest/Baselines/console.std.approved.txt index ab0a83de..9c5ea971 100644 --- a/projects/SelfTest/Baselines/console.std.approved.txt +++ b/projects/SelfTest/Baselines/console.std.approved.txt @@ -105,10 +105,10 @@ due to unexpected exception with message: ------------------------------------------------------------------------------- Contains string matcher ------------------------------------------------------------------------------- -MiscTests.cpp:<line number> +MatchersTests.cpp:<line number> ............................................................................... -MiscTests.cpp:<line number>: FAILED: +MatchersTests.cpp:<line number>: FAILED: CHECK_THAT( testStringForMatching(), Contains( "not there" ) ) with expansion: "this string contains 'abc' as a substring" contains: "not there" @@ -148,10 +148,10 @@ due to unexpected exception with message: ------------------------------------------------------------------------------- EndsWith string matcher ------------------------------------------------------------------------------- -MiscTests.cpp:<line number> +MatchersTests.cpp:<line number> ............................................................................... -MiscTests.cpp:<line number>: FAILED: +MatchersTests.cpp:<line number>: FAILED: CHECK_THAT( testStringForMatching(), EndsWith( "this" ) ) with expansion: "this string contains 'abc' as a substring" ends with: "this" @@ -230,10 +230,10 @@ with expansion: ------------------------------------------------------------------------------- Equals string matcher ------------------------------------------------------------------------------- -MiscTests.cpp:<line number> +MatchersTests.cpp:<line number> ............................................................................... -MiscTests.cpp:<line number>: FAILED: +MatchersTests.cpp:<line number>: FAILED: CHECK_THAT( testStringForMatching(), Equals( "something else" ) ) with expansion: "this string contains 'abc' as a substring" equals: "something else" @@ -355,10 +355,10 @@ with expansion: ------------------------------------------------------------------------------- Matchers can be composed with both && and || - failing ------------------------------------------------------------------------------- -MiscTests.cpp:<line number> +MatchersTests.cpp:<line number> ............................................................................... -MiscTests.cpp:<line number>: FAILED: +MatchersTests.cpp:<line number>: FAILED: CHECK_THAT( testStringForMatching(), ( Contains( "string" ) || Contains( "different" ) ) && Contains( "random" ) ) with expansion: "this string contains 'abc' as a substring" ( ( contains: "string" or @@ -367,10 +367,10 @@ with expansion: ------------------------------------------------------------------------------- Matchers can be negated (Not) with the ! operator - failing ------------------------------------------------------------------------------- -MiscTests.cpp:<line number> +MatchersTests.cpp:<line number> ............................................................................... -MiscTests.cpp:<line number>: FAILED: +MatchersTests.cpp:<line number>: FAILED: CHECK_THAT( testStringForMatching(), !Contains( "substring" ) ) with expansion: "this string contains 'abc' as a substring" not contains: "substring" @@ -564,10 +564,10 @@ Message from section two ------------------------------------------------------------------------------- StartsWith string matcher ------------------------------------------------------------------------------- -MiscTests.cpp:<line number> +MatchersTests.cpp:<line number> ............................................................................... -MiscTests.cpp:<line number>: FAILED: +MatchersTests.cpp:<line number>: FAILED: CHECK_THAT( testStringForMatching(), StartsWith( "string" ) ) with expansion: "this string contains 'abc' as a substring" starts with: "string" diff --git a/projects/SelfTest/Baselines/console.sw.approved.txt b/projects/SelfTest/Baselines/console.sw.approved.txt index 5aff4b8c..eb58e3a0 100644 --- a/projects/SelfTest/Baselines/console.sw.approved.txt +++ b/projects/SelfTest/Baselines/console.sw.approved.txt @@ -307,10 +307,10 @@ with expansion: ------------------------------------------------------------------------------- AllOf matcher ------------------------------------------------------------------------------- -MiscTests.cpp:<line number> +MatchersTests.cpp:<line number> ............................................................................... -MiscTests.cpp:<line number>: +MatchersTests.cpp:<line number>: PASSED: CHECK_THAT( testStringForMatching(), AllOf( Catch::Contains( "string" ), Catch::Contains( "abc" ) ) ) with expansion: @@ -364,17 +364,17 @@ with message: ------------------------------------------------------------------------------- AnyOf matcher ------------------------------------------------------------------------------- -MiscTests.cpp:<line number> +MatchersTests.cpp:<line number> ............................................................................... -MiscTests.cpp:<line number>: +MatchersTests.cpp:<line number>: PASSED: CHECK_THAT( testStringForMatching(), AnyOf( Catch::Contains( "string" ), Catch::Contains( "not there" ) ) ) with expansion: "this string contains 'abc' as a substring" ( contains: "string" or contains: "not there" ) -MiscTests.cpp:<line number>: +MatchersTests.cpp:<line number>: PASSED: CHECK_THAT( testStringForMatching(), AnyOf( Catch::Contains( "not there" ), Catch::Contains( "string" ) ) ) with expansion: @@ -848,10 +848,10 @@ with expansion: ------------------------------------------------------------------------------- Contains string matcher ------------------------------------------------------------------------------- -MiscTests.cpp:<line number> +MatchersTests.cpp:<line number> ............................................................................... -MiscTests.cpp:<line number>: FAILED: +MatchersTests.cpp:<line number>: FAILED: CHECK_THAT( testStringForMatching(), Contains( "not there" ) ) with expansion: "this string contains 'abc' as a substring" contains: "not there" @@ -903,10 +903,10 @@ with expansion: ------------------------------------------------------------------------------- EndsWith string matcher ------------------------------------------------------------------------------- -MiscTests.cpp:<line number> +MatchersTests.cpp:<line number> ............................................................................... -MiscTests.cpp:<line number>: FAILED: +MatchersTests.cpp:<line number>: FAILED: CHECK_THAT( testStringForMatching(), EndsWith( "this" ) ) with expansion: "this string contains 'abc' as a substring" ends with: "this" @@ -1033,10 +1033,10 @@ with expansion: ------------------------------------------------------------------------------- Equals ------------------------------------------------------------------------------- -MiscTests.cpp:<line number> +MatchersTests.cpp:<line number> ............................................................................... -MiscTests.cpp:<line number>: +MatchersTests.cpp:<line number>: PASSED: CHECK_THAT( testStringForMatching(), Equals( "this string contains 'abc' as a substring" ) ) with expansion: @@ -1046,10 +1046,10 @@ with expansion: ------------------------------------------------------------------------------- Equals string matcher ------------------------------------------------------------------------------- -MiscTests.cpp:<line number> +MatchersTests.cpp:<line number> ............................................................................... -MiscTests.cpp:<line number>: FAILED: +MatchersTests.cpp:<line number>: FAILED: CHECK_THAT( testStringForMatching(), Equals( "something else" ) ) with expansion: "this string contains 'abc' as a substring" equals: "something else" @@ -4281,10 +4281,10 @@ with message: ------------------------------------------------------------------------------- Matchers can be (AllOf) composed with the && operator ------------------------------------------------------------------------------- -MiscTests.cpp:<line number> +MatchersTests.cpp:<line number> ............................................................................... -MiscTests.cpp:<line number>: +MatchersTests.cpp:<line number>: PASSED: CHECK_THAT( testStringForMatching(), Contains( "string" ) && Contains( "abc" ) && Contains( "substring" ) && Contains( "contains" ) ) with expansion: @@ -4294,17 +4294,17 @@ with expansion: ------------------------------------------------------------------------------- Matchers can be (AnyOf) composed with the || operator ------------------------------------------------------------------------------- -MiscTests.cpp:<line number> +MatchersTests.cpp:<line number> ............................................................................... -MiscTests.cpp:<line number>: +MatchersTests.cpp:<line number>: PASSED: CHECK_THAT( testStringForMatching(), Contains( "string" ) || Contains( "different" ) || Contains( "random" ) ) with expansion: "this string contains 'abc' as a substring" ( contains: "string" or contains: "different" or contains: "random" ) -MiscTests.cpp:<line number>: +MatchersTests.cpp:<line number>: PASSED: CHECK_THAT( testStringForMatching2(), Contains( "string" ) || Contains( "different" ) || Contains( "random" ) ) with expansion: @@ -4314,10 +4314,10 @@ with expansion: ------------------------------------------------------------------------------- Matchers can be composed with both && and || ------------------------------------------------------------------------------- -MiscTests.cpp:<line number> +MatchersTests.cpp:<line number> ............................................................................... -MiscTests.cpp:<line number>: +MatchersTests.cpp:<line number>: PASSED: CHECK_THAT( testStringForMatching(), ( Contains( "string" ) || Contains( "different" ) ) && Contains( "substring" ) ) with expansion: @@ -4327,10 +4327,10 @@ with expansion: ------------------------------------------------------------------------------- Matchers can be composed with both && and || - failing ------------------------------------------------------------------------------- -MiscTests.cpp:<line number> +MatchersTests.cpp:<line number> ............................................................................... -MiscTests.cpp:<line number>: FAILED: +MatchersTests.cpp:<line number>: FAILED: CHECK_THAT( testStringForMatching(), ( Contains( "string" ) || Contains( "different" ) ) && Contains( "random" ) ) with expansion: "this string contains 'abc' as a substring" ( ( contains: "string" or @@ -4339,10 +4339,10 @@ with expansion: ------------------------------------------------------------------------------- Matchers can be negated (Not) with the ! operator ------------------------------------------------------------------------------- -MiscTests.cpp:<line number> +MatchersTests.cpp:<line number> ............................................................................... -MiscTests.cpp:<line number>: +MatchersTests.cpp:<line number>: PASSED: CHECK_THAT( testStringForMatching(), !Contains( "different" ) ) with expansion: @@ -4351,10 +4351,10 @@ with expansion: ------------------------------------------------------------------------------- Matchers can be negated (Not) with the ! operator - failing ------------------------------------------------------------------------------- -MiscTests.cpp:<line number> +MatchersTests.cpp:<line number> ............................................................................... -MiscTests.cpp:<line number>: FAILED: +MatchersTests.cpp:<line number>: FAILED: CHECK_THAT( testStringForMatching(), !Contains( "substring" ) ) with expansion: "this string contains 'abc' as a substring" not contains: "substring" @@ -6620,10 +6620,10 @@ No assertions in section 'two' ------------------------------------------------------------------------------- StartsWith string matcher ------------------------------------------------------------------------------- -MiscTests.cpp:<line number> +MatchersTests.cpp:<line number> ............................................................................... -MiscTests.cpp:<line number>: FAILED: +MatchersTests.cpp:<line number>: FAILED: CHECK_THAT( testStringForMatching(), StartsWith( "string" ) ) with expansion: "this string contains 'abc' as a substring" starts with: "string" @@ -6631,28 +6631,28 @@ with expansion: ------------------------------------------------------------------------------- String matchers ------------------------------------------------------------------------------- -MiscTests.cpp:<line number> +MatchersTests.cpp:<line number> ............................................................................... -MiscTests.cpp:<line number>: +MatchersTests.cpp:<line number>: PASSED: REQUIRE_THAT( testStringForMatching(), Contains( "string" ) ) with expansion: "this string contains 'abc' as a substring" contains: "string" -MiscTests.cpp:<line number>: +MatchersTests.cpp:<line number>: PASSED: CHECK_THAT( testStringForMatching(), Contains( "abc" ) ) with expansion: "this string contains 'abc' as a substring" contains: "abc" -MiscTests.cpp:<line number>: +MatchersTests.cpp:<line number>: PASSED: CHECK_THAT( testStringForMatching(), StartsWith( "this" ) ) with expansion: "this string contains 'abc' as a substring" starts with: "this" -MiscTests.cpp:<line number>: +MatchersTests.cpp:<line number>: PASSED: CHECK_THAT( testStringForMatching(), EndsWith( "substring" ) ) with expansion: diff --git a/projects/SelfTest/Baselines/junit.sw.approved.txt b/projects/SelfTest/Baselines/junit.sw.approved.txt index c619c366..6b9ab73b 100644 --- a/projects/SelfTest/Baselines/junit.sw.approved.txt +++ b/projects/SelfTest/Baselines/junit.sw.approved.txt @@ -92,7 +92,7 @@ ExceptionTests.cpp:<line number> <testcase classname="global" name="Comparisons with int literals don't warn when mixing signed/ unsigned" time="{duration}"/> <testcase classname="global" name="Contains string matcher" time="{duration}"> <failure message=""this string contains 'abc' as a substring" contains: "not there"" type="CHECK_THAT"> -MiscTests.cpp:<line number> +MatchersTests.cpp:<line number> </failure> </testcase> <testcase classname="global" name="Custom exceptions can be translated when testing for nothrow" time="{duration}"> @@ -116,7 +116,7 @@ ExceptionTests.cpp:<line number> <testcase classname="global" name="Demonstrate that a non-const == is not used" time="{duration}"/> <testcase classname="global" name="EndsWith string matcher" time="{duration}"> <failure message=""this string contains 'abc' as a substring" ends with: "this"" type="CHECK_THAT"> -MiscTests.cpp:<line number> +MatchersTests.cpp:<line number> </failure> </testcase> <testcase classname="global" name="Equality checks that should fail" time="{duration}"> @@ -164,7 +164,7 @@ ConditionTests.cpp:<line number> <testcase classname="global" name="Equals" time="{duration}"/> <testcase classname="global" name="Equals string matcher" time="{duration}"> <failure message=""this string contains 'abc' as a substring" equals: "something else"" type="CHECK_THAT"> -MiscTests.cpp:<line number> +MatchersTests.cpp:<line number> </failure> </testcase> <testcase classname="Exception messages can be tested for" name="exact match" time="{duration}"/> @@ -256,13 +256,13 @@ ConditionTests.cpp:<line number> <testcase classname="global" name="Matchers can be composed with both && and ||" time="{duration}"/> <testcase classname="global" name="Matchers can be composed with both && and || - failing" time="{duration}"> <failure message=""this string contains 'abc' as a substring" ( ( contains: "string" or contains: "different" ) and contains: "random" )" type="CHECK_THAT"> -MiscTests.cpp:<line number> +MatchersTests.cpp:<line number> </failure> </testcase> <testcase classname="global" name="Matchers can be negated (Not) with the ! operator" time="{duration}"/> <testcase classname="global" name="Matchers can be negated (Not) with the ! operator - failing" time="{duration}"> <failure message=""this string contains 'abc' as a substring" not contains: "substring"" type="CHECK_THAT"> -MiscTests.cpp:<line number> +MatchersTests.cpp:<line number> </failure> </testcase> <testcase classname="global" name="Mismatching exception messages failing the test" time="{duration}"> @@ -445,7 +445,7 @@ Message from section two </testcase> <testcase classname="global" name="StartsWith string matcher" time="{duration}"> <failure message=""this string contains 'abc' as a substring" starts with: "string"" type="CHECK_THAT"> -MiscTests.cpp:<line number> +MatchersTests.cpp:<line number> </failure> </testcase> <testcase classname="global" name="String matchers" time="{duration}"/> diff --git a/projects/SelfTest/Baselines/xml.sw.approved.txt b/projects/SelfTest/Baselines/xml.sw.approved.txt index 3d8d6d30..32ecb062 100644 --- a/projects/SelfTest/Baselines/xml.sw.approved.txt +++ b/projects/SelfTest/Baselines/xml.sw.approved.txt @@ -341,8 +341,8 @@ </Expression> <OverallResult success="false"/> </TestCase> - <TestCase name="AllOf matcher" tags="[matchers]" filename="projects/<exe-name>/MiscTests.cpp" > - <Expression success="true" type="CHECK_THAT" filename="projects/<exe-name>/MiscTests.cpp" > + <TestCase name="AllOf matcher" tags="[matchers]" filename="projects/<exe-name>/MatchersTests.cpp" > + <Expression success="true" type="CHECK_THAT" filename="projects/<exe-name>/MatchersTests.cpp" > <Original> testStringForMatching(), AllOf( Catch::Contains( "string" ), Catch::Contains( "abc" ) ) </Original> @@ -399,8 +399,8 @@ <TestCase name="Anonymous test case 1" filename="projects/<exe-name>/VariadicMacrosTests.cpp" > <OverallResult success="true"/> </TestCase> - <TestCase name="AnyOf matcher" tags="[matchers]" filename="projects/<exe-name>/MiscTests.cpp" > - <Expression success="true" type="CHECK_THAT" filename="projects/<exe-name>/MiscTests.cpp" > + <TestCase name="AnyOf matcher" tags="[matchers]" filename="projects/<exe-name>/MatchersTests.cpp" > + <Expression success="true" type="CHECK_THAT" filename="projects/<exe-name>/MatchersTests.cpp" > <Original> testStringForMatching(), AnyOf( Catch::Contains( "string" ), Catch::Contains( "not there" ) ) </Original> @@ -408,7 +408,7 @@ "this string contains 'abc' as a substring" ( contains: "string" or contains: "not there" ) </Expanded> </Expression> - <Expression success="true" type="CHECK_THAT" filename="projects/<exe-name>/MiscTests.cpp" > + <Expression success="true" type="CHECK_THAT" filename="projects/<exe-name>/MatchersTests.cpp" > <Original> testStringForMatching(), AnyOf( Catch::Contains( "not there" ), Catch::Contains( "string" ) ) </Original> @@ -927,8 +927,8 @@ </Expression> <OverallResult success="true"/> </TestCase> - <TestCase name="Contains string matcher" tags="[.][failing][hide][matchers]" filename="projects/<exe-name>/MiscTests.cpp" > - <Expression success="false" type="CHECK_THAT" filename="projects/<exe-name>/MiscTests.cpp" > + <TestCase name="Contains string matcher" tags="[.][failing][hide][matchers]" filename="projects/<exe-name>/MatchersTests.cpp" > + <Expression success="false" type="CHECK_THAT" filename="projects/<exe-name>/MatchersTests.cpp" > <Original> testStringForMatching(), Contains( "not there" ) </Original> @@ -983,8 +983,8 @@ </Expression> <OverallResult success="true"/> </TestCase> - <TestCase name="EndsWith string matcher" tags="[.][failing][hide][matchers]" filename="projects/<exe-name>/MiscTests.cpp" > - <Expression success="false" type="CHECK_THAT" filename="projects/<exe-name>/MiscTests.cpp" > + <TestCase name="EndsWith string matcher" tags="[.][failing][hide][matchers]" filename="projects/<exe-name>/MatchersTests.cpp" > + <Expression success="false" type="CHECK_THAT" filename="projects/<exe-name>/MatchersTests.cpp" > <Original> testStringForMatching(), EndsWith( "this" ) </Original> @@ -1160,8 +1160,8 @@ </Expression> <OverallResult success="true"/> </TestCase> - <TestCase name="Equals" tags="[matchers]" filename="projects/<exe-name>/MiscTests.cpp" > - <Expression success="true" type="CHECK_THAT" filename="projects/<exe-name>/MiscTests.cpp" > + <TestCase name="Equals" tags="[matchers]" filename="projects/<exe-name>/MatchersTests.cpp" > + <Expression success="true" type="CHECK_THAT" filename="projects/<exe-name>/MatchersTests.cpp" > <Original> testStringForMatching(), Equals( "this string contains 'abc' as a substring" ) </Original> @@ -1171,8 +1171,8 @@ </Expression> <OverallResult success="true"/> </TestCase> - <TestCase name="Equals string matcher" tags="[.][failing][hide][matchers]" filename="projects/<exe-name>/MiscTests.cpp" > - <Expression success="false" type="CHECK_THAT" filename="projects/<exe-name>/MiscTests.cpp" > + <TestCase name="Equals string matcher" tags="[.][failing][hide][matchers]" filename="projects/<exe-name>/MatchersTests.cpp" > + <Expression success="false" type="CHECK_THAT" filename="projects/<exe-name>/MatchersTests.cpp" > <Original> testStringForMatching(), Equals( "something else" ) </Original> @@ -4380,8 +4380,8 @@ re>" <TestCase name="ManuallyRegistered" filename="projects/<exe-name>/TestMain.cpp" > <OverallResult success="true"/> </TestCase> - <TestCase name="Matchers can be (AllOf) composed with the && operator" tags="[matchers][operator&&][operators]" filename="projects/<exe-name>/MiscTests.cpp" > - <Expression success="true" type="CHECK_THAT" filename="projects/<exe-name>/MiscTests.cpp" > + <TestCase name="Matchers can be (AllOf) composed with the && operator" tags="[matchers][operator&&][operators]" filename="projects/<exe-name>/MatchersTests.cpp" > + <Expression success="true" type="CHECK_THAT" filename="projects/<exe-name>/MatchersTests.cpp" > <Original> testStringForMatching(), Contains( "string" ) && Contains( "abc" ) && Contains( "substring" ) && Contains( "contains" ) </Original> @@ -4391,8 +4391,8 @@ re>" </Expression> <OverallResult success="true"/> </TestCase> - <TestCase name="Matchers can be (AnyOf) composed with the || operator" tags="[matchers][operators][operator||]" filename="projects/<exe-name>/MiscTests.cpp" > - <Expression success="true" type="CHECK_THAT" filename="projects/<exe-name>/MiscTests.cpp" > + <TestCase name="Matchers can be (AnyOf) composed with the || operator" tags="[matchers][operators][operator||]" filename="projects/<exe-name>/MatchersTests.cpp" > + <Expression success="true" type="CHECK_THAT" filename="projects/<exe-name>/MatchersTests.cpp" > <Original> testStringForMatching(), Contains( "string" ) || Contains( "different" ) || Contains( "random" ) </Original> @@ -4400,7 +4400,7 @@ re>" "this string contains 'abc' as a substring" ( contains: "string" or contains: "different" or contains: "random" ) </Expanded> </Expression> - <Expression success="true" type="CHECK_THAT" filename="projects/<exe-name>/MiscTests.cpp" > + <Expression success="true" type="CHECK_THAT" filename="projects/<exe-name>/MatchersTests.cpp" > <Original> testStringForMatching2(), Contains( "string" ) || Contains( "different" ) || Contains( "random" ) </Original> @@ -4410,8 +4410,8 @@ re>" </Expression> <OverallResult success="true"/> </TestCase> - <TestCase name="Matchers can be composed with both && and ||" tags="[matchers][operator&&][operators][operator||]" filename="projects/<exe-name>/MiscTests.cpp" > - <Expression success="true" type="CHECK_THAT" filename="projects/<exe-name>/MiscTests.cpp" > + <TestCase name="Matchers can be composed with both && and ||" tags="[matchers][operator&&][operators][operator||]" filename="projects/<exe-name>/MatchersTests.cpp" > + <Expression success="true" type="CHECK_THAT" filename="projects/<exe-name>/MatchersTests.cpp" > <Original> testStringForMatching(), ( Contains( "string" ) || Contains( "different" ) ) && Contains( "substring" ) </Original> @@ -4421,8 +4421,8 @@ re>" </Expression> <OverallResult success="true"/> </TestCase> - <TestCase name="Matchers can be composed with both && and || - failing" tags="[.][.failing][hide][matchers][operator&&][operators][operator||]" filename="projects/<exe-name>/MiscTests.cpp" > - <Expression success="false" type="CHECK_THAT" filename="projects/<exe-name>/MiscTests.cpp" > + <TestCase name="Matchers can be composed with both && and || - failing" tags="[.][.failing][hide][matchers][operator&&][operators][operator||]" filename="projects/<exe-name>/MatchersTests.cpp" > + <Expression success="false" type="CHECK_THAT" filename="projects/<exe-name>/MatchersTests.cpp" > <Original> testStringForMatching(), ( Contains( "string" ) || Contains( "different" ) ) && Contains( "random" ) </Original> @@ -4432,8 +4432,8 @@ re>" </Expression> <OverallResult success="false"/> </TestCase> - <TestCase name="Matchers can be negated (Not) with the ! operator" tags="[matchers][not][operators]" filename="projects/<exe-name>/MiscTests.cpp" > - <Expression success="true" type="CHECK_THAT" filename="projects/<exe-name>/MiscTests.cpp" > + <TestCase name="Matchers can be negated (Not) with the ! operator" tags="[matchers][not][operators]" filename="projects/<exe-name>/MatchersTests.cpp" > + <Expression success="true" type="CHECK_THAT" filename="projects/<exe-name>/MatchersTests.cpp" > <Original> testStringForMatching(), !Contains( "different" ) </Original> @@ -4443,8 +4443,8 @@ re>" </Expression> <OverallResult success="true"/> </TestCase> - <TestCase name="Matchers can be negated (Not) with the ! operator - failing" tags="[.][.failing][hide][matchers][not][operators]" filename="projects/<exe-name>/MiscTests.cpp" > - <Expression success="false" type="CHECK_THAT" filename="projects/<exe-name>/MiscTests.cpp" > + <TestCase name="Matchers can be negated (Not) with the ! operator - failing" tags="[.][.failing][hide][matchers][not][operators]" filename="projects/<exe-name>/MatchersTests.cpp" > + <Expression success="false" type="CHECK_THAT" filename="projects/<exe-name>/MatchersTests.cpp" > <Original> testStringForMatching(), !Contains( "substring" ) </Original> @@ -7032,8 +7032,8 @@ Message from section two </StdOut> </OverallResult> </TestCase> - <TestCase name="StartsWith string matcher" tags="[.][failing][hide][matchers]" filename="projects/<exe-name>/MiscTests.cpp" > - <Expression success="false" type="CHECK_THAT" filename="projects/<exe-name>/MiscTests.cpp" > + <TestCase name="StartsWith string matcher" tags="[.][failing][hide][matchers]" filename="projects/<exe-name>/MatchersTests.cpp" > + <Expression success="false" type="CHECK_THAT" filename="projects/<exe-name>/MatchersTests.cpp" > <Original> testStringForMatching(), StartsWith( "string" ) </Original> @@ -7043,8 +7043,8 @@ Message from section two </Expression> <OverallResult success="false"/> </TestCase> - <TestCase name="String matchers" tags="[matchers]" filename="projects/<exe-name>/MiscTests.cpp" > - <Expression success="true" type="REQUIRE_THAT" filename="projects/<exe-name>/MiscTests.cpp" > + <TestCase name="String matchers" tags="[matchers]" filename="projects/<exe-name>/MatchersTests.cpp" > + <Expression success="true" type="REQUIRE_THAT" filename="projects/<exe-name>/MatchersTests.cpp" > <Original> testStringForMatching(), Contains( "string" ) </Original> @@ -7052,7 +7052,7 @@ Message from section two "this string contains 'abc' as a substring" contains: "string" </Expanded> </Expression> - <Expression success="true" type="CHECK_THAT" filename="projects/<exe-name>/MiscTests.cpp" > + <Expression success="true" type="CHECK_THAT" filename="projects/<exe-name>/MatchersTests.cpp" > <Original> testStringForMatching(), Contains( "abc" ) </Original> @@ -7060,7 +7060,7 @@ Message from section two "this string contains 'abc' as a substring" contains: "abc" </Expanded> </Expression> - <Expression success="true" type="CHECK_THAT" filename="projects/<exe-name>/MiscTests.cpp" > + <Expression success="true" type="CHECK_THAT" filename="projects/<exe-name>/MatchersTests.cpp" > <Original> testStringForMatching(), StartsWith( "this" ) </Original> @@ -7068,7 +7068,7 @@ Message from section two "this string contains 'abc' as a substring" starts with: "this" </Expanded> </Expression> - <Expression success="true" type="CHECK_THAT" filename="projects/<exe-name>/MiscTests.cpp" > + <Expression success="true" type="CHECK_THAT" filename="projects/<exe-name>/MatchersTests.cpp" > <Original> testStringForMatching(), EndsWith( "substring" ) </Original> diff --git a/projects/SelfTest/MatchersTests.cpp b/projects/SelfTest/MatchersTests.cpp new file mode 100644 index 00000000..601c6608 --- /dev/null +++ b/projects/SelfTest/MatchersTests.cpp @@ -0,0 +1,99 @@ +/* + * Created by Phil on 21/02/2017. + * Copyright 2017 Two Blue Cubes Ltd. All rights reserved. + * + * Distributed under the Boost Software License, Version 1.0. (See accompanying + * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + */ + +#include "catch.hpp" + +inline const char* testStringForMatching() +{ + return "this string contains 'abc' as a substring"; +} +inline const char* testStringForMatching2() +{ + return "some completely different text that contains one common word"; +} + +using namespace Catch::Matchers; + +TEST_CASE("String matchers", "[matchers]" ) +{ + REQUIRE_THAT( testStringForMatching(), Contains( "string" ) ); + CHECK_THAT( testStringForMatching(), Contains( "abc" ) ); + + CHECK_THAT( testStringForMatching(), StartsWith( "this" ) ); + CHECK_THAT( testStringForMatching(), EndsWith( "substring" ) ); +} + +TEST_CASE("Contains string matcher", "[.][failing][matchers]") +{ + CHECK_THAT( testStringForMatching(), Contains( "not there" ) ); +} + +TEST_CASE("StartsWith string matcher", "[.][failing][matchers]") +{ + CHECK_THAT( testStringForMatching(), StartsWith( "string" ) ); +} + +TEST_CASE("EndsWith string matcher", "[.][failing][matchers]") +{ + CHECK_THAT( testStringForMatching(), EndsWith( "this" ) ); +} + +TEST_CASE("Equals string matcher", "[.][failing][matchers]") +{ + CHECK_THAT( testStringForMatching(), Equals( "something else" ) ); +} + +TEST_CASE("AllOf matcher", "[matchers]") +{ + CHECK_THAT( testStringForMatching(), AllOf( Catch::Contains( "string" ), Catch::Contains( "abc" ) ) ); +} +TEST_CASE("AnyOf matcher", "[matchers]") +{ + CHECK_THAT( testStringForMatching(), AnyOf( Catch::Contains( "string" ), Catch::Contains( "not there" ) ) ); + CHECK_THAT( testStringForMatching(), AnyOf( Catch::Contains( "not there" ), Catch::Contains( "string" ) ) ); +} + +TEST_CASE("Equals", "[matchers]") +{ + CHECK_THAT( testStringForMatching(), Equals( "this string contains 'abc' as a substring" ) ); +} + +TEST_CASE("Matchers can be (AllOf) composed with the && operator", "[matchers][operators][operator&&]") +{ + CHECK_THAT( testStringForMatching(), + Contains( "string" ) && + Contains( "abc" ) && + Contains( "substring" ) && + Contains( "contains" ) ); +} + +TEST_CASE("Matchers can be (AnyOf) composed with the || operator", "[matchers][operators][operator||]") +{ + CHECK_THAT( testStringForMatching(), Contains( "string" ) || Contains( "different" ) || Contains( "random" ) ); + CHECK_THAT( testStringForMatching2(), Contains( "string" ) || Contains( "different" ) || Contains( "random" ) ); +} + +TEST_CASE("Matchers can be composed with both && and ||", "[matchers][operators][operator||][operator&&]") +{ + CHECK_THAT( testStringForMatching(), ( Contains( "string" ) || Contains( "different" ) ) && Contains( "substring" ) ); +} + +TEST_CASE("Matchers can be composed with both && and || - failing", "[matchers][operators][operator||][operator&&][.failing]") +{ + CHECK_THAT( testStringForMatching(), ( Contains( "string" ) || Contains( "different" ) ) && Contains( "random" ) ); +} + +TEST_CASE("Matchers can be negated (Not) with the ! operator", "[matchers][operators][not]") +{ + CHECK_THAT( testStringForMatching(), !Contains( "different" ) ); +} + +TEST_CASE("Matchers can be negated (Not) with the ! operator - failing", |