Skip to content

Commit 29169e6

Browse files
committed
Use FAIL_CHECK macro to report non-fatal failures to Catch2
This avoids a two-step dance of first capturing a local variable and then doing a roundabout CHECK(false); The previous approach produces a somewhat cluttered error message, that primarily describes the expression `failure.empty() == false`, showing the real issue only as an extra "failure := "..." variable (which is presented as a quoted value, and possible truncated). FAILED: CHECK( failure.empty() ) with expansion: false with message: failure := "test.cpp:15 Unfulfilled expectation: Expected mock.foo(42) to be called once, actually never called param _1 == 42 " Using FAIL_CHECK puts the real message up front, with no extra quoting. Like CHECK(false) (but unlike FAIL) it allows execution to continue. FAILED: explicitly with message: test.cpp:15 Unfulfilled expectation: Expected mock.foo(42) to be called once, actually never called param _1 == 42 FAIL_CHECK has been available since Catch2 1.8.2
1 parent 2a633b9 commit 29169e6

File tree

2 files changed

+3
-6
lines changed

2 files changed

+3
-6
lines changed

docs/CookBook.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,8 +286,7 @@ Before running any tests, make sure to call:
286286
}
287287
else
288288
{
289-
CAPTURE(failure);
290-
CHECK(failure.empty());
289+
FAIL_CHECK(failure);
291290
}
292291
});
293292
```

include/catch2/trompeloeil.hpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,9 @@ namespace trompeloeil
4747
else
4848
{
4949
#ifdef CATCH_CONFIG_PREFIX_ALL
50-
CATCH_CAPTURE(failure);
51-
CATCH_CHECK(failure.empty());
50+
CATCH_FAIL_CHECK(failure);
5251
#else
53-
CAPTURE(failure);
54-
CHECK(failure.empty());
52+
FAIL_CHECK(failure);
5553
#endif
5654
}
5755
}

0 commit comments

Comments
 (0)