boostorg / boostorg/test

BOOST_CHECK_EXCEPTION does not report an error when actual thrown type is different than the expected thrown type

Open
#294 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
213
Forks
149
Avg merge
18h 17m
Merged PRs (30d)
2

Description

Example code:

```
BOOST_CHECK_EXCEPTION(
throw std::logic_error("A Logic Error"),
std::runtime_error,
[] (const std::runtime_error& e) -> bool { return true; }
);
```
I would expect this to report that the wrong exception was thrown. Indeed, the documentation for this macro seems to indicate that a report on the wrong exception is desired: https://www.boost.org/doc/libs/1_35_0/libs/test/doc/components/test_tools/reference/BOOST_CHECK_EXCEPTION.html

That link states that

> In case if exception does not comply to specified predicate the tool produces an error message in a form "error in : incorrect exception is caught.

Instead of an error report, the logic_error is not caught at all and bubbles up to the test suite engine. This seems to be because of the implementation of BOOST_CHECK_THROW_IMPL here: https://github.com/boostorg/test/blob/develop/include/boost/test/tools/interface.hpp#L174. That implementation only catches the *expected* type instead of all types to check if the correct type was caught.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.