Exceptions not properly reported when a REQUIRE_THROWS is present
- Dominant language
- C++
- Stars
- 21.5k
- Forks
- 3.5k
- Avg merge
- 3d 16h
- Merged PRs (30d)
- 2
Description
Hi,
The following code does not work properly:
```
#define CATCH_CONFIG_MAIN
#include "tests/catch.hpp" // Catch v2.11.3, Generated: 2020-03-19 13:44:21.042491
#include
static void willThrow(){
throw std::runtime_error("Catch me if you can");
}
TEST_CASE( "My test" ){
REQUIRE_THROWS( willThrow() ); // <--- line 10
willThrow(); // <--- line 11
}
```
**Expected behavior**
I expect Catch to show me that my test fails at line 11.
However, Catch reports the failure at line 10. This is not terrible in this minimal example, but it is very misleading in case there are multiple other lines of code between lines 10 and 11.
```
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
issue is a Catch v2.11.3 host application.
Run with -? for options
-------------------------------------------------------------------------------
My test
-------------------------------------------------------------------------------
CatchIssue.cpp:9
...............................................................................
CatchIssue.cpp:10: FAILED:
{Unknown expression after the reported line}
due to unexpected exception with message:
This fails
===============================================================================
test cases: 1 | 1 failed
assertions: 2 | 1 passed | 1 failed
```
**Reproduction steps**
Build and run (`clang++ -o build/issue CatchIssue.cpp`)
**Platform information:**
- OS: Debian (under the Windows Subsystem for Linux, if that matters)
- Compiler+version: g++ (Debian 8.3.0-6) 8.3.0, same with clang version 7.0.1-8 (tags/RELEASE_701/final)
- Catch version: v2.11.3
Thanks
Contributor guide
Research direction
Reproduce the failure by building CatchIssue.cpp with the shown clang++ command and running it, then trace how REQUIRE_THROWS and the following willThrow() are reported through tests/catch.hpp. Done means the unexpected exception on line 11 is reported at line 11 rather than attributed to the REQUIRE_THROWS on line 10.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- testing-qa
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100