Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/docs
diff options
context:
space:
mode:
authorMartin Hořeňovský2026-01-08 14:35:05 +0100
committerMartin Hořeňovský2026-01-11 14:53:08 +0100
commit2580eadc4230eedf1b66841bdd27a8aacc2412a5 (patch)
treeba8508f3ab737c0b9d11a2fd5c33d0bdbfcd457e /docs
parentb59f4f352291a89c4a3fe1488eeccbddeea85625 (diff)
downloadcatch3-2580eadc4230eedf1b66841bdd27a8aacc2412a5.tar.gz
Add UNSCOPED_CAPTURE
Closes #2954 Closes #3010
Diffstat (limited to 'docs')
-rw-r--r--docs/configuration.md2
-rw-r--r--docs/logging.md33
2 files changed, 23 insertions, 12 deletions
diff --git a/docs/configuration.md b/docs/configuration.md
index 527a3f82..35867104 100644
--- a/docs/configuration.md
+++ b/docs/configuration.md
@@ -29,7 +29,7 @@ with the same name.
## Prefixing Catch macros
CATCH_CONFIG_PREFIX_ALL // Prefix all macros with CATCH_
- CATCH_CONFIG_PREFIX_MESSAGES // Prefix only INFO, UNSCOPED_INFO, WARN and CAPTURE
+ CATCH_CONFIG_PREFIX_MESSAGES // Prefix only message macros ((UNSCOPED_)INFO, WARN, (UNSCOPED_)CAPTURE)
To keep test code clean and uncluttered Catch uses short macro names (e.g. ```TEST_CASE``` and ```REQUIRE```). Occasionally these may conflict with identifiers from platform headers or the system under test. In this case the above identifier can be defined. This will cause all the Catch user macros to be prefixed with ```CATCH_``` (e.g. ```CATCH_TEST_CASE``` and ```CATCH_REQUIRE```).
diff --git a/docs/logging.md b/docs/logging.md
index 1da97749..371c80ad 100644
--- a/docs/logging.md
+++ b/docs/logging.md
@@ -26,19 +26,22 @@ started" and "Section B", while the third one will only report "Test case
started" as the extra info.
-## Logging without local scope
+## Logging outside of current scope
-> [Introduced](https://github.com/catchorg/Catch2/issues/1522) in Catch2 2.7.0.
+> `UNSCOPED_INFO` was [introduced](https://github.com/catchorg/Catch2/issues/1522) in Catch2 2.7.0.
-`UNSCOPED_INFO` is similar to `INFO` with two key differences:
+> `UNSCOPED_CAPTURE` was introduced in Catch2 X.Y.Z.
-- Lifetime of an unscoped message is not tied to its own scope.
-- An unscoped message can be reported by the first following assertion only, regardless of the result of that assertion.
+The `UNSCOPED_X` macros are similar to their plain `X` macro counterparts,
+with two key differences:
-In other words, lifetime of `UNSCOPED_INFO` is limited by the following assertion (or by the end of test case/section, whichever comes first) whereas lifetime of `INFO` is limited by its own scope.
+- The lifetime of an unscoped message is not tied to its own scope.
+- An unscoped message can be reported by the first following assertion only, regardless of the result of that assertion.
-These differences make this macro useful for reporting information from helper functions or inner scopes. An example:
+In other words, the `UNSCOPED_X` macros are useful to add extra information
+to the next assertion, e.g. from helper functions or inner scopes.
+An example:
```cpp
void print_some_info() {
UNSCOPED_INFO("Info from helper");
@@ -83,9 +86,16 @@ Second info
Second unscoped info
```
+Note that unscoped messages are not passed between test cases, even if
+there were no assertions between them.
+
+
## Streaming macros
-All these macros allow heterogeneous sequences of values to be streaming using the insertion operator (```<<```) in the same way that std::ostream, std::cout, etc support it.
+Apart from `CAPTURE` (and its close sibling, `UNSCOPED_CAPTURE`), message
+macros support gradual streaming of messages and values in the same way
+that the standard streams do.
+
E.g.:
```c++
@@ -99,9 +109,6 @@ These macros come in three forms:
The message is logged to a buffer, but only reported with next assertions that are logged. This allows you to log contextual information in case of failures which is not shown during a successful test run (for the console reporter, without -s). Messages are removed from the buffer at the end of their scope, so may be used, for example, in loops.
-_Note that in Catch2 2.x.x `INFO` can be used without a trailing semicolon as there is a trailing semicolon inside macro.
-This semicolon will be removed with next major version. It is highly advised to use a trailing semicolon after `INFO` macro._
-
**UNSCOPED_INFO(** _message expression_ **)**
> [Introduced](https://github.com/catchorg/Catch2/issues/1522) in Catch2 2.7.0.
@@ -128,6 +135,10 @@ AS `FAIL`, but does not abort the test
**CAPTURE(** _expression1_, _expression2_, ... **)**
+**UNSCOPED_CAPTURE(** _expression1_, _expression2_, ... **)**
+
+> `UNSCOPED_CAPTURE` was introduced in Catch2 X.Y.Z.
+
Sometimes you just want to log a value of variable, or expression. For
convenience, we provide the `CAPTURE` macro, that can take a variable,
or an expression, and prints out that variable/expression and its value