Description
I don't have much exp with catch2. Though I think it wouldn't take much work to setup. This site shows an example of how to add catch2 via cmake: https://cliutils.gitlab.io/modern-cmake/chapters/projects/fetch.html
https://github.com/catchorg/Catch2/blob/devel/docs/other-macros.md shows STATIC_REQUIRE which can be used as a static_assert but it'll show as a pass or fail instead of just failing to compile. Since the code is constexpr I figure something like this would be a good way to go.
Or maybe we could try https://github.com/boost-ext/ut
From the talks I saw it seems neat. I don't know if it's got a static_require like thing or if it needs it. To test the constexpr, since this just uses lambdas, is just assign to a constexpr variable in the lambda and require it to be true.
example ut.cmake file.
enable_testing()
include(FetchContent)
FetchContent_Declare(
ut
GIT_REPOSITORY https://github.com/boost-ext/ut.git
GIT_TAG v1.1.8
)
#FetchContent_MakeAvailable(ut) #includes everything
#Below filters out building stuff in this repo when you build all.
FetchContent_GetProperties(ut)
if(NOT ut_POPULATED)
FetchContent_Populate(ut)
add_subdirectory(${ut_SOURCE_DIR} ${ut_BINARY_DIR} EXCLUDE_FROM_ALL)
endif()
To use this afterwards: (based on example on ut's readme)
include(cmake/ut.cmake)
add_executable(ut_1
ut_1.cpp)
target_link_libraries(ut_1 PRIVATE boost::ut)