Open bartgol opened 21 hours ago
I see now what you're getting at. The unit test itself had mistakes.
I see now what you're getting at. The unit test itself had mistakes.
Yeah, the macro was fine. But always throwing the same exception does not allow us to differentiate in case we need to throw multiple exceptions in the same call. Besides, it is helpful to be able to throw a specific type of exception, in case the calling code is able to handle SOME type of exceptions but nothers (e.g., a bad cast can be handled, but a bad alloc can't)
Tests pass on mappy.
Motivation
When doing unit tests, I often check that exceptions are raised when appropriate, via something like
But if the function can throw at several points in its execution, this check may not verify the desired behavior. E.g., consdider this
The second
REQUIRE_THROWS
will throw, but NOT b/cj<0
, bur rather b/ci<0
, since we did not change its value back to 2.With this PR, I can do
Now, the test will fail, since the 2nd
REQUIRE_THROWS
will still throwExceptionA
.Note: this change is backward compatible.
Testing
I added a unit test that verifies we can now throw a user-defined exception type.