Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,12 @@ jobs:
- name: Build
run: cmake --build build

- name: Test
working-directory: build
run: ctest -V

# - name: Test with Coverage
# - name: Test
# working-directory: build
# run: cmake --build ${BUILD_DIR} --target os_test_coverage
# run: ctest -V

- name: Test with Coverage
run: cmake --build build --target Wavefront_coverage

lint:
runs-on: ubuntu-latest
Expand Down
28 changes: 28 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ project(Wavefront
option(WAVEFRONT_BUILD_DOCS "Builds the Wavefront documentation" ON)
option(WAVEFRONT_BUILD_TESTS "Builds the Wavefront tests" ON)

option(WAVEFRONT_TEST_COVERAGE "Generate gcov target for calculating code coverage" ON)
option(WAVEFRONT_TEST_COVERAGE_CAN_FAIL "Tests can fail for coverage" ON)
option(WAVEFRONT_TEST_COVERAGE_DARK "Use dark theme for html output" ON)

# Only if this is the top level project (not included with add_subdirectory)
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
# Use -std=c++xx instead of -std=g++xx
Expand All @@ -17,6 +21,19 @@ if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)

if(WAVEFRONT_BUILD_TESTS)
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
if(WAVEFRONT_TEST_COVERAGE AND CMAKE_COMPILER_IS_GNUCXX)
include(CodeCoverage)
append_coverage_compiler_flags()
if(WAVEFRONT_TEST_COVERAGE_CAN_FAIL)
set(GCOVR_ADDITIONAL_ARGS ${GCOVR_ADDITIONAL_ARGS} --html-high-threshold 100 --html-medium-threshold 90 --fail-under-line 100 --fail-under-branch 100)
endif()
if(WAVEFRONT_TEST_COVERAGE_DARK)
set(GCOVR_ADDITIONAL_ARGS ${GCOVR_ADDITIONAL_ARGS} --html-theme github.dark-green)
else()
set(GCOVR_ADDITIONAL_ARGS ${GCOVR_ADDITIONAL_ARGS} --html-theme github.green)
endif()
endif()
# Testing only available for top level projects. It calls enable_testing
# which must be in the main CMakeLists.
include(CTest)
Expand Down Expand Up @@ -71,3 +88,14 @@ install(FILES
if((CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME OR MODERN_CMAKE_BUILD_TESTING) AND WAVEFRONT_BUILD_TESTS)
add_subdirectory(tests)
endif()

if(WAVEFRONT_TEST_COVERAGE AND CMAKE_COMPILER_IS_GNUCXX)
setup_target_for_coverage_gcovr_html(
NAME ${PROJECT_NAME}_coverage
EXECUTABLE ctest
EXECUTABLE_ARGS --output-on-failure
DEPENDENCIES ${PROJECT_NAME}
BASE_DIRECTORY .
EXCLUDE ${PROJECT_SOURCE_DIR}/tests ${PROJECT_BINARY_DIR}/*
)
endif()
18 changes: 17 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,20 @@ test: build
test-ci: build
cd build && GTEST_COLOR=1 ctest -V

.PHONY: setup build install lint format test test-ci
test-cov: test coverage

coverage:
@mkdir -p build/coverage
gcovr --txt \
--html build/coverage/index.html \
--html-details \
--html-theme github.dark-green \
--html-high-threshold 100 \
--html-medium-threshold 90 \
--fail-under-line 100 \
--fail-under-branch 100 \
--lcov build/coverage.lcov \
-e build \
-e tests

.PHONY: setup build install lint format test test-ci test-cov coverage
Loading
Loading