Skip to content

Commit 54f50e5

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 54f50e5

File tree

4 files changed

+130
-5
lines changed

4 files changed

+130
-5
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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ include_directories(${gtest_SOURCE_DIR}/include ${gtest_SOURCE_DIR})
134134
########################################
135135
# Test files
136136
########################################
137-
file(GLOB TEST_SRC_FILES ${PROJECT_SOURCE_DIR}/test/*.cpp)
137+
file(GLOB TEST_SRC_FILES ${PROJECT_SOURCE_DIR}/tests/*.cpp)
138138

139139
########################################
140140
# Unit Tests
@@ -149,7 +149,7 @@ target_link_libraries(runUnitTests gtest gtest_main)
149149
########################################
150150
# Extra linking for the project.
151151
########################################
152-
target_link_libraries(runUnitTests project1_lib)
152+
#target_link_libraries(runUnitTests project1_lib)
153153

154154
# This is so you can do 'make test' to see all your tests run, instead of
155155
# manually running the executable runUnitTests to see those specific tests.

deps/googletest

Submodule googletest added at 065127f

0 commit comments

Comments
 (0)