-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Misleading error reporting when a CHECK calls a REQUIRE #1292
Comments
what an interesting find! the doctest testing framework has the same issue - thanks for reporting! |
Yeah, I can see how that output would be very confusing. |
I ran in the same problem. CATCH_CONFIG_DISABLE_EXCEPTIONS is not set and I get the same error message. I have 2.8.0 at the moment. |
Hi, I've found a very similar case, that result in exactly the same misleading error report.
The root cause is the same, my test runner calls CHECK inside CHECK_THROWS ( Use Trompeloeil with Catch2 ) Example test to reproducestruct Dependency
{
MAKE_MOCK0(Method, void());
};
struct TestObject
{
TestObject(Dependency& d, bool condition)
{
if (condition)
{
// Should throw, but there's a bug...
// throw std::invalid_argument{"invalid condition"};
}
d.Method();
}
};
TEST_CASE("exception")
{
Dependency d{};
FORBID_CALL(d, Method());
CHECK_THROWS_AS(TestObject(d, true), std::runtime_error);
} Tested with Catch v2.13.0 |
I'm also getting this, in my case a REQUIRE() that calls a FAIL() - I configured my logger to fail the test if anything unexpected is outputted to the error stream, so the REQUIRE() assertion calls some code that logs to the error stream which then calls FAIL(). Using v2.7.0 though. |
Is there any workaround for this? Other than disabling exceptions... It keeps randomly popping up in my codebase... sometimes on Linux builds, sometimes on Windows builds only. Happens only on the build server (azure devops). I have a custom assertion handler that can be configured to throw. So don't even have a nested CHECK/REQUIRE... |
reproduced today with Catch v2.13.7.
with code INFO("<INFO stuff>");
REQUIRE_NOTHROW([&]() {
const auto targetDevice = getAvailableDevice(std::chrono::seconds(protocol == X_LINK_TCP_IP ? 60 : 15), protocol);
REQUIRE(std::get<bool>(targetDevice));
device = std::make_unique<dai::Device>(p, std::get<dai::DeviceInfo>(targetDevice));
}()); |
Any update on the issue? Today I ran into the same problem as @slci with trompeloeil mocking framework and was scratching my head what is going on. Tested on 2.13.10. |
Any update or workaround for this? |
This issue occurs for any Catch exception thrown during the evaluation of any assertion macro (i.e. #include <catch2/catch_test_macros.hpp>
void fn() { FAIL("Throw a Catch::TestFailureException"); } // Line 3
TEST_CASE("example") {
SECTION("misleading error message") { // Line 6
CHECK_NOTHROW(fn()); // Line 7
}
SECTION("no misleading error message") { // Line 10
CHECK_THROWS_AS(fn(), Catch::TestFailureException); // Line 11
}
}
Yes, this includes #include <catch2/catch_test_macros.hpp>
void fn() { SKIP("This test should be skipped; it should not fail!"); } // Line 3
TEST_CASE("example") { // Line 5
CHECK((fn(), true)); // Line 6
}
Unless nested test macros are not intended to be supported, this is arguably incorrect test suite behavior, not just a misleading error message. |
Description
If a
CHECK()
assertion internally calls a function that does aREQUIRE()
assertion that fails, we get a very misleading message.Steps to reproduce
Here is the complete test:
Compiled with
-std=c++11
and no other flags, run with no arguments. This emits:Note the message about
CATCH_CONFIG_FAST_COMPILE
- which isn't actually defined here. This is super confusing.Extra information
The text was updated successfully, but these errors were encountered: