1 /*
2  *  Created by Phil on 21/02/2017.
3  *  Copyright 2017 Two Blue Cubes Ltd. All rights reserved.
4  *
5  *  Distributed under the Boost Software License, Version 1.0. (See accompanying
6  *  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7  */
8 
9 #include "catch.hpp"
10 
11 #include <sstream>
12 #include <algorithm>
13 
14 #ifdef __clang__
15 #pragma clang diagnostic push
16 #pragma clang diagnostic ignored "-Wweak-vtables"
17 #pragma clang diagnostic ignored "-Wpadded"
18 #endif
19 
20 namespace { namespace MatchersTests {
21 
22 #ifndef CATCH_CONFIG_DISABLE_MATCHERS
23 
24 #ifndef MATCHERS_TEST_HELPERS_INCLUDED // Don't compile this more than once per TU
25 #define MATCHERS_TEST_HELPERS_INCLUDED
26 
testStringForMatching()27     inline const char *testStringForMatching() {
28         return "this string contains 'abc' as a substring";
29     }
30 
testStringForMatching2()31     inline const char *testStringForMatching2() {
32         return "some completely different text that contains one common word";
33     }
34 
alwaysTrue(int)35     inline bool alwaysTrue(int) { return true; }
alwaysFalse(int)36     inline bool alwaysFalse(int) { return false; }
37 
38 
39 #ifdef _MSC_VER
40 #pragma warning(disable:4702) // Unreachable code -- MSVC 19 (VS 2015) sees right through the indirection
41 #endif
42 
43 #include <exception>
44 
45     struct SpecialException : std::exception {
SpecialException__anonc5ab40470111::MatchersTests::SpecialException46         SpecialException(int i_) : i(i_) {}
47 
what__anonc5ab40470111::MatchersTests::SpecialException48         char const* what() const noexcept override {
49             return "SpecialException::what";
50         }
51 
52         int i;
53     };
54 
55     struct DerivedException : std::exception {
what__anonc5ab40470111::MatchersTests::DerivedException56         char const* what() const noexcept override {
57             return "DerivedException::what";
58         }
59     };
60 
doesNotThrow()61     void doesNotThrow() {}
62 
63 #if !defined(CATCH_CONFIG_DISABLE_EXCEPTIONS)
64     [[noreturn]]
throwsSpecialException(int i)65     void throwsSpecialException(int i) {
66         throw SpecialException{i};
67     }
68 
69     [[noreturn]]
throwsAsInt(int i)70     void throwsAsInt(int i) {
71         throw i;
72     }
73 
74     [[noreturn]]
throwsDerivedException()75     void throwsDerivedException() {
76         throw DerivedException{};
77     }
78 #endif
79 
80     class ExceptionMatcher : public Catch::MatcherBase<SpecialException> {
81         int m_expected;
82     public:
ExceptionMatcher(int i)83         ExceptionMatcher(int i) : m_expected(i) {}
84 
match(SpecialException const & se) const85         bool match(SpecialException const &se) const override {
86             return se.i == m_expected;
87         }
88 
describe() const89         std::string describe() const override {
90             std::ostringstream ss;
91             ss << "special exception has value of " << m_expected;
92             return ss.str();
93         }
94     };
95 
96 #endif
97 
98     using namespace Catch::Matchers;
99 
100 #ifdef __DJGPP__
nextafter(float from,float to)101     float nextafter(float from, float to)
102     {
103         return ::nextafterf(from, to);
104     }
105 
nextafter(double from,double to)106     double nextafter(double from, double to)
107     {
108         return ::nextafter(from, to);
109     }
110 #else
111     using std::nextafter;
112 #endif
113 
114     TEST_CASE("String matchers", "[matchers]") {
115         REQUIRE_THAT(testStringForMatching(), Contains("string"));
116         REQUIRE_THAT(testStringForMatching(), Contains("string", Catch::CaseSensitive::No));
117         CHECK_THAT(testStringForMatching(), Contains("abc"));
118         CHECK_THAT(testStringForMatching(), Contains("aBC", Catch::CaseSensitive::No));
119 
120         CHECK_THAT(testStringForMatching(), StartsWith("this"));
121         CHECK_THAT(testStringForMatching(), StartsWith("THIS", Catch::CaseSensitive::No));
122         CHECK_THAT(testStringForMatching(), EndsWith("substring"));
123         CHECK_THAT(testStringForMatching(), EndsWith(" SuBsTrInG", Catch::CaseSensitive::No));
124     }
125 
126     TEST_CASE("Contains string matcher", "[.][failing][matchers]") {
127         CHECK_THAT(testStringForMatching(), Contains("not there", Catch::CaseSensitive::No));
128         CHECK_THAT(testStringForMatching(), Contains("STRING"));
129     }
130 
131     TEST_CASE("StartsWith string matcher", "[.][failing][matchers]") {
132         CHECK_THAT(testStringForMatching(), StartsWith("This String"));
133         CHECK_THAT(testStringForMatching(), StartsWith("string", Catch::CaseSensitive::No));
134     }
135 
136     TEST_CASE("EndsWith string matcher", "[.][failing][matchers]") {
137         CHECK_THAT(testStringForMatching(), EndsWith("Substring"));
138         CHECK_THAT(testStringForMatching(), EndsWith("this", Catch::CaseSensitive::No));
139     }
140 
141     TEST_CASE("Equals string matcher", "[.][failing][matchers]") {
142         CHECK_THAT(testStringForMatching(), Equals("this string contains 'ABC' as a substring"));
143         CHECK_THAT(testStringForMatching(), Equals("something else", Catch::CaseSensitive::No));
144     }
145 
146     TEST_CASE("Equals", "[matchers]") {
147         CHECK_THAT(testStringForMatching(), Equals("this string contains 'abc' as a substring"));
148         CHECK_THAT(testStringForMatching(),
149                    Equals("this string contains 'ABC' as a substring", Catch::CaseSensitive::No));
150     }
151 
152 // <regex> does not work in libstdc++ 4.8, so we have to enable these tests only when they
153 // are expected to pass and cannot have them in baselines
154     TEST_CASE("Regex string matcher -- libstdc++-4.8 workaround", "[matchers][approvals]") {
155 
156 // This is fiiiine
157 // Taken from an answer at
158 // https://stackoverflow.com/questions/12530406/is-gcc-4-8-or-earlier-buggy-about-regular-expressions
159 #if (!defined(__GNUC__)) || \
160       (__cplusplus >= 201103L && \
161       (!defined(__GLIBCXX__) || (__cplusplus >= 201402L) || \
162         (defined(_GLIBCXX_REGEX_DFS_QUANTIFIERS_LIMIT) || \
163           defined(_GLIBCXX_REGEX_STATE_LIMIT) || \
164              (defined(_GLIBCXX_RELEASE) && \
165              _GLIBCXX_RELEASE > 4))))
166 
167 // DJGPP meets the above condition but <regex> does not work properly anyway
168 #ifndef __DJGPP__
169             REQUIRE_THAT(testStringForMatching(), Matches("this string contains 'abc' as a substring"));
170             REQUIRE_THAT(testStringForMatching(),
171                          Matches("this string CONTAINS 'abc' as a substring", Catch::CaseSensitive::No));
172             REQUIRE_THAT(testStringForMatching(), Matches("^this string contains 'abc' as a substring$"));
173             REQUIRE_THAT(testStringForMatching(), Matches("^.* 'abc' .*$"));
174             REQUIRE_THAT(testStringForMatching(), Matches("^.* 'ABC' .*$", Catch::CaseSensitive::No));
175 #endif
176 
177 #endif
178 
179             REQUIRE_THAT(testStringForMatching2(), !Matches("this string contains 'abc' as a substring"));
180         }
181 
182         TEST_CASE("Regex string matcher", "[matchers][.failing]") {
183             CHECK_THAT(testStringForMatching(), Matches("this STRING contains 'abc' as a substring"));
184             CHECK_THAT(testStringForMatching(), Matches("contains 'abc' as a substring"));
185             CHECK_THAT(testStringForMatching(), Matches("this string contains 'abc' as a"));
186         }
187 
188         TEST_CASE("Matchers can be (AllOf) composed with the && operator", "[matchers][operators][operator&&]") {
189             CHECK_THAT(testStringForMatching(),
190                        Contains("string") &&
191                        Contains("abc") &&
192                        Contains("substring") &&
193                        Contains("contains"));
194         }
195 
196         TEST_CASE("Matchers can be (AnyOf) composed with the || operator", "[matchers][operators][operator||]") {
197             CHECK_THAT(testStringForMatching(), Contains("string") || Contains("different") || Contains("random"));
198             CHECK_THAT(testStringForMatching2(), Contains("string") || Contains("different") || Contains("random"));
199         }
200 
201         TEST_CASE("Matchers can be composed with both && and ||", "[matchers][operators][operator||][operator&&]") {
202             CHECK_THAT(testStringForMatching(), (Contains("string") || Contains("different")) && Contains("substring"));
203         }
204 
205         TEST_CASE("Matchers can be composed with both && and || - failing",
206                   "[matchers][operators][operator||][operator&&][.failing]") {
207             CHECK_THAT(testStringForMatching(), (Contains("string") || Contains("different")) && Contains("random"));
208         }
209 
210         TEST_CASE("Matchers can be negated (Not) with the ! operator", "[matchers][operators][not]") {
211             CHECK_THAT(testStringForMatching(), !Contains("different"));
212         }
213 
214         TEST_CASE("Matchers can be negated (Not) with the ! operator - failing",
215                   "[matchers][operators][not][.failing]") {
216             CHECK_THAT(testStringForMatching(), !Contains("substring"));
217         }
218 
219         TEST_CASE("Vector matchers", "[matchers][vector]") {
220             std::vector<int> v;
221             v.push_back(1);
222             v.push_back(2);
223             v.push_back(3);
224 
225             std::vector<int> v2;
226             v2.push_back(1);
227             v2.push_back(2);
228 
229             std::vector<double> v3;
230             v3.push_back(1);
231             v3.push_back(2);
232             v3.push_back(3);
233 
234             std::vector<double> v4;
235             v4.push_back(1 + 1e-8);
236             v4.push_back(2 + 1e-8);
237             v4.push_back(3 + 1e-8);
238 
239             std::vector<int> empty;
240 
241             SECTION("Contains (element)") {
242                 CHECK_THAT(v, VectorContains(1));
243                 CHECK_THAT(v, VectorContains(2));
244             }
245             SECTION("Contains (vector)") {
246                 CHECK_THAT(v, Contains(v2));
247                 v2.push_back(3); // now exactly matches
248                 CHECK_THAT(v, Contains(v2));
249 
250                 CHECK_THAT(v, Contains(empty));
251                 CHECK_THAT(empty, Contains(empty));
252             }
253             SECTION("Contains (element), composed") {
254                 CHECK_THAT(v, VectorContains(1) && VectorContains(2));
255             }
256 
257             SECTION("Equals") {
258 
259                 // Same vector
260                 CHECK_THAT(v, Equals(v));
261 
262                 CHECK_THAT(empty, Equals(empty));
263 
264                 // Different vector with same elements
265                 v2.push_back(3);
266                 CHECK_THAT(v, Equals(v2));
267             }
268             SECTION("UnorderedEquals") {
269                 CHECK_THAT(v, UnorderedEquals(v));
270                 CHECK_THAT(empty, UnorderedEquals(empty));
271 
272                 auto permuted = v;
273                 std::next_permutation(begin(permuted), end(permuted));
274                 REQUIRE_THAT(permuted, UnorderedEquals(v));
275 
276                 std::reverse(begin(permuted), end(permuted));
277                 REQUIRE_THAT(permuted, UnorderedEquals(v));
278             }
279         }
280 
281         TEST_CASE("Vector matchers that fail", "[matchers][vector][.][failing]") {
282             std::vector<int> v;
283             v.push_back(1);
284             v.push_back(2);
285             v.push_back(3);
286 
287             std::vector<int> v2;
288             v2.push_back(1);
289             v2.push_back(2);
290 
291             std::vector<double> v3;
292             v3.push_back(1);
293             v3.push_back(2);
294             v3.push_back(3);
295 
296             std::vector<double> v4;
297             v4.push_back(1.1);
298             v4.push_back(2.1);
299             v4.push_back(3.1);
300 
301             std::vector<int> empty;
302 
303             SECTION("Contains (element)") {
304                 CHECK_THAT(v, VectorContains(-1));
305                 CHECK_THAT(empty, VectorContains(1));
306             }
307             SECTION("Contains (vector)") {
308                 CHECK_THAT(empty, Contains(v));
309                 v2.push_back(4);
310                 CHECK_THAT(v, Contains(v2));
311             }
312 
313             SECTION("Equals") {
314 
315                 CHECK_THAT(v, Equals(v2));
316                 CHECK_THAT(v2, Equals(v));
317                 CHECK_THAT(empty, Equals(v));
318                 CHECK_THAT(v, Equals(empty));
319             }
320             SECTION("UnorderedEquals") {
321                 CHECK_THAT(v, UnorderedEquals(empty));
322                 CHECK_THAT(empty, UnorderedEquals(v));
323 
324                 auto permuted = v;
325                 std::next_permutation(begin(permuted), end(permuted));
326                 permuted.pop_back();
327                 CHECK_THAT(permuted, UnorderedEquals(v));
328 
329                 std::reverse(begin(permuted), end(permuted));
330                 CHECK_THAT(permuted, UnorderedEquals(v));
331             }
332         }
333 
334 #if !defined(CATCH_CONFIG_DISABLE_EXCEPTIONS)
335         TEST_CASE("Exception matchers that succeed", "[matchers][exceptions][!throws]") {
336             CHECK_THROWS_MATCHES(throwsSpecialException(1), SpecialException, ExceptionMatcher{1});
337             REQUIRE_THROWS_MATCHES(throwsSpecialException(2), SpecialException, ExceptionMatcher{2});
338         }
339 
340         TEST_CASE("Exception matchers that fail", "[matchers][exceptions][!throws][.failing]") {
341             SECTION("No exception") {
342                 CHECK_THROWS_MATCHES(doesNotThrow(), SpecialException, ExceptionMatcher{1});
343                 REQUIRE_THROWS_MATCHES(doesNotThrow(), SpecialException, ExceptionMatcher{1});
344             }
345             SECTION("Type mismatch") {
346                 CHECK_THROWS_MATCHES(throwsAsInt(1), SpecialException, ExceptionMatcher{1});
347                 REQUIRE_THROWS_MATCHES(throwsAsInt(1), SpecialException, ExceptionMatcher{1});
348             }
349             SECTION("Contents are wrong") {
350                 CHECK_THROWS_MATCHES(throwsSpecialException(3), SpecialException, ExceptionMatcher{1});
351                 REQUIRE_THROWS_MATCHES(throwsSpecialException(4), SpecialException, ExceptionMatcher{1});
352             }
353         }
354 #endif
355 
356         TEST_CASE("Floating point matchers: float", "[matchers][floating-point]") {
357             SECTION("Relative") {
358                 REQUIRE_THAT(10.f,  WithinRel(11.1f, 0.1f));
359                 REQUIRE_THAT(10.f, !WithinRel(11.2f, 0.1f));
360                 REQUIRE_THAT( 1.f, !WithinRel(0.f, 0.99f));
361                 REQUIRE_THAT(-0.f,  WithinRel(0.f));
362                 SECTION("Some subnormal values") {
363                     auto v1 = std::numeric_limits<float>::min();
364                     auto v2 = v1;
365                     for (int i = 0; i < 5; ++i) {
366                         v2 = std::nextafter(v1, 0.f);
367                     }
368                     REQUIRE_THAT(v1, WithinRel(v2));
369                 }
370             }
371             SECTION("Margin") {
372                 REQUIRE_THAT(1.f, WithinAbs(1.f, 0));
373                 REQUIRE_THAT(0.f, WithinAbs(1.f, 1));
374 
375                 REQUIRE_THAT(0.f, !WithinAbs(1.f, 0.99f));
376                 REQUIRE_THAT(0.f, !WithinAbs(1.f, 0.99f));
377 
378                 REQUIRE_THAT(0.f, WithinAbs(-0.f, 0));
379 
380                 REQUIRE_THAT(11.f, !WithinAbs(10.f, 0.5f));
381                 REQUIRE_THAT(10.f, !WithinAbs(11.f, 0.5f));
382                 REQUIRE_THAT(-10.f, WithinAbs(-10.f, 0.5f));
383                 REQUIRE_THAT(-10.f, WithinAbs(-9.6f, 0.5f));
384             }
385             SECTION("ULPs") {
386                 REQUIRE_THAT(1.f, WithinULP(1.f, 0));
387 
388                 REQUIRE_THAT(nextafter(1.f, 2.f), WithinULP(1.f, 1));
389                 REQUIRE_THAT(0.f, WithinULP(nextafter(0.f, 1.f), 1));
390                 REQUIRE_THAT(1.f, WithinULP(nextafter(1.f, 0.f), 1));
391                 REQUIRE_THAT(1.f, !WithinULP(nextafter(1.f, 2.f), 0));
392 
393                 REQUIRE_THAT(1.f, WithinULP(1.f, 0));
394                 REQUIRE_THAT(-0.f, WithinULP(0.f, 0));
395             }
396             SECTION("Composed") {
397                 REQUIRE_THAT(1.f, WithinAbs(1.f, 0.5) || WithinULP(1.f, 1));
398                 REQUIRE_THAT(1.f, WithinAbs(2.f, 0.5) || WithinULP(1.f, 0));
399                 REQUIRE_THAT(0.0001f, WithinAbs(0.f, 0.001f) || WithinRel(0.f, 0.1f));
400             }
401             SECTION("Constructor validation") {
402                 REQUIRE_NOTHROW(WithinAbs(1.f, 0.f));
403                 REQUIRE_THROWS_AS(WithinAbs(1.f, -1.f), std::domain_error);
404 
405                 REQUIRE_NOTHROW(WithinULP(1.f, 0));
406                 REQUIRE_THROWS_AS(WithinULP(1.f, static_cast<uint64_t>(-1)), std::domain_error);
407 
408                 REQUIRE_NOTHROW(WithinRel(1.f, 0.f));
409                 REQUIRE_THROWS_AS(WithinRel(1.f, -0.2f), std::domain_error);
410                 REQUIRE_THROWS_AS(WithinRel(1.f, 1.f), std::domain_error);
411             }
412         }
413 
414         TEST_CASE("Floating point matchers: double", "[matchers][floating-point]") {
415             SECTION("Relative") {
416                 REQUIRE_THAT(10., WithinRel(11.1, 0.1));
417                 REQUIRE_THAT(10., !WithinRel(11.2, 0.1));
418                 REQUIRE_THAT(1., !WithinRel(0., 0.99));
419                 REQUIRE_THAT(-0., WithinRel(0.));
420                 SECTION("Some subnormal values") {
421                     auto v1 = std::numeric_limits<double>::min();
422                     auto v2 = v1;
423                     for (int i = 0; i < 5; ++i) {
424                         v2 = std::nextafter(v1, 0);
425                     }
426                     REQUIRE_THAT(v1, WithinRel(v2));
427                 }
428             }
429             SECTION("Margin") {
430                 REQUIRE_THAT(1., WithinAbs(1., 0));
431                 REQUIRE_THAT(0., WithinAbs(1., 1));
432 
433                 REQUIRE_THAT(0., !WithinAbs(1., 0.99));
434                 REQUIRE_THAT(0., !WithinAbs(1., 0.99));
435 
436                 REQUIRE_THAT(11., !WithinAbs(10., 0.5));
437                 REQUIRE_THAT(10., !WithinAbs(11., 0.5));
438                 REQUIRE_THAT(-10., WithinAbs(-10., 0.5));
439                 REQUIRE_THAT(-10., WithinAbs(-9.6, 0.5));
440             }
441             SECTION("ULPs") {
442                 REQUIRE_THAT(1., WithinULP(1., 0));
443 
444                 REQUIRE_THAT(nextafter(1., 2.), WithinULP(1., 1));
445                 REQUIRE_THAT(0.,  WithinULP(nextafter(0., 1.), 1));
446                 REQUIRE_THAT(1.,  WithinULP(nextafter(1., 0.), 1));
447                 REQUIRE_THAT(1., !WithinULP(nextafter(1., 2.), 0));
448 
449                 REQUIRE_THAT(1., WithinULP(1., 0));
450                 REQUIRE_THAT(-0., WithinULP(0., 0));
451             }
452             SECTION("Composed") {
453                 REQUIRE_THAT(1., WithinAbs(1., 0.5) || WithinULP(2., 1));
454                 REQUIRE_THAT(1., WithinAbs(2., 0.5) || WithinULP(1., 0));
455                 REQUIRE_THAT(0.0001, WithinAbs(0., 0.001) || WithinRel(0., 0.1));
456             }
457             SECTION("Constructor validation") {
458                 REQUIRE_NOTHROW(WithinAbs(1., 0.));
459                 REQUIRE_THROWS_AS(WithinAbs(1., -1.), std::domain_error);
460 
461                 REQUIRE_NOTHROW(WithinULP(1., 0));
462 
463                 REQUIRE_NOTHROW(WithinRel(1., 0.));
464                 REQUIRE_THROWS_AS(WithinRel(1., -0.2), std::domain_error);
465                 REQUIRE_THROWS_AS(WithinRel(1., 1.), std::domain_error);
466             }
467         }
468 
469         TEST_CASE("Floating point matchers that are problematic in approvals", "[approvals][matchers][floating-point]") {
470             REQUIRE_THAT(NAN, !WithinAbs(NAN, 0));
471             REQUIRE_THAT(NAN, !(WithinAbs(NAN, 100) || WithinULP(NAN, 123)));
472             REQUIRE_THAT(NAN, !WithinULP(NAN, 123));
473             REQUIRE_THAT(INFINITY, WithinRel(INFINITY));
474             REQUIRE_THAT(-INFINITY, !WithinRel(INFINITY));
475             REQUIRE_THAT(1., !WithinRel(INFINITY));
476             REQUIRE_THAT(INFINITY, !WithinRel(1.));
477             REQUIRE_THAT(NAN, !WithinRel(NAN));
478             REQUIRE_THAT(1., !WithinRel(NAN));
479             REQUIRE_THAT(NAN, !WithinRel(1.));
480         }
481 
482         TEST_CASE("Arbitrary predicate matcher", "[matchers][generic]") {
483             SECTION("Function pointer") {
484                 REQUIRE_THAT(1,  Predicate<int>(alwaysTrue, "always true"));
485                 REQUIRE_THAT(1, !Predicate<int>(alwaysFalse, "always false"));
486             }
487             SECTION("Lambdas + different type") {
488                 REQUIRE_THAT("Hello olleH",
489                              Predicate<std::string>(
__anonc5ab40470202(std::string const& str) 490                                  [] (std::string const& str) -> bool { return str.front() == str.back(); },
491                                  "First and last character should be equal")
492                 );
493 
494                 REQUIRE_THAT("This wouldn't pass",
495                              !Predicate<std::string>(
__anonc5ab40470302(std::string const& str) 496                                  [] (std::string const& str) -> bool { return str.front() == str.back(); }
497                              )
498                 );
499             }
500         }
501 
502         TEST_CASE("Regression test #1", "[matchers][vector]") {
503             // At some point, UnorderedEqualsMatcher skipped
504             // mismatched prefixed before doing the comparison itself
505             std::vector<char> actual = { 'a', 'b' };
506             std::vector<char> expected = { 'c', 'b' };
507 
508             CHECK_THAT(actual, !UnorderedEquals(expected));
509         }
510 
511         TEST_CASE("Predicate matcher can accept const char*", "[matchers][compilation]") {
__anonc5ab40470402(const char* const&) 512             REQUIRE_THAT("foo", Predicate<const char*>([] (const char* const&) { return true; }));
513         }
514 
515         TEST_CASE("Vector Approx matcher", "[matchers][approx][vector]") {
516             using Catch::Matchers::Approx;
517             SECTION("Empty vector is roughly equal to an empty vector") {
518                 std::vector<double> empty;
519                 REQUIRE_THAT(empty, Approx(empty));
520             }
521             SECTION("Vectors with elements") {
522                 std::vector<double> v1({1., 2., 3.});
523                 SECTION("A vector is approx equal to itself") {
524                     REQUIRE_THAT(v1, Approx(v1));
525                 }
526                 std::vector<double> v2({1.5, 2.5, 3.5});
527                 SECTION("Different length") {
528                     auto temp(v1);
529                     temp.push_back(4);
530                     REQUIRE_THAT(v1, !Approx(temp));
531                 }
532                 SECTION("Same length, different elements") {
533                     REQUIRE_THAT(v1, !Approx(v2));
534                     REQUIRE_THAT(v1, Approx(v2).margin(0.5));
535                     REQUIRE_THAT(v1, Approx(v2).epsilon(0.5));
536                     REQUIRE_THAT(v1, Approx(v2).epsilon(0.1).scale(500));
537                 }
538             }
539         }
540 
541         TEST_CASE("Vector Approx matcher -- failing", "[matchers][approx][vector][.failing]") {
542             using Catch::Matchers::Approx;
543             SECTION("Empty and non empty vectors are not approx equal") {
544                 std::vector<double> empty, t1({1, 2});
545                 CHECK_THAT(empty, Approx(t1));
546             }
547             SECTION("Just different vectors") {
548                 std::vector<double> v1({2., 4., 6.}), v2({1., 3., 5.});
549                 CHECK_THAT(v1, Approx(v2));
550             }
551         }
552 
553 #if !defined(CATCH_CONFIG_DISABLE_EXCEPTIONS)
554         TEST_CASE("Exceptions matchers", "[matchers][exceptions][!throws]") {
555             REQUIRE_THROWS_MATCHES(throwsDerivedException(),  DerivedException,  Message("DerivedException::what"));
556             REQUIRE_THROWS_MATCHES(throwsDerivedException(),  DerivedException, !Message("derivedexception::what"));
557             REQUIRE_THROWS_MATCHES(throwsSpecialException(2), SpecialException, !Message("DerivedException::what"));
558             REQUIRE_THROWS_MATCHES(throwsSpecialException(2), SpecialException,  Message("SpecialException::what"));
559         }
560 #endif
561 
562         TEST_CASE("Composed matchers are distinct", "[matchers][composed]") {
563             auto m1 = Contains("string");
564             auto m2 = Contains("random");
565             auto composed1 = m1 || m2;
566             auto m3 = Contains("different");
567             auto composed2 = composed1 || m3;
568             REQUIRE_THAT(testStringForMatching2(), !composed1);
569             REQUIRE_THAT(testStringForMatching2(), composed2);
570         }
571 
572 } } // namespace MatchersTests
573 
574 #endif // CATCH_CONFIG_DISABLE_MATCHERS
575 
576 #ifdef __clang__
577 #pragma clang diagnostic pop
578 #endif
579