Skip to content

Commit f3c21d1

Browse files
authored
build: limit coverage flags to specific target (#65)
* build: only set coverage flags to `my_fibonacci_test` * build: rebuild library instead of linking it * ci: remove `src/main.cpp` from `excludes` input in check coverage step * ci: set `fail-under-line` to 100 in check coverage step
1 parent ebf098d commit f3c21d1

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

.github/workflows/ci.yaml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,5 @@ jobs:
4747
- name: Check coverage
4848
uses: threeal/[email protected]
4949
with:
50-
excludes: |
51-
build/*
52-
src/main.cpp
53-
fail-under-line: 80
50+
excludes: build/*
51+
fail-under-line: 100

CMakeLists.txt

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,18 @@ if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
2929
cpmgetpackage(Catch2)
3030
include("${Catch2_SOURCE_DIR}/extras/Catch.cmake")
3131

32-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage -fPIC -O0")
32+
get_target_property(my_fibonacci_SOURCES my_fibonacci SOURCES)
33+
add_executable(my_fibonacci_test test/sequence_test.cpp ${my_fibonacci_SOURCES})
34+
35+
get_target_property(my_fibonacci_INCLUDES my_fibonacci INCLUDE_DIRECTORIES)
36+
target_include_directories(my_fibonacci_test PRIVATE ${my_fibonacci_INCLUDES})
37+
38+
target_link_libraries(my_fibonacci_test PRIVATE Catch2::Catch2WithMain)
3339

34-
add_executable(my_fibonacci_test test/sequence_test.cpp)
35-
target_link_libraries(my_fibonacci_test PRIVATE my_fibonacci Catch2::Catch2WithMain)
3640
target_check_warning(my_fibonacci_test)
41+
target_compile_options(my_fibonacci_test PRIVATE --coverage -O0)
42+
target_link_options(my_fibonacci_test PRIVATE --coverage)
43+
3744
catch_discover_tests(my_fibonacci_test)
3845
endif()
3946
endif()

0 commit comments

Comments
 (0)