Skip to content

Commit 3a3098d

Browse files
committed
Improve CI tests (#6)
- Adapt test.cpp to run with gtest - Adapt bench.cpp to run with benchmark - Add fuzztest to CI - Add clang-format to CI - Add cppcheck to CI - Combine CI unit tests into one workflow - Test clang and g++ in UTs for Ubuntu
1 parent 74cfc41 commit 3a3098d

19 files changed

+882
-723
lines changed

.github/workflows/bench.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: "Benchmarks"
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
branches: [ master ]
8+
9+
permissions:
10+
deployments: write
11+
contents: write
12+
13+
jobs:
14+
build:
15+
runs-on: ubuntu-latest
16+
strategy:
17+
matrix:
18+
compiler: ['g++', 'clang++']
19+
20+
steps:
21+
- uses: actions/checkout@v3
22+
23+
- name: Configure CMake
24+
run: cmake -B ${{github.workspace}}/build -DWITH_BENCHMARKS=ON -DCMAKE_CXX_COMPILER=${{matrix.compiler}} -DCMAKE_CXX_FLAGS="-O3"
25+
26+
- name: Build
27+
working-directory: ${{github.workspace}}/build
28+
run: cmake --build . -j $(nproc)
29+
30+
- name: Bench
31+
working-directory: ${{github.workspace}}/build
32+
run: ./bench --benchmark_format=json | tee benchmark_results_${{matrix.compiler}}.txt
33+
34+
- name: Store benchmark result
35+
uses: benchmark-action/github-action-benchmark@v1
36+
with:
37+
name: Benchmark
38+
tool: 'googlecpp'
39+
summary-always: true
40+
output-file-path: ${{github.workspace}}/build/benchmark_results_${{matrix.compiler}}.txt
41+
fail-on-alert: true
42+
github-token: ${{ secrets.GITHUB_TOKEN }}
43+
comment-on-alert: true
44+
alert-threshold: 150%
45+
gh-pages-branch: gh-pages
46+
benchmark-data-dir-path: 'benchmarks'
47+
auto-push: true

.github/workflows/cppcheck.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: "CppCheck"
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
branches: [ master ]
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- uses: actions/checkout@v3
15+
16+
- name: Install cppcheck
17+
run: |
18+
sudo apt update -y
19+
sudo apt install -y cppcheck
20+
21+
- name: Check code
22+
run: |
23+
readarray -t files < <(find . -maxdepth 1 -type f \( -name "*.h" -o -name "*.cpp" \))
24+
cppcheck --check-level=exhaustive \
25+
--enable=warning,performance,portability \
26+
--error-exitcode=1 \
27+
--force \
28+
--inconclusive \
29+
--language=c++ \
30+
--std=c++11 \
31+
-j $(nproc) \
32+
"${files[@]}"

.github/workflows/format.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: "Format"
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
branches: [ master ]
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- uses: actions/checkout@v3
15+
16+
- name: Install clang-format
17+
run: |
18+
sudo apt update -y
19+
sudo apt install -y clang-format
20+
21+
- name: Check format
22+
run: |
23+
readarray -t files < <(find . -maxdepth 1 -type f \( -name "*.h" -o -name "*.cpp" \))
24+
clang-format --verbose --Werror --dry-run "${files[@]}"

.github/workflows/fuzz.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: "Fuzz tests"
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
branches: [ master ]
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- uses: actions/checkout@v3
15+
16+
- name: Configure CMake
17+
run: cmake -B ${{github.workspace}}/build -DWITH_FUZZING=ON -DFUZZTEST_FUZZING_MODE=ON -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++
18+
19+
- name: Build
20+
working-directory: ${{github.workspace}}/build
21+
run: cmake --build . -j $(nproc)
22+
23+
- name: Fuzz
24+
working-directory: ${{github.workspace}}/build
25+
run: ./fuzz_test --fuzz_for=30s

.github/workflows/macos.yml

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

.github/workflows/test.yml

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
name: "Unit Tests"
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
branches: [ master ]
8+
9+
jobs:
10+
ubuntu:
11+
runs-on: ubuntu-latest
12+
strategy:
13+
matrix:
14+
standard: [11, 14, 17, 20, 23]
15+
compiler: ['g++', 'clang++']
16+
17+
steps:
18+
- uses: actions/checkout@v3
19+
20+
- name: Configure CMake
21+
run: cmake -B ${{github.workspace}}/build -DWITH_TESTS=ON -DCMAKE_CXX_STANDARD=${{matrix.standard}} -DCMAKE_CXX_COMPILER=${{matrix.compiler}}
22+
23+
- name: Build
24+
working-directory: ${{github.workspace}}/build
25+
run: cmake --build . -j $(nproc)
26+
27+
- name: Test
28+
working-directory: ${{github.workspace}}/build
29+
run: ctest --rerun-failed --output-on-failure
30+
31+
windows:
32+
runs-on: windows-latest
33+
strategy:
34+
matrix:
35+
standard: [11, 14, 17, 20, 23]
36+
37+
steps:
38+
- uses: actions/checkout@v3
39+
40+
- name: Configure CMake
41+
run: cmake -B ${{github.workspace}}/build -DWITH_TESTS=ON -DCMAKE_CXX_STANDARD=${{matrix.standard}}
42+
43+
- name: Build
44+
working-directory: ${{github.workspace}}/build
45+
run: cmake --build . -j "$env:NUMBER_OF_PROCESSORS"
46+
47+
- name: Test
48+
working-directory: ${{github.workspace}}/build
49+
run: ctest --rerun-failed --output-on-failure
50+
51+
macos:
52+
runs-on: macos-latest
53+
strategy:
54+
matrix:
55+
standard: [11, 14, 17, 20, 23]
56+
57+
steps:
58+
- uses: actions/checkout@v3
59+
60+
- name: Configure CMake
61+
run: cmake -B ${{github.workspace}}/build -DWITH_TESTS=ON -DCMAKE_CXX_STANDARD=${{matrix.standard}}
62+
63+
- name: Build
64+
working-directory: ${{github.workspace}}/build
65+
run: cmake --build . -j $(nproc)
66+
67+
- name: Test
68+
working-directory: ${{github.workspace}}/build
69+
run: ctest --rerun-failed --output-on-failure

.github/workflows/ubuntu.yml

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

.github/workflows/windows.yml

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

.vscode/compile_commands.json

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

CMakeLists.txt

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,64 @@ if(WITH_SPAN)
2222
endif()
2323

2424
if(WITH_BENCHMARKS)
25-
set(bench_target bench)
25+
set(CMAKE_BUILD_TYPE Release)
26+
27+
include(FetchContent)
28+
FetchContent_Declare(
29+
benchmark
30+
GIT_REPOSITORY https://github.com/google/benchmark.git
31+
GIT_TAG v1.9.1
32+
)
33+
set(BENCHMARK_ENABLE_TESTING OFF CACHE BOOL "" FORCE)
34+
set(BENCHMARK_ENABLE_GTEST_TESTS OFF CACHE BOOL "" FORCE)
35+
FetchContent_MakeAvailable(benchmark)
36+
37+
set(bench_target bench_test)
2638
add_executable(${bench_target} "bench.cpp")
39+
target_link_libraries(${bench_target} PRIVATE benchmark::benchmark)
2740
endif()
2841

2942
if(WITH_TESTS)
43+
set(CMAKE_BUILD_TYPE Debug)
44+
45+
include(FetchContent)
46+
FetchContent_Declare(
47+
googletest
48+
GIT_REPOSITORY https://github.com/google/googletest.git
49+
GIT_TAG v1.15.2
50+
)
51+
52+
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
53+
FetchContent_MakeAvailable(googletest)
54+
55+
include(GoogleTest)
56+
enable_testing()
57+
3058
set(test_target unit_test)
3159
add_executable(${test_target} "test.cpp")
60+
target_link_libraries(${test_target} PRIVATE gtest_main)
61+
gtest_discover_tests(${test_target})
62+
endif()
63+
64+
if(WITH_FUZZING)
65+
set(CMAKE_BUILD_TYPE RelWithDebInfo)
3266

67+
include(FetchContent)
68+
FetchContent_Declare(
69+
fuzztest
70+
GIT_REPOSITORY https://github.com/google/fuzztest.git
71+
GIT_TAG 2025-08-05
72+
)
73+
FetchContent_MakeAvailable(fuzztest)
74+
75+
include(GoogleTest)
3376
enable_testing()
34-
add_test(NAME ${test_target} COMMAND ${test_target})
77+
78+
fuzztest_setup_fuzzing_flags()
79+
set(fuzz_target fuzz_test)
80+
add_executable(${fuzz_target} "fuzz.cpp")
81+
link_fuzztest(${fuzz_target})
82+
gtest_discover_tests(${fuzz_target})
3583
endif()
3684

3785
configure_file(

0 commit comments

Comments
 (0)