Open alabuzhev opened 1 year ago
Maybe create a PR with this macro?
UPD: interface could probably be better, though
This does look like an interesting feature but remember that Catch2 is a C++14 library (with optional C++17 features) so anything requiring C++20 is out of scope until the next major version which as of yet isn't in the works.
Description Testing unhappy paths is as important as testing happy paths, so Catch2 has quite a few useful assertions like
REQUIRE_THROWS
,REQUIRE_THROWS_AS
etc. However, those are run time, and these days a lot of things is happening at compile time. Especially with introduction of constraints and concepts in C++20.It is logical to check that your custom constraint works as expected, i.e. not only accepts valid types, but rejects invalid ones. Validating the happy path is trivial ("it compiles"), the unhappy one - not so much (for obvious reasons). Luckily, C++20 introduced the requires expression, that allows to turn a hard compilation error into a
constexpr false
.It would be nice to have an out-of-the-box assertion for this.
Additional context A new assertion could piggyback on the existing
STATIC_REQUIRE_FALSE
and should be trivial to implement:Compiler Explorer demo: https://godbolt.org/z/hc9WoMrKf