-
-
Notifications
You must be signed in to change notification settings - Fork 649
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
REQUIRE_THROWS_AS does not support class constructors #216
Comments
well... you could do what I suggested in this commit in a PR to json: nlohmann/json@5d511a6 basically: have a compatibility header which includes the actual doctest header and have the following in there: #include <doctest/doctest.h>
#undef CHECK_THROWS
#undef CHECK_THROWS_AS
#undef CHECK_THROWS_WITH
#undef CHECK_NOTHROW
#undef REQUIRE_THROWS
#undef REQUIRE_THROWS_AS
#undef REQUIRE_THROWS_WITH
#undef REQUIRE_NOTHROW
// doctest allows multiple statements in these macros (even blocks of code) but json
// tests rely on passing single function/constructor calls which have a [[nodiscard]]
// attribute so here we static_cast to void - just like Catch does
#define CHECK_THROWS(expr) DOCTEST_CHECK_THROWS(static_cast<void>(expr))
#define CHECK_THROWS_AS(expr, e) DOCTEST_CHECK_THROWS_AS(static_cast<void>(expr), e)
#define CHECK_THROWS_WITH(expr, e) DOCTEST_CHECK_THROWS_WITH(static_cast<void>(expr), e)
#define CHECK_NOTHROW(expr) DOCTEST_CHECK_NOTHROW(static_cast<void>(expr))
#define REQUIRE_THROWS(expr) DOCTEST_REQUIRE_THROWS(static_cast<void>(expr))
#define REQUIRE_THROWS_AS(expr, e) DOCTEST_REQUIRE_THROWS_AS(static_cast<void>(expr), e)
#define REQUIRE_THROWS_WITH(expr, e) DOCTEST_REQUIRE_THROWS_WITH(static_cast<void>(expr), e)
#define REQUIRE_NOTHROW(expr) DOCTEST_REQUIRE_NOTHROW(static_cast<void>(expr)) I don't think |
Thanks for your quick reply. I have to admit that I do not fully understand how a Looking further, this looks like an instance of the C++'s most vexing parse. And indeed, here's what clang says:
I wonder what your motivation for not casting is here. To me it is quite reasonable to assert that a particular construction fails... |
The idea is to support arbitrary code - like entire blocks or multiple statements: REQUIRE_THROWS_AS(if (x) { foo(); bar(); }, ex_type);
REQUIRE_THROWS_AS(foo(); bar(), ex_type); But when I think about it - users could just use a lambda - this was a concern when doctest supported C++98... So if I change this it would be a breaking change........... And yes - |
Confirming that |
6 days ago I added the |
Description
I would like to use the
REQUIRE_THROWS_AS
macro with class constructors, not just freestanding functions. The following code results in a build failure for me (GCC 8.1.0, Doctest from the latestdev
):The error:
I know that in this particular scneario I could workaround this via initializing via the uniform construction syntax with curly braces, i.e.,
DriverUnderTest{serial}
, but that's not possible in general becauseFoo{x, y}
andFoo(x, y)
are different constructors (seestd::vector::vector
for example).dev
The text was updated successfully, but these errors were encountered: