-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Description
Describe the bug
A scoped message logged with the INFO macro is not removed from the buffer if its scope is left due to an exception. Instead the message is reported if later (i.e. outside of the said scope) an assertion macro such as CHECK reports failure.
Expected behavior
The scoped message should be removed from the buffer and not reported outside of its scope, even if the scope is left due to an exception.
Reproduction steps
Create a file named test_scope.cxx with the following content (adjust #include as needed):
#define CATCH_CONFIG_MAIN
#include "catch2/catch.hpp"
TEST_CASE("Scoped message after exception")
{
{
INFO("scope before try block");
}
try {
INFO("inside try block");
throw std::runtime_error("exception");
}
catch (...) {}
CHECK(false);
}Compile and run:
g++ -std=c++11 -o test test_scope.cxx && ./test
A single failure is reported:
test_scope.cxx:15: FAILED:
CHECK( false )
with message:
inside try block
Although the assertion macro is outside of the try block, the reported message includes the scoped message "inside try block" from the try block. That message should have been removed from the buffer when the try block was left with the exception.
The message "scope before try block" is not reported. This is as expected. This additional block has been added only to demonstrate that scoping of messages works, if the scope is not left with an exception. The error also happens, if this additional scope in lines 6-8 is removed from the test_scope.cxx file.
Platform information:
- OS: Linux (CentOS 7)
- Compiler+version: GCC v4.8.5, GCC v10.2.0
- Catch version: v2.13.1
Additional context
The same happens if the exception is thrown by a function called from within the said scope after the INFO macro. In addition, messages logged by such a function are also not removed from the buffer.
The same also happens if the exception is handled for example with REQUIRE_THROWS_WITH.