trompeloeil icon indicating copy to clipboard operation
trompeloeil copied to clipboard

Use FAIL_CHECK macro to report non-fatal failures to Catch2

Open puetzk opened this issue 7 months ago • 1 comments

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).

.../catch2/trompeloeil.hpp(52): 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.

.../catch2/trompeloeil.hpp(52): 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 Catch 1.8.2, i.e. before it was Catch2, so I don't think there's a compatibility concern.

puetzk avatar Jun 05 '25 22:06 puetzk

Codecov Report

:white_check_mark: All modified and coverable lines are covered by tests. :white_check_mark: Project coverage is 99.41%. Comparing base (2a633b9) to head (6ab99d3).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #350   +/-   ##
=======================================
  Coverage   99.41%   99.41%           
=======================================
  Files          15       15           
  Lines        1361     1361           
  Branches       22       21    -1     
=======================================
  Hits         1353     1353           
  Misses          8        8           

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

:rocket: New features to boost your workflow:
  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

codecov[bot] avatar Jun 05 '25 22:06 codecov[bot]