trompeloeil icon indicating copy to clipboard operation
trompeloeil copied to clipboard

catch2/trompeloeil.hpp header requires bigger Catch2 include than is actually needed

Open johnbeard opened this issue 3 years ago • 1 comments

Catch2 v3 is no longer distributed as a single header. If you do this:

#include <catch2/catch_test_macros.hpp>
#include <catch2/trompeloeil.hpp>

Then the CATCH_VERSION_MAJOR will not be set, used here:

https://github.com/rollbear/trompeloeil/blob/6b2742870a4b08e87cf104e2e9e7904c3818275d/include/catch2/trompeloeil.hpp#L19

since that's in #include <catch2/catch_version_macros.hpp>. While this is included in Catch2's catch2/catch_all.hpp, the new split Catch2 headers apparently allow much faster compilation.

catch2/trompeloeil.hpp only actually needs the macros from catch_test_macros.hpp (specifically FAIL, CAPTURE, CHECK and REQUIRE).

It would be better, I think, if the check actually checked for what was used, perhaps like:

#if ! (defined(CATCH_CONFIG_PREFIX_ALL) && defined(CATCH_CHECK)) || (!defined(CATCH_CONFIG_PREFIX_ALL) && defined(CHECK))
#error "Catch2 macros must be defined before including <catch2/trompeloeil.hpp>"
#endif

(or it could do the include itself?)

johnbeard avatar Mar 25 '22 14:03 johnbeard

Thanks. I'll look into it.

rollbear avatar Mar 29 '22 10:03 rollbear

Corrected fix:

#if !((defined(CATCH_CONFIG_PREFIX_ALL) && defined(CATCH_CHECK)) || (!defined(CATCH_CONFIG_PREFIX_ALL) && defined(CHECK)))
#error "Catch2 macros must be defined before including <catch2/trompeloeil.hpp>"
#endif

Was missing parentheses.

ingefredriksen avatar Sep 12 '22 07:09 ingefredriksen