Skip to content

Commit

Permalink
Merge pull request #1 from apigear-io/refactor-tests
Browse files Browse the repository at this point in the history
Rework test and example integration
  • Loading branch information
w4bremer authored Oct 20, 2021
2 parents ab53bb9 + b5d96d8 commit 643f0fb
Show file tree
Hide file tree
Showing 13 changed files with 83 additions and 38 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/cmake-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: CMake unit test

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

env:
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
BUILD_TYPE: Release

jobs:
build:
# The CMake configure and build commands are platform agnostic and should work equally
# well on Windows or Mac. You can convert this to a matrix build if you need
# cross-platform coverage.
# See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
runs-on: ${{ matrix.os }}

strategy:
matrix:
os: [macos-latest, ubuntu-latest, windows-latest]

steps:
- uses: actions/checkout@v2

- name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}

- name: Build
# Build your program with the given configuration
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}

- name: Test
working-directory: ${{github.workspace}}/build
# Execute tests defined by the CMake configuration.
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
run: ctest -C ${{env.BUILD_TYPE}}

3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,6 @@
*.exe
*.out
*.app

# build directory
build/
9 changes: 3 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
cmake_minimum_required(VERSION 3.14)

if(DEFINED PROJECT_NAME)
set(SUBPROJECT ON)
endif()

option(BUILD_EXAMPLES "Build examples" FALSE)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
Expand All @@ -13,11 +10,11 @@ project(objectlink-core-cpp LANGUAGES CXX)

set(CMAKE_INCLUDE_CURRENT_DIR ON)

add_subdirectory (external)
add_subdirectory (src)
add_subdirectory (tests)


if(NOT SUBPROJECT)
if(BUILD_EXAMPLES)
add_subdirectory (examples/app)
add_subdirectory (examples/server)
endif()
16 changes: 0 additions & 16 deletions external/CMakeLists.txt

This file was deleted.

25 changes: 9 additions & 16 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
set(SPDLOG_DEBUG_ON true)
set(SPDLOG_TRACE_ON true)

# pull nlohmann json as dependency
include(FetchContent)

FetchContent_Declare(json
GIT_REPOSITORY https://github.com/ArthurSonzogni/nlohmann_json_cmake_fetchcontent
GIT_TAG v3.9.1)

FetchContent_MakeAvailable(json)

set(OLINK_SOURCES
olink/core/types.cpp
olink/core/node.cpp
Expand All @@ -24,19 +33,3 @@ add_library (olink_core STATIC ${OLINK_SOURCES} ${OLINK_HEADERS})

target_include_directories (olink_core PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(olink_core PUBLIC nlohmann_json::nlohmann_json)



set(TEST_OLINK_SOURCES
tests/test_main.cpp
tests/test_olink.cpp
tests/test_protocol.cpp
tests/sinkobject.hpp
tests/sourceobject.hpp
tests/mocksink.hpp
tests/mocksource.hpp
)

add_executable(tst_olink ${TEST_OLINK_SOURCES})
target_link_libraries(tst_olink PRIVATE olink_core Catch2::Catch2)

26 changes: 26 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
set(SPDLOG_DEBUG_ON true)
set(SPDLOG_TRACE_ON true)

Include(FetchContent)

# pull catch2 as dependency
FetchContent_Declare(
Catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
GIT_TAG v2.13.1)

FetchContent_MakeAvailable(Catch2)

set(TEST_OLINK_SOURCES
test_main.cpp
test_olink.cpp
test_protocol.cpp
sinkobject.hpp
sourceobject.hpp
mocksink.hpp
mocksource.hpp
)

add_executable(tst_olink ${TEST_OLINK_SOURCES})
target_link_libraries(tst_olink PRIVATE olink_core Catch2::Catch2)

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 643f0fb

Please sign in to comment.