Wire Sysio Wire Sysion 1.0.0
|
Additional messages can be logged during a test case. Note that the messages logged with INFO
are scoped and thus will not be reported if failure occurs in scope preceding the message declaration. An example:
When the CHECK
fails in the "Foo" test case, then two messages will be printed.
When the last CHECK
fails in the "Bar" test case, then only one message will be printed: Test case start
.
UNSCOPED_INFO
is similar to INFO
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.
These differences make this macro useful for reporting information from helper functions or inner scopes. An example:
"Baz" test case prints:
With "Qux" test case, two messages will be printed when the first CHECK
fails:
"First unscoped info" message will be cleared after the first CHECK
, while "First info" message will persist until the end of the test case. Therefore, when the second CHECK
fails, three messages will be printed:
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.
E.g.:
(Note that there is no initial <<
- instead the insertion sequence is placed in parentheses.) These macros come in three forms:
INFO(** message expression **)
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 **)
Similar to INFO
, but messages are not limited to their own scope: They are removed from the buffer after each assertion, section or test case, whichever comes first.
WARN(** message expression **)
The message is always reported but does not fail the test.
FAIL(** message expression **)
The message is reported and the test case fails.
FAIL_CHECK(** message expression **)
AS FAIL
, but does not abort the test
CAPTURE(** expression1, expression2, ... **)
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 at the time of capture.
e.g. CAPTURE( theAnswer );
will log message "theAnswer := 42", while
will log a total of 6 messages:
You can also capture expressions that use commas inside parentheses (e.g. function calls), brackets, or braces (e.g. initializers). To properly capture expression that contains template parameters list (in other words, it contains commas between angle brackets), you need to enclose the expression inside parentheses: CAPTURE( (std::pair<int, int>{1, 2}) );