Skip to content

Commit 3314a03

Browse files
committed
add test ci
1 parent f6ceeb5 commit 3314a03

File tree

5 files changed

+94
-8
lines changed

5 files changed

+94
-8
lines changed

.github/workflows/test.yml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: CI
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 deps
17+
run: |
18+
sudo apt-get update
19+
sudo apt-get install -y cmake build-essential libgtest-dev lcov
20+
21+
- name: Configure & build (with coverage)
22+
run: cmake -S . -B build \
23+
-DENABLE_COVERAGE=ON \
24+
-DBUILD_TESTING=ON \
25+
-DCMAKE_BUILD_TYPE=Debug
26+
27+
- name: Build
28+
run: cmake --build build --parallel
29+
30+
- name: Zero coverage counters
31+
run: lcov --directory build --zerocounters
32+
33+
- name: Run tests
34+
run: ctest --test-dir build --output-on-failure
35+
36+
- name: Capture coverage
37+
run: lcov \
38+
--directory build \
39+
--capture \
40+
--output-file coverage.info
41+
42+
- name: Filter coverage
43+
run: lcov \
44+
--remove coverage.info \
45+
'/usr/*' '*/test/*' \
46+
--output-file coverage.filtered.info
47+
48+
- name: Generate HTML report
49+
run: genhtml coverage.filtered.info --output-directory coverage-report
50+
51+
- name: Upload coverage-report
52+
uses: actions/upload-artifact@v3
53+
with:
54+
name: coverage-report
55+
path: coverage-report
56+
57+
# Optional: push to Codecov (requires you set CODECOV_TOKEN in secrets)
58+
# - name: Upload to Codecov
59+
# uses: codecov/codecov-action@v3
60+
# with:
61+
# files: coverage.filtered.info
62+
# fail_ci_if_error: true

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1-
build
1+
build
2+
coverage.filtered.info
3+
coverage.info
4+
coverage-report

CMakeLists.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,17 @@ install(
8282
DESTINATION ${config_package_location}
8383
)
8484

85+
option(ENABLE_COVERAGE "Enable coverage reporting" OFF)
86+
if(ENABLE_COVERAGE)
87+
message(STATUS "Building with coverage support")
88+
# GCC/Clang coverage instrumentation
89+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage -O0 -g")
90+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --coverage -O0 -g")
91+
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage")
92+
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} --coverage")
93+
endif()
94+
95+
8596
option(BUILD_TESTING "Enable unit tests" ON)
8697
if(BUILD_TESTING)
8798
enable_testing()

README.md

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,12 @@ To ensure your control unit is supported, please refer to the [Micro Epsilon man
3030
3. Build the project:
3131

3232
```bash
33-
mkdir build
33+
cmake -S . -B build \
34+
-DENABLE_COVERAGE=OFF \
35+
-DBUILD_TESTING=OFF \
36+
-DCMAKE_BUILD_TYPE=Debug
37+
3438
cd build
35-
# use flag -DBUILD_TESTING=ON to build the tests
36-
cmake .. -DCMAKE_INSTALL_PREFIX=/usr/local
3739
make
3840
```
3941

@@ -184,13 +186,22 @@ Where:
184186

185187
## Development
186188

187-
Install GTest for testing. On ubuntu you can do this with:
189+
Install GTest and lcov for testing. On ubuntu you can do this with:
188190

189191
```bash
190-
sudo apt-get install libgtest-dev
192+
sudo apt-get install libgtest-dev lcov
191193
```
192194

193-
Follow the installation instructions above to set up the project. The library uses CMake for building and testing. To run the tests, ensure you have the `BUILD_TESTING` option enabled in your CMake configuration.
195+
Build the project:
196+
197+
```bash
198+
cmake -S . -B build \
199+
-DENABLE_COVERAGE=OFF \
200+
-DBUILD_TESTING=OFF \
201+
-DCMAKE_BUILD_TYPE=Debug
202+
203+
cmake --build build --parallel
204+
```
194205

195206
Testing:
196207

test/test_proximity_sensor_message.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#include <gtest/gtest.h>
2-
// #include <endian.h>
32
#include <memory>
43
#include "capancdt/proximity_sensor_message.h"
54

0 commit comments

Comments
 (0)