Skip to content

Commit

Permalink
Update workflow to use catch2
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 a22f7e1 commit c394c7c
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 14 deletions.
14 changes: 5 additions & 9 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
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 3 REQUIRED)
find_package(Catch2 REQUIRED)
enable_testing()
add_subdirectory(test)
endif()
Expand Down
9 changes: 8 additions & 1 deletion test/AutoProjectTest.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
#include "AutoProject.h"
#include "trim.h"
#include <catch2/catch_test_macros.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::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)
Expand Down
9 changes: 8 additions & 1 deletion test/ConfigFileTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@
#include <string>
#include <sstream>
#include "ConfigFile.h"
#include <catch2/catch_test_macros.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 c394c7c

Please sign in to comment.