Skip to content

Commit

Permalink
Configure to use Catch2 v2 or v3
Browse files Browse the repository at this point in the history
Signed-off-by: Ed Beroset <[email protected]>
  • Loading branch information
beroset committed Dec 18, 2023
1 parent 39c7605 commit 9262714
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
os: [ubuntu-latest macos-latest]

steps:
- uses: actions/checkout@v2
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ add_subdirectory(config)
add_subdirectory(autodownload)

if (WITH_TEST)
find_package(Catch2 2 REQUIRED)
find_package(Catch2 REQUIRED)
enable_testing()
add_subdirectory(test)
endif()
Expand Down
10 changes: 8 additions & 2 deletions test/AutoProjectTest.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
#include "AutoProject.h"
#include "trim.h"
#define CATCH_CONFIG_MAIN
#include <catch2/catch.hpp>
#if USE_CATCH2_VERSION == 2
# define CATCH_CONFIG_MAIN
# include <catch2/catch.hpp>
#elif USE_CATCH2_VERSION == 3
# include <catch2/catch_test_macros.hpp>
#else
# error "Catch2 version unknown"
#endif

TEST_CASE( "Trim characters and substrings", "[trim]" ) {
SECTION("Can trim using string") {
Expand Down
11 changes: 9 additions & 2 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,15 @@ endif()
file(COPY examples DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
target_link_directories(ConfigFileTest PRIVATE /usr/local/lib)
target_link_directories(AutoProjectTest PRIVATE /usr/local/lib)
target_link_libraries(ConfigFileTest PRIVATE ConfigFile Catch2::Catch2)
target_link_libraries(AutoProjectTest PRIVATE autoproj Catch2::Catch2)
target_compile_definitions(ConfigFileTest PRIVATE USE_CATCH2_VERSION=${Catch2_VERSION_MAJOR})
target_compile_definitions(AutoProjectTest PRIVATE USE_CATCH2_VERSION=${Catch2_VERSION_MAJOR})
if(${Catch2_VERSION_MAJOR} STREQUAL "2")
target_link_libraries(ConfigFileTest PRIVATE ConfigFile Catch2::Catch2)
target_link_libraries(AutoProjectTest PRIVATE autoproj Catch2::Catch2)
else()
target_link_libraries(ConfigFileTest PRIVATE ConfigFile Catch2::Catch2WithMain)
target_link_libraries(AutoProjectTest PRIVATE autoproj Catch2::Catch2WithMain)
endif()
add_test(ConfigFileTest ConfigFileTest)
add_test(AutoProjectTest AutoProjectTest)
add_test(createRandqt ${TESTSCRIPT} examples/randqt.md)
Expand Down
10 changes: 8 additions & 2 deletions test/ConfigFileTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,14 @@
#include <string>
#include <sstream>
#include "ConfigFile.h"
#define CATCH_CONFIG_MAIN
#include <catch2/catch.hpp>
#if USE_CATCH2_VERSION == 2
# define CATCH_CONFIG_MAIN
# include <catch2/catch.hpp>
#elif USE_CATCH2_VERSION == 3
# include <catch2/catch_test_macros.hpp>
#else
# error "Catch2 version unknown"
#endif


TEST_CASE("Configuration file can be opened, read, written, queried", "[configtest]") {
Expand Down

0 comments on commit 9262714

Please sign in to comment.