Skip to content

Commit 6eb16d2

Browse files
committed
Add Test infrastructure
This adds googletest to enable unit tests. Made a directory and integrated it into CMake. Also created an basic workflow for github to run the tests. Integration into VS is missing
1 parent b91b900 commit 6eb16d2

File tree

5 files changed

+184
-42
lines changed

5 files changed

+184
-42
lines changed

.github/workflows/tests_cmake.yml

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
# This workflow uses actions that are not certified by GitHub.
2+
# They are provided by a third-party and are governed by
3+
# separate terms of service, privacy policy, and support
4+
# documentation.
5+
6+
name: "Build server (CMake)"
7+
8+
on:
9+
push:
10+
branches:
11+
- master
12+
13+
paths:
14+
- '.github/workflows/tests_cmake.yml'
15+
16+
pull_request:
17+
branches:
18+
- master
19+
20+
paths:
21+
- '.github/workflows/tests_cmake.yml'
22+
23+
workflow_dispatch:
24+
25+
jobs:
26+
build_windows:
27+
runs-on: windows-latest
28+
29+
strategy:
30+
matrix:
31+
BUILD_CONFIGURATION: [Debug, Release]
32+
BUILD_PLATFORM: [Win32, x64]
33+
34+
name: "Server: ${{ matrix.BUILD_CONFIGURATION }} - ${{ matrix.BUILD_PLATFORM }} (Windows)"
35+
36+
steps:
37+
- uses: actions/checkout@v4
38+
with:
39+
submodules: 'false'
40+
41+
- uses: lukka/get-cmake@latest
42+
43+
- name: Configure CMake
44+
shell: bash
45+
run: |
46+
cmake -S . \
47+
-B build-windows-${{ matrix.BUILD_CONFIGURATION }}-${{ matrix.BUILD_PLATFORM }} \
48+
-G "Visual Studio 17 2022" \
49+
-A ${{ matrix.BUILD_PLATFORM }} \
50+
-DCMAKE_BUILD_TYPE=${{ matrix.BUILD_CONFIGURATION }}
51+
52+
- name: Build server
53+
shell: bash
54+
run: |
55+
cmake \
56+
--build build-windows-${{ matrix.BUILD_CONFIGURATION }}-${{ matrix.BUILD_PLATFORM }} \
57+
--config ${{ matrix.BUILD_CONFIGURATION }}
58+
59+
- name: Run tests
60+
shell: bash
61+
working-directory: build-windows-${{ matrix.BUILD_CONFIGURATION }}-${{ matrix.BUILD_PLATFORM }}
62+
run: |
63+
ctest
64+
65+
build_linux:
66+
runs-on: ubuntu-latest
67+
68+
strategy:
69+
matrix:
70+
BUILD_CONFIGURATION: [Debug, Release]
71+
COMPILER: [gcc, clang, clang-20]
72+
73+
env:
74+
clang-latest-version: 20
75+
76+
name: "Server: ${{ matrix.BUILD_CONFIGURATION }} - ${{ matrix.COMPILER }} (Linux)"
77+
78+
steps:
79+
- uses: actions/checkout@v4
80+
with:
81+
submodules: 'false'
82+
83+
- name: Install unixODBC
84+
run: sudo apt-get install unixodbc-dev -y
85+
86+
- uses: lukka/get-cmake@latest
87+
88+
- name: Setup compiler
89+
run: |
90+
if [ "${{ matrix.COMPILER }}" = "gcc" ]; then
91+
export CC=gcc
92+
export CXX=g++
93+
elif [ "${{ matrix.COMPILER }}" = "clang" ]; then
94+
export CC=clang
95+
export CXX=clang++
96+
else
97+
wget https://apt.llvm.org/llvm.sh
98+
chmod +x llvm.sh
99+
sudo ./llvm.sh ${{ env.clang-latest-version }}
100+
sudo apt-get update
101+
export CC=clang-${{ env.clang-latest-version }}
102+
export CXX=clang++-${{ env.clang-latest-version }}
103+
fi
104+
echo "CC=$CC" >> $GITHUB_ENV
105+
echo "CXX=$CXX" >> $GITHUB_ENV
106+
107+
- name: Configure CMake
108+
run: |
109+
cmake -S . \
110+
-B build-${{ matrix.COMPILER }}-${{ matrix.BUILD_CONFIGURATION }} \
111+
-G "Ninja" \
112+
-DCMAKE_BUILD_TYPE=${{ matrix.BUILD_CONFIGURATION }}
113+
114+
- name: Build server
115+
run: |
116+
cmake \
117+
--build build-${{ matrix.COMPILER }}-${{ matrix.BUILD_CONFIGURATION }} \
118+
--config ${{ matrix.BUILD_CONFIGURATION }}
119+
120+
- name: Run tests
121+
shell: bash
122+
working-directory: build-${{ matrix.COMPILER }}-${{ matrix.BUILD_CONFIGURATION }}
123+
run: |
124+
ctest

.gitmodules

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,6 @@
6464
url = https://github.com/p-ranav/argparse
6565
shallow = true
6666
[submodule "deps/googletest"]
67-
path = deps/googletest
68-
url = https://github.com/google/googletest
69-
shallow = true
67+
path = deps/googletest
68+
url = https://github.com/google/googletest.git
69+
shallow = true

CMakeLists.txt

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -115,42 +115,4 @@ if(OPENKO_BUILD_SERVERS)
115115
add_subdirectory(Server/VersionManager)
116116
endif()
117117

118-
119-
########################################
120-
# Testing
121-
########################################
122-
# Options. Turn on with 'cmake -Dmyvarname=ON'.
123-
# option(BUILD_TESTS "Build all tests." ON) # Makes boolean 'test' available.
124-
125-
# google test is a git submodule for the project, and it is also cmake-based
126-
add_subdirectory(./deps/googletest)
127-
128-
enable_testing()
129-
#
130-
# Include the gtest library. gtest_SOURCE_DIR is available due to
131-
# 'project(gtest)' above.
132-
include_directories(${gtest_SOURCE_DIR}/include ${gtest_SOURCE_DIR})
133-
134-
########################################
135-
# Test files
136-
########################################
137-
file(GLOB TEST_SRC_FILES ${PROJECT_SOURCE_DIR}/test/*.cpp)
138-
139-
########################################
140-
# Unit Tests
141-
########################################
142-
add_executable(runUnitTests ${TEST_SRC_FILES})
143-
144-
########################################
145-
# Standard linking to gtest stuff.
146-
########################################
147-
target_link_libraries(runUnitTests gtest gtest_main)
148-
149-
########################################
150-
# Extra linking for the project.
151-
########################################
152-
target_link_libraries(runUnitTests project1_lib)
153-
154-
# This is so you can do 'make test' to see all your tests run, instead of
155-
# manually running the executable runUnitTests to see those specific tests.
156-
add_test(UnitTests runUnitTests)
118+
add_subdirectory(deps/googletest-cmake)

deps/googletest

Submodule googletest added at 065127f
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
fetchcontent_declare(
2+
googletest
3+
GIT_REPOSITORY "https://github.com/google/googletest.git"
4+
GIT_TAG "v1.17.0"
5+
GIT_PROGRESS ON
6+
GIT_SHALLOW ON
7+
OVERRIDE_FIND_PACKAGE TRUE
8+
EXCLUDE_FROM_ALL
9+
)
10+
11+
message(STATUS "OpenKO: [googletest] Checking and fetching...")
12+
13+
fetchcontent_makeavailable(googletest)
14+
15+
message(STATUS "OpenKO: [googletest] Up-to-date!")
16+
17+
18+
########################################
19+
# Testing
20+
########################################
21+
# Options. Turn on with 'cmake -Dmyvarname=ON'.
22+
# option(BUILD_TESTS "Build all tests." ON) # Makes boolean 'test' available.
23+
24+
# google test is a git submodule for the project, and it is also cmake-based
25+
#add_subdirectory(./deps/googletest)
26+
27+
enable_testing()
28+
#
29+
# Include the gtest library. gtest_SOURCE_DIR is available due to
30+
# 'project(gtest)' above.
31+
include_directories(${gtest_SOURCE_DIR}/include ${gtest_SOURCE_DIR})
32+
33+
########################################
34+
# Test files
35+
########################################
36+
file(GLOB TEST_SRC_FILES ${PROJECT_SOURCE_DIR}/tests/*.cpp)
37+
38+
########################################
39+
# Unit Tests
40+
########################################
41+
add_executable(runUnitTests ${TEST_SRC_FILES})
42+
43+
########################################
44+
# Standard linking to gtest stuff.
45+
########################################
46+
target_link_libraries(runUnitTests gtest gtest_main)
47+
48+
########################################
49+
# Extra linking for the project.
50+
########################################
51+
#target_link_libraries(runUnitTests project1_lib)
52+
53+
# This is so you can do 'make test' to see all your tests run, instead of
54+
# manually running the executable runUnitTests to see those specific tests.
55+
add_test(UnitTests runUnitTests)

0 commit comments

Comments
 (0)