Skip to content

Commit 643f0fb

Browse files
authored
Merge pull request #1 from apigear-io/refactor-tests
Rework test and example integration
2 parents ab53bb9 + b5d96d8 commit 643f0fb

13 files changed

+83
-38
lines changed

.github/workflows/cmake-test.yml

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: CMake unit test
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
env:
10+
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
11+
BUILD_TYPE: Release
12+
13+
jobs:
14+
build:
15+
# The CMake configure and build commands are platform agnostic and should work equally
16+
# well on Windows or Mac. You can convert this to a matrix build if you need
17+
# cross-platform coverage.
18+
# See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
19+
runs-on: ${{ matrix.os }}
20+
21+
strategy:
22+
matrix:
23+
os: [macos-latest, ubuntu-latest, windows-latest]
24+
25+
steps:
26+
- uses: actions/checkout@v2
27+
28+
- name: Configure CMake
29+
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
30+
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
31+
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}
32+
33+
- name: Build
34+
# Build your program with the given configuration
35+
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
36+
37+
- name: Test
38+
working-directory: ${{github.workspace}}/build
39+
# Execute tests defined by the CMake configuration.
40+
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
41+
run: ctest -C ${{env.BUILD_TYPE}}
42+

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,6 @@
3030
*.exe
3131
*.out
3232
*.app
33+
34+
# build directory
35+
build/

CMakeLists.txt

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
cmake_minimum_required(VERSION 3.14)
22

3-
if(DEFINED PROJECT_NAME)
4-
set(SUBPROJECT ON)
5-
endif()
6-
3+
option(BUILD_EXAMPLES "Build examples" FALSE)
74

85
set(CMAKE_CXX_STANDARD 11)
96
set(CMAKE_CXX_STANDARD_REQUIRED ON)
@@ -13,11 +10,11 @@ project(objectlink-core-cpp LANGUAGES CXX)
1310

1411
set(CMAKE_INCLUDE_CURRENT_DIR ON)
1512

16-
add_subdirectory (external)
1713
add_subdirectory (src)
14+
add_subdirectory (tests)
1815

1916

20-
if(NOT SUBPROJECT)
17+
if(BUILD_EXAMPLES)
2118
add_subdirectory (examples/app)
2219
add_subdirectory (examples/server)
2320
endif()

external/CMakeLists.txt

-16
This file was deleted.

src/CMakeLists.txt

+9-16
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
set(SPDLOG_DEBUG_ON true)
22
set(SPDLOG_TRACE_ON true)
33

4+
# pull nlohmann json as dependency
5+
include(FetchContent)
6+
7+
FetchContent_Declare(json
8+
GIT_REPOSITORY https://github.com/ArthurSonzogni/nlohmann_json_cmake_fetchcontent
9+
GIT_TAG v3.9.1)
10+
11+
FetchContent_MakeAvailable(json)
12+
413
set(OLINK_SOURCES
514
olink/core/types.cpp
615
olink/core/node.cpp
@@ -24,19 +33,3 @@ add_library (olink_core STATIC ${OLINK_SOURCES} ${OLINK_HEADERS})
2433

2534
target_include_directories (olink_core PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
2635
target_link_libraries(olink_core PUBLIC nlohmann_json::nlohmann_json)
27-
28-
29-
30-
set(TEST_OLINK_SOURCES
31-
tests/test_main.cpp
32-
tests/test_olink.cpp
33-
tests/test_protocol.cpp
34-
tests/sinkobject.hpp
35-
tests/sourceobject.hpp
36-
tests/mocksink.hpp
37-
tests/mocksource.hpp
38-
)
39-
40-
add_executable(tst_olink ${TEST_OLINK_SOURCES})
41-
target_link_libraries(tst_olink PRIVATE olink_core Catch2::Catch2)
42-

tests/CMakeLists.txt

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
set(SPDLOG_DEBUG_ON true)
2+
set(SPDLOG_TRACE_ON true)
3+
4+
Include(FetchContent)
5+
6+
# pull catch2 as dependency
7+
FetchContent_Declare(
8+
Catch2
9+
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
10+
GIT_TAG v2.13.1)
11+
12+
FetchContent_MakeAvailable(Catch2)
13+
14+
set(TEST_OLINK_SOURCES
15+
test_main.cpp
16+
test_olink.cpp
17+
test_protocol.cpp
18+
sinkobject.hpp
19+
sourceobject.hpp
20+
mocksink.hpp
21+
mocksource.hpp
22+
)
23+
24+
add_executable(tst_olink ${TEST_OLINK_SOURCES})
25+
target_link_libraries(tst_olink PRIVATE olink_core Catch2::Catch2)
26+
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 commit comments

Comments
 (0)