Skip to content
This repository has been archived by the owner on Apr 19, 2023. It is now read-only.

Commit

Permalink
Update Catch2 to version 3.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
StevenvdSchoot committed Jan 17, 2023
1 parent 5bdc542 commit 6c2e63e
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 16 deletions.
2 changes: 1 addition & 1 deletion conanfile.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Docs at https://docs.conan.io/en/latest/reference/conanfile_txt.html

[requires]
catch2/2.13.9
catch2/3.2.1
cli11/2.2.0
spdlog/1.10.0

Expand Down
16 changes: 6 additions & 10 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ find_package(Catch2 CONFIG REQUIRED)

include(Catch)

add_library(catch_main OBJECT catch_main.cpp)
target_link_libraries(catch_main PUBLIC Catch2::Catch2)
target_link_libraries(catch_main PRIVATE myproject::project_options)

# Provide a simple smoke test to make sure that the CLI works and can display a --help message
add_test(NAME cli.has_help COMMAND intro --help)

Expand All @@ -36,7 +32,7 @@ add_test(NAME cli.version_matches COMMAND intro --version)
set_tests_properties(cli.version_matches PROPERTIES PASS_REGULAR_EXPRESSION "${PROJECT_VERSION}")

add_executable(tests tests.cpp)
target_link_libraries(tests PRIVATE myproject::project_warnings myproject::project_options catch_main)
target_link_libraries(tests PRIVATE myproject::project_warnings myproject::project_options Catch2::Catch2WithMain)

# automatically discover tests that are defined in catch based test files you can modify the unittests. Set TEST_PREFIX
# to whatever you want, or use different for different binaries
Expand All @@ -45,7 +41,7 @@ catch_discover_tests(
TEST_PREFIX
"unittests."
REPORTER
xml
XML
OUTPUT_DIR
.
OUTPUT_PREFIX
Expand All @@ -55,14 +51,14 @@ catch_discover_tests(

# Add a file containing a set of constexpr tests
add_executable(constexpr_tests constexpr_tests.cpp)
target_link_libraries(constexpr_tests PRIVATE myproject::project_options myproject::project_warnings catch_main)
target_link_libraries(constexpr_tests PRIVATE myproject::project_options myproject::project_warnings Catch2::Catch2WithMain)

catch_discover_tests(
constexpr_tests
TEST_PREFIX
"constexpr."
REPORTER
xml
XML
OUTPUT_DIR
.
OUTPUT_PREFIX
Expand All @@ -73,15 +69,15 @@ catch_discover_tests(
# Disable the constexpr portion of the test, and build again this allows us to have an executable that we can debug when
# things go wrong with the constexpr testing
add_executable(relaxed_constexpr_tests constexpr_tests.cpp)
target_link_libraries(relaxed_constexpr_tests PRIVATE myproject::project_options myproject::project_warnings catch_main)
target_link_libraries(relaxed_constexpr_tests PRIVATE myproject::project_options myproject::project_warnings Catch2::Catch2WithMain)
target_compile_definitions(relaxed_constexpr_tests PRIVATE -DCATCH_CONFIG_RUNTIME_STATIC_REQUIRE)

catch_discover_tests(
relaxed_constexpr_tests
TEST_PREFIX
"relaxed_constexpr."
REPORTER
xml
XML
OUTPUT_DIR
.
OUTPUT_PREFIX
Expand Down
3 changes: 0 additions & 3 deletions test/catch_main.cpp

This file was deleted.

2 changes: 1 addition & 1 deletion test/constexpr_tests.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <catch2/catch.hpp>
#include <catch2/catch_test_macros.hpp>

constexpr unsigned int Factorial(unsigned int number)// NOLINT(misc-no-recursion)
{
Expand Down
2 changes: 1 addition & 1 deletion test/tests.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <catch2/catch.hpp>
#include <catch2/catch_test_macros.hpp>

unsigned int Factorial(unsigned int number)// NOLINT(misc-no-recursion)
{
Expand Down

2 comments on commit 6c2e63e

@viniciusferrao
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you was able to change the myproject name with this patch? I tried it and it broke CMake:

 CMake Warning (dev) at CMakeLists.txt:144 (message):
   Building Tests.  Be sure to check out test/constexpr_tests.cpp for
   constexpr testing
 This warning is for project developers.  Use -Wno-dev to suppress it.
 CMake Error at test/CMakeLists.txt:10 (find_package):
   Could not find a package configuration file provided by "newprojectname" with
   any of the following names:

     newprojectnameConfig.cmake
     newprojectname-config.cmake

   Add the installation prefix of "newprojectname" to CMAKE_PREFIX_PATH or set
   "newprojectname_DIR" to a directory containing one of the above files.  If
   "newprojectname" provides a separate development package or SDK, be sure it
   has been installed.

 Configuring incomplete, errors occurred!
 See also "/tmp/newprojectname/build/CMakeFiles/CMakeOutput.log".

@StevenvdSchoot
Copy link
Author

@StevenvdSchoot StevenvdSchoot commented on 6c2e63e Jan 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you was able to change the myproject name with this patch? I tried it and it broke CMake:

 CMake Warning (dev) at CMakeLists.txt:144 (message):
   Building Tests.  Be sure to check out test/constexpr_tests.cpp for
   constexpr testing
 This warning is for project developers.  Use -Wno-dev to suppress it.
 CMake Error at test/CMakeLists.txt:10 (find_package):
   Could not find a package configuration file provided by "newprojectname" with
   any of the following names:

     newprojectnameConfig.cmake
     newprojectname-config.cmake

   Add the installation prefix of "newprojectname" to CMAKE_PREFIX_PATH or set
   "newprojectname_DIR" to a directory containing one of the above files.  If
   "newprojectname" provides a separate development package or SDK, be sure it
   has been installed.

 Configuring incomplete, errors occurred!
 See also "/tmp/newprojectname/build/CMakeFiles/CMakeOutput.log".

I am assuming you used test/CMakeLists.txt as the toplevel project when configuring. In that case you will have to install or otherwise provide a build, including xConfig.cmake file, to the test project. If you rename the project you will not only have to rename it in test/CMakeLists.txt and CMakeLists.txt, but also build and install using the new name.

Tbh, I'm not sure what the intended usecase is providing the option to use the tests a s a standalone project, maybe someone else can comment on how you are intended to use this? It works the same before and after this commit though ;)

Please sign in to comment.