Skip to content

Commit f62a508

Browse files
author
Igor Egorov
authored
Enable Code Coverage (#112)
Signed-off-by: Igor Egorov <[email protected]>
1 parent 4953f30 commit f62a508

File tree

8 files changed

+608
-181
lines changed

8 files changed

+608
-181
lines changed

.github/workflows/ci.yml

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: CI
22

3-
on:
3+
on:
44
push:
55
branches:
66
- master
@@ -45,7 +45,7 @@ jobs:
4545
fi
4646
4747
sudo python3 -m pip install --upgrade pip
48-
sudo pip3 install scikit-build
48+
sudo pip3 install scikit-build
4949
sudo pip3 install cmake requests gitpython gcovr pyyaml
5050
- name: cmake
5151
env:
@@ -61,6 +61,7 @@ jobs:
6161
env:
6262
CTEST_OUTPUT_ON_FAILURE: 1
6363
run: cmake --build build --target test
64+
6465
# TODO(warchant): on CI (linux/clang) this can not be built, figure out why
6566
# - name: install & test
6667
# run: |

.github/workflows/coverage.yml

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Coverage
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
branches:
9+
- master
10+
11+
jobs:
12+
coverage:
13+
name: "Codecov"
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v1
17+
name: checkout
18+
with:
19+
submodules: true
20+
clean: true
21+
fetch-depth: 2
22+
- name: "install dependencies"
23+
run: |
24+
set -e
25+
sudo apt-get update || true
26+
sudo apt-get install -y ninja-build
27+
sudo python3 -m pip install --upgrade pip
28+
sudo pip3 install scikit-build
29+
sudo pip3 install cmake requests gitpython gcovr pyyaml
30+
- name: "cmake"
31+
env:
32+
CC: clang
33+
CXX: clang++
34+
run: cmake . -GNinja -Bbuild-coverage -DCOVERAGE=ON -DEXAMPLES=OFF
35+
- name: "build report"
36+
env:
37+
CTEST_OUTPUT_ON_FAILURE: 1
38+
run: cmake --build build-coverage --target ctest_coverage -- -j4
39+
- name: "upload"
40+
uses: codecov/[email protected]
41+
with:
42+
files: build-coverage/ctest_coverage.xml
43+
verbose: false

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ config/__pycahe__
22
**/__pycache__/*
33
__pycache__/*
44
build/*
5+
build*
56
*.DS_Store
67
*.vscode/
78
*.swp

CMakeLists.txt

+8-5
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ print("C flags: ${CMAKE_C_FLAGS}")
3737
print("CXX flags: ${CMAKE_CXX_FLAGS}")
3838
print("Using CMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}")
3939

40+
# the property is out of "if TESTING" scope due to addtest func is out too
41+
set_property(GLOBAL PROPERTY TEST_TARGETS)
42+
4043
include(CheckCXXCompilerFlag)
4144
include(cmake/install.cmake)
4245
include(cmake/libp2p_add_library.cmake)
@@ -77,9 +80,6 @@ elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
7780
# TODO(warchant): add flags https://github.com/lefticus/cppbestpractices/blob/master/02-Use_the_Tools_Available.md#msvc
7881
endif ()
7982

80-
if (COVERAGE)
81-
include(cmake/coverage.cmake)
82-
endif ()
8383
if (CLANG_TIDY)
8484
include(cmake/clang-tidy.cmake)
8585
endif ()
@@ -98,8 +98,11 @@ add_subdirectory(src)
9898
if(EXAMPLES)
9999
add_subdirectory(example)
100100
endif()
101-
102-
if(TESTING)
101+
if(TESTING OR COVERAGE)
103102
enable_testing()
104103
add_subdirectory(test)
105104
endif()
105+
106+
if (COVERAGE)
107+
include(cmake/coverage.cmake)
108+
endif ()

0 commit comments

Comments
 (0)