From c394c7c8dd3c5b5988fe42c9627f0ca7f28da3f2 Mon Sep 17 00:00:00 2001 From: Ed Beroset Date: Mon, 18 Dec 2023 08:21:24 -0500 Subject: [PATCH] Update workflow to use catch2 Signed-off-by: Ed Beroset --- .github/workflows/cmake.yml | 14 +++++--------- CMakeLists.txt | 2 +- test/AutoProjectTest.cpp | 9 ++++++++- test/CMakeLists.txt | 11 +++++++++-- test/ConfigFileTest.cpp | 9 ++++++++- 5 files changed, 31 insertions(+), 14 deletions(-) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index bf0d2e5..990892e 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -15,21 +15,19 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - os: [macos-latest, windows-latest, ubuntu-latest] + os: [macos-latest, ubuntu-latest] steps: - uses: actions/checkout@v2 - - name: Install cppunit + - name: Install catch2 run: | if [ "$RUNNER_OS" == "Linux" ]; then sudo apt-get update - sudo apt-get install libcppunit-dev - elif [ "$RUNNER_OS" == "Windows" ]; then - echo "Windows does not support cppunit testing" + sudo apt-get install catch2 elif [ "$RUNNER_OS" == "macOS" ]; then brew update - brew install cppunit + brew install catch2 else echo "$RUNNER_OS is not supported" exit 1 @@ -50,9 +48,7 @@ jobs: # and build directories, but this is only available with CMake 3.13 and higher. # The CMake binaries on the Github Actions machines are (as of this writing) 3.12 run: | - if [ "$RUNNER_OS" == "Windows" ]; then - cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DWITH_TEST=OFF - elif [ "$RUNNER_OS" == "macOS" ]; then + if [ "$RUNNER_OS" == "macOS" ]; then cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DWITH_TEST=ON else cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DWITH_TEST=ON diff --git a/CMakeLists.txt b/CMakeLists.txt index c954c7e..cb492ba 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -36,7 +36,7 @@ add_subdirectory(config) add_subdirectory(autodownload) if (WITH_TEST) - find_package(Catch2 3 REQUIRED) + find_package(Catch2 REQUIRED) enable_testing() add_subdirectory(test) endif() diff --git a/test/AutoProjectTest.cpp b/test/AutoProjectTest.cpp index c7ec226..0275ec2 100644 --- a/test/AutoProjectTest.cpp +++ b/test/AutoProjectTest.cpp @@ -1,6 +1,13 @@ #include "AutoProject.h" #include "trim.h" -#include +#if USE_CATCH2_VERSION == 2 +# define CATCH_CONFIG_MAIN +# include +#elif USE_CATCH2_VERSION == 3 +# include +#else +# error "Catch2 version unknown" +#endif TEST_CASE( "Trim characters and substrings", "[trim]" ) { SECTION("Can trim using string") { diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index d8ae4f3..e9af30c 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -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::Catch2WithMain) -target_link_libraries(AutoProjectTest PRIVATE autoproj Catch2::Catch2WithMain) +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) diff --git a/test/ConfigFileTest.cpp b/test/ConfigFileTest.cpp index 39db35b..671fc48 100644 --- a/test/ConfigFileTest.cpp +++ b/test/ConfigFileTest.cpp @@ -4,7 +4,14 @@ #include #include #include "ConfigFile.h" -#include +#if USE_CATCH2_VERSION == 2 +# define CATCH_CONFIG_MAIN +# include +#elif USE_CATCH2_VERSION == 3 +# include +#else +# error "Catch2 version unknown" +#endif TEST_CASE("Configuration file can be opened, read, written, queried", "[configtest]") {