From 4e6938d78e375d9bc3481d7baccb0f84341a4010 Mon Sep 17 00:00:00 2001 From: Phil Nash Date: Tue, 21 Feb 2017 14:19:09 +0000 Subject: [PATCH] Moved matchers tests into their own file --- CMakeLists.txt | 1 + .../Baselines/console.std.approved.txt | 24 ++--- .../Baselines/console.sw.approved.txt | 66 ++++++------- .../SelfTest/Baselines/junit.sw.approved.txt | 12 +-- .../SelfTest/Baselines/xml.sw.approved.txt | 66 ++++++------- projects/SelfTest/MatchersTests.cpp | 99 +++++++++++++++++++ projects/SelfTest/MiscTests.cpp | 91 ----------------- 7 files changed, 184 insertions(+), 175 deletions(-) create mode 100644 projects/SelfTest/MatchersTests.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index b6fff3ca..3eddb983 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -70,6 +70,7 @@ set(TEST_SOURCES ${SELF_TEST_DIR}/ToStringWhich.cpp ${SELF_TEST_DIR}/TrickyTests.cpp ${SELF_TEST_DIR}/VariadicMacrosTests.cpp + ${SELF_TEST_DIR}/MatchersTests.cpp ) CheckFileList(TEST_SOURCES ${SELF_TEST_DIR}) 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: +MatchersTests.cpp: ............................................................................... -MiscTests.cpp:: FAILED: +MatchersTests.cpp:: 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: +MatchersTests.cpp: ............................................................................... -MiscTests.cpp:: FAILED: +MatchersTests.cpp:: 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: +MatchersTests.cpp: ............................................................................... -MiscTests.cpp:: FAILED: +MatchersTests.cpp:: 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: +MatchersTests.cpp: ............................................................................... -MiscTests.cpp:: FAILED: +MatchersTests.cpp:: 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: +MatchersTests.cpp: ............................................................................... -MiscTests.cpp:: FAILED: +MatchersTests.cpp:: 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: +MatchersTests.cpp: ............................................................................... -MiscTests.cpp:: FAILED: +MatchersTests.cpp:: 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: +MatchersTests.cpp: ............................................................................... -MiscTests.cpp:: +MatchersTests.cpp:: PASSED: CHECK_THAT( testStringForMatching(), AllOf( Catch::Contains( "string" ), Catch::Contains( "abc" ) ) ) with expansion: @@ -364,17 +364,17 @@ with message: ------------------------------------------------------------------------------- AnyOf matcher ------------------------------------------------------------------------------- -MiscTests.cpp: +MatchersTests.cpp: ............................................................................... -MiscTests.cpp:: +MatchersTests.cpp:: 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:: +MatchersTests.cpp:: 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: +MatchersTests.cpp: ............................................................................... -MiscTests.cpp:: FAILED: +MatchersTests.cpp:: 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: +MatchersTests.cpp: ............................................................................... -MiscTests.cpp:: FAILED: +MatchersTests.cpp:: 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: +MatchersTests.cpp: ............................................................................... -MiscTests.cpp:: +MatchersTests.cpp:: 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: +MatchersTests.cpp: ............................................................................... -MiscTests.cpp:: FAILED: +MatchersTests.cpp:: 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: +MatchersTests.cpp: ............................................................................... -MiscTests.cpp:: +MatchersTests.cpp:: 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: +MatchersTests.cpp: ............................................................................... -MiscTests.cpp:: +MatchersTests.cpp:: 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:: +MatchersTests.cpp:: 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: +MatchersTests.cpp: ............................................................................... -MiscTests.cpp:: +MatchersTests.cpp:: 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: +MatchersTests.cpp: ............................................................................... -MiscTests.cpp:: FAILED: +MatchersTests.cpp:: 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: +MatchersTests.cpp: ............................................................................... -MiscTests.cpp:: +MatchersTests.cpp:: 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: +MatchersTests.cpp: ............................................................................... -MiscTests.cpp:: FAILED: +MatchersTests.cpp:: 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: +MatchersTests.cpp: ............................................................................... -MiscTests.cpp:: FAILED: +MatchersTests.cpp:: 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: +MatchersTests.cpp: ............................................................................... -MiscTests.cpp:: +MatchersTests.cpp:: PASSED: REQUIRE_THAT( testStringForMatching(), Contains( "string" ) ) with expansion: "this string contains 'abc' as a substring" contains: "string" -MiscTests.cpp:: +MatchersTests.cpp:: PASSED: CHECK_THAT( testStringForMatching(), Contains( "abc" ) ) with expansion: "this string contains 'abc' as a substring" contains: "abc" -MiscTests.cpp:: +MatchersTests.cpp:: PASSED: CHECK_THAT( testStringForMatching(), StartsWith( "this" ) ) with expansion: "this string contains 'abc' as a substring" starts with: "this" -MiscTests.cpp:: +MatchersTests.cpp:: 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: -MiscTests.cpp: +MatchersTests.cpp: @@ -116,7 +116,7 @@ ExceptionTests.cpp: -MiscTests.cpp: +MatchersTests.cpp: @@ -164,7 +164,7 @@ ConditionTests.cpp: -MiscTests.cpp: +MatchersTests.cpp: @@ -256,13 +256,13 @@ ConditionTests.cpp: -MiscTests.cpp: +MatchersTests.cpp: -MiscTests.cpp: +MatchersTests.cpp: @@ -445,7 +445,7 @@ Message from section two -MiscTests.cpp: +MatchersTests.cpp: 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 @@ - - + + testStringForMatching(), AllOf( Catch::Contains( "string" ), Catch::Contains( "abc" ) ) @@ -399,8 +399,8 @@ - - + + testStringForMatching(), AnyOf( Catch::Contains( "string" ), Catch::Contains( "not there" ) ) @@ -408,7 +408,7 @@ "this string contains 'abc' as a substring" ( contains: "string" or contains: "not there" ) - + testStringForMatching(), AnyOf( Catch::Contains( "not there" ), Catch::Contains( "string" ) ) @@ -927,8 +927,8 @@ - - + + testStringForMatching(), Contains( "not there" ) @@ -983,8 +983,8 @@ - - + + testStringForMatching(), EndsWith( "this" ) @@ -1160,8 +1160,8 @@ - - + + testStringForMatching(), Equals( "this string contains 'abc' as a substring" ) @@ -1171,8 +1171,8 @@ - - + + testStringForMatching(), Equals( "something else" ) @@ -4380,8 +4380,8 @@ re>" - - + + testStringForMatching(), Contains( "string" ) && Contains( "abc" ) && Contains( "substring" ) && Contains( "contains" ) @@ -4391,8 +4391,8 @@ re>" - - + + testStringForMatching(), Contains( "string" ) || Contains( "different" ) || Contains( "random" ) @@ -4400,7 +4400,7 @@ re>" "this string contains 'abc' as a substring" ( contains: "string" or contains: "different" or contains: "random" ) - + testStringForMatching2(), Contains( "string" ) || Contains( "different" ) || Contains( "random" ) @@ -4410,8 +4410,8 @@ re>" - - + + testStringForMatching(), ( Contains( "string" ) || Contains( "different" ) ) && Contains( "substring" ) @@ -4421,8 +4421,8 @@ re>" - - + + testStringForMatching(), ( Contains( "string" ) || Contains( "different" ) ) && Contains( "random" ) @@ -4432,8 +4432,8 @@ re>" - - + + testStringForMatching(), !Contains( "different" ) @@ -4443,8 +4443,8 @@ re>" - - + + testStringForMatching(), !Contains( "substring" ) @@ -7032,8 +7032,8 @@ Message from section two - - + + testStringForMatching(), StartsWith( "string" ) @@ -7043,8 +7043,8 @@ Message from section two - - + + testStringForMatching(), Contains( "string" ) @@ -7052,7 +7052,7 @@ Message from section two "this string contains 'abc' as a substring" contains: "string" - + testStringForMatching(), Contains( "abc" ) @@ -7060,7 +7060,7 @@ Message from section two "this string contains 'abc' as a substring" contains: "abc" - + testStringForMatching(), StartsWith( "this" ) @@ -7068,7 +7068,7 @@ Message from section two "this string contains 'abc' as a substring" starts with: "this" - + testStringForMatching(), EndsWith( "substring" ) 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", "[matchers][operators][not][.failing]") +{ + CHECK_THAT( testStringForMatching(), !Contains( "substring" ) ); +} diff --git a/projects/SelfTest/MiscTests.cpp b/projects/SelfTest/MiscTests.cpp index 73c4ccc0..88a524f8 100644 --- a/projects/SelfTest/MiscTests.cpp +++ b/projects/SelfTest/MiscTests.cpp @@ -204,97 +204,6 @@ TEST_CASE( "atomic if", "[failing][0]") REQUIRE(x == 0); } -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", "[matchers][operators][not][.failing]") -{ - CHECK_THAT( testStringForMatching(), !Contains( "substring" ) ); -} - - inline unsigned int Factorial( unsigned int number ) { // return number <= 1 ? number : Factorial(number-1)*number;