Skip to content

Commit 95b72f8

Browse files
author
pfeatherstone
committed
Unit tests moved and added CI/CD
1 parent 208b56f commit 95b72f8

File tree

7 files changed

+122
-41
lines changed

7 files changed

+122
-41
lines changed

.github/workflows/ci.yml

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches:
6+
- '**'
7+
pull_request:
8+
branches:
9+
- '**'
10+
11+
env:
12+
CMAKE_VERSION: '3.31.7'
13+
CMAKE_INSTALL_DIR: '${{ github.workspace }}/.cmake'
14+
CMAKE_BIN: '${{ github.workspace }}/.cmake/bin/cmake'
15+
TEST_RESULTS_DIR: '${{ github.workspace }}/test-results'
16+
17+
jobs:
18+
build-and-test:
19+
strategy:
20+
matrix:
21+
include:
22+
- name: Ubuntu-20.04-GCC
23+
os: ubuntu-20.04
24+
cc: gcc
25+
cxx: g++
26+
- name: Ubuntu-20.04-Clang
27+
os: ubuntu-20.04
28+
cc: clang
29+
cxx: clang++
30+
- name: Ubuntu-22.04-GCC
31+
os: ubuntu-22.04
32+
cc: gcc
33+
cxx: g++
34+
- name: Ubuntu-22.04-Clang
35+
os: ubuntu-22.04
36+
cc: clang
37+
cxx: clang++
38+
- name: Ubuntu-24.04-GCC
39+
os: ubuntu-24.04
40+
cc: gcc
41+
cxx: g++
42+
- name: Ubuntu-24.04-Clang
43+
os: ubuntu-24.04
44+
cc: clang
45+
cxx: clang++
46+
- name: Ubuntu-22.04-GCC-FFTW
47+
os: ubuntu-22.04
48+
cc: gcc
49+
cxx: g++
50+
extra_packages: libfftw3-dev
51+
52+
runs-on: ${{ matrix.os }}
53+
name: ${{ matrix.name }}
54+
55+
steps:
56+
- name: Checkout repository
57+
uses: actions/checkout@v4
58+
59+
- name: Install dependencies
60+
run: |
61+
sudo apt update
62+
sudo apt install -y ninja-build ${{ matrix.cc }} ${{ matrix.cxx }} ${{ matrix.extra_packages }}
63+
64+
- name: Cache CMake
65+
uses: actions/cache@v4
66+
with:
67+
path: ${{ env.CMAKE_INSTALL_DIR }}
68+
key: cmake-${{ env.CMAKE_VERSION }}-${{ matrix.os }}-${{ matrix.cc }}-try2
69+
70+
- name: Download and Install CMake if not cached
71+
run: |
72+
if [ ! -f "${{ env.CMAKE_BIN }}" ]; then
73+
echo "CMake not found in cache. Downloading..."
74+
mkdir -p "${{ env.CMAKE_INSTALL_DIR }}"
75+
wget -q https://github.com/Kitware/CMake/releases/download/v${{ env.CMAKE_VERSION }}/cmake-${{ env.CMAKE_VERSION }}-linux-x86_64.tar.gz
76+
tar -xzf cmake-${{ env.CMAKE_VERSION }}-linux-x86_64.tar.gz --strip-components=1 -C "${{ env.CMAKE_INSTALL_DIR }}"
77+
else
78+
echo "Using cached CMake"
79+
fi
80+
"${{ env.CMAKE_BIN }}" --version
81+
82+
- name: Run CMake configuration and build
83+
run: |
84+
"${{ env.CMAKE_BIN }}" . -B build -G Ninja \
85+
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
86+
-DCMAKE_C_COMPILER=${{ matrix.cc }} \
87+
-DCMAKE_CXX_COMPILER=${{ matrix.cxx }}
88+
"${{ env.CMAKE_BIN }}" --build build --parallel
89+
90+
- name: Run Unit Tests
91+
run: |
92+
mkdir -p "${{ env.TEST_RESULTS_DIR }}"
93+
./build/tests --reporters=junit --out="${{ env.TEST_RESULTS_DIR }}/results.xml"
94+
95+
- name: Render JUnit results in GitHub UI
96+
if: always()
97+
uses: dorny/test-reporter@v1
98+
with:
99+
name: ${{ matrix.name }} Tests
100+
path: ${{ env.TEST_RESULTS_DIR }}/results.xml
101+
reporter: junit
102+
103+
- name: Upload Test Results Artifact
104+
if: always()
105+
uses: actions/upload-artifact@v4
106+
with:
107+
name: ${{ matrix.name }}-test-results
108+
path: ${{ env.TEST_RESULTS_DIR }}/results.xml

examples/CMakeLists.txt

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,32 @@ FetchContent_MakeAvailable(Boost)
2121
add_library(http ${CMAKE_CURRENT_SOURCE_DIR}/../src/http.cpp)
2222
target_compile_features(http PUBLIC cxx_std_17)
2323
target_include_directories(http PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../src)
24-
target_link_libraries(http
25-
PUBLIC Boost::asio
26-
PUBLIC OpenSSL::SSL OpenSSL::Crypto)
24+
target_link_libraries(http PUBLIC OpenSSL::SSL OpenSSL::Crypto Boost::asio)
2725

2826
# Examples
2927
function(add_executable_20 target_name)
3028
add_executable(${target_name} ${ARGN})
3129
target_compile_features(${target_name} PUBLIC cxx_std_20)
3230
target_link_options(${target_name} PUBLIC $<$<CONFIG:Release>:-s>)
33-
target_link_libraries(${target_name} PUBLIC Threads::Threads PUBLIC http)
31+
target_link_libraries(${target_name} PUBLIC Threads::Threads http)
3432
endfunction()
3533

3634
function(add_executable_coro target_name)
3735
add_executable(${target_name} ${ARGN})
38-
target_link_options(${target_name} PUBLIC $<$<CONFIG:Release>:-s>)
39-
target_link_libraries(${target_name} PUBLIC Threads::Threads Boost::compat PUBLIC http)
36+
target_link_options(${target_name} PRIVATE $<$<CONFIG:Release>:-s>)
37+
target_link_libraries(${target_name} PRIVATE Threads::Threads Boost::compat http)
4038
endfunction()
4139

4240
add_executable_20(server ${CMAKE_CURRENT_SOURCE_DIR}/server.cpp)
4341
add_executable_20(client_http ${CMAKE_CURRENT_SOURCE_DIR}/client_http.cpp ${CMAKE_CURRENT_SOURCE_DIR}/extra/yyjson.c)
4442
add_executable_20(client_ws_awaitable ${CMAKE_CURRENT_SOURCE_DIR}/client_ws_awaitable.cpp)
45-
add_executable_coro(client_ws_coro ${CMAKE_CURRENT_SOURCE_DIR}/client_ws_coro.cpp)
43+
add_executable_coro(client_ws_coro ${CMAKE_CURRENT_SOURCE_DIR}/client_ws_coro.cpp)
44+
45+
# Unit tests
46+
add_executable(tests
47+
unit_tests/main.cpp
48+
unit_tests/base64.cpp
49+
unit_tests/sha1.cpp)
50+
target_link_options(tests PRIVATE $<$<CONFIG:Release>:-s>)
51+
target_include_directories(tests PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/extra)
52+
target_link_libraries(tests PRIVATE http)
File renamed without changes.

test/CMakeLists.txt

Lines changed: 0 additions & 34 deletions
This file was deleted.

0 commit comments

Comments
 (0)