Skip to content

Conversation

@puetzk
Copy link
Contributor

@puetzk puetzk commented Jun 5, 2025

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.

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
@codecov
Copy link

codecov bot commented Jun 5, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ 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           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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

The previous approach buries the list of which trompeloil requirements
were matched in the expansion of the REQUIRE expression:

PASSED:
  REQUIRE( trompeloeil_mock_calls_done_correctly != 0 )
with expansion:
  "spy.rowsAboutToBeInserted(QModelIndex{},1,1)"
  !=
  0

Using SUCCESS puts the real message up front, with no extra quoting.

 PASSED:
with message:
  spy.rowsAboutToBeInserted(QModelIndex{},1,1)

SUCCEED has been available since Catch2 1.2.0
@puetzk puetzk force-pushed the catch2-FAIL_CHECK branch from 3296cf6 to 6ab99d3 Compare August 8, 2025 21:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant