catchorg / catchorg/Catch2

Feature Request: Implementing custom failure message for REQUIRE/CHECK macros

Open
#2,653 3 comments 35 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
21.5k
Forks
3.5k
Avg merge
3d 16h
Merged PRs (30d)
2

Description

**Description**

I suggest catch2 to implement a semantic to display some messages only in case of failures. [GoogleTest](http://google.github.io/googletest/reference/assertions.html) has it in this form:

```
EXPECT_TRUE(false) << "Something went wrong";
```

[CppUnit](https://cppunit.sourceforge.net/doc/cvs/group___assertions.html) has it in this form:

```
CPPUNIT_ASSERT_MESSAGE(message, condition)
```

[Boost](https://www.boost.org/doc/libs/1_61_0/libs/assert/assert.html#BOOST_ASSERT_MSG) has it in this form:

```
BOOST_ASSERT_MSG(expr, msg)
```

Microsoft unit testing [framework](https://learn.microsoft.com/en-us/visualstudio/test/microsoft-visualstudio-testtools-cppunittestframework-api-reference?view=vs-2022#general_is_True) for c++ has it in this form:

```
Assert::IsTrue(condition, message)
```

I'm not suggesting how to implement it but I believe a facility to implement the same semantics should exist in Catch2 as well. I understand the desire to keep the number of macros small and not have a hell of AssertTrue, AssertFalse, AssertEqual, etc. , but what I'm asking is something that can't be replaced by formulating the condition in a different way.

**Additional context**

This is the same request as in https://github.com/catchorg/Catch2/issues/929 , that was closed by its author when explained to use `INFO` instead. Other people in the issue (including me) intervened to ask for the same semantics because the use of `INFO` is not really a replacement.

Contributor guide

Open the contributing guide

Research direction

The issue names no files, tests, or entry points. Start by reading the Catch2 assertion and diagnostic documentation alongside the linked GoogleTest, CppUnit, Boost, and Microsoft examples; done requires an agreed failure-only message facility with defined macro semantics and coverage for the requested behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
testing-qa
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Active
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.