diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/ubuntu.yml index 4821a79..18e7fc1 100644 --- a/.github/workflows/ubuntu.yml +++ b/.github/workflows/ubuntu.yml @@ -39,3 +39,20 @@ jobs: run: cmake --build build - name: test run: cd build && ctest --output-on-failure + + ci_test_coverage: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: cmake + run: cmake -S . -B build + - name: build + run: cmake --build build --target ci_test_coverage + - name: archive coverage report + uses: actions/upload-artifact@v2 + with: + name: code-coverage-report + - name: Coveralls + uses: coverallsapp/github-action@master + with: + github-token: ${{ secrets.GITHUB_TOKEN }} diff --git a/CMakeLists.txt b/CMakeLists.txt index 6c98995..541d55c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,6 +24,7 @@ endif() option(AMC_ENABLE_TESTS "Build the unit tests" ${MAIN_PROJECT}) option(AMC_ENABLE_BENCHMARKS "Build the benchmarks" ${MAIN_PROJECT}) option(AMC_ENABLE_ASAN "Compile with AddressSanitizer" ${ASAN_BUILD}) +option(AMC_ENABLE_GCOV "Compile for gcov" OFF) # Activate all warnings, in all build modes if(MAIN_PROJECT) @@ -36,10 +37,14 @@ endif(MAIN_PROJECT) if(AMC_ENABLE_ASAN) if(NOT MSVC) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -fsanitize=address -fsanitize=undefined -fsanitize=float-divide-by-zero -fno-sanitize-recover=all") + add_compile_options(-g -fsanitize=address -fsanitize=undefined -fsanitize=float-divide-by-zero -fno-sanitize-recover=all) endif() endif() +if(AMC_ENABLE_GCOV) + add_compile_options(-fprofile-arcs -fprofile-abs-path -ftest-coverage) +endif(AMC_ENABLE_GCOV) + # Create interface library for header files add_library(amc INTERFACE) add_library(amc::amc ALIAS amc) diff --git a/README.md b/README.md index acdfee0..7c58c55 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ [![Ubuntu](https://github.com/AmadeusITGroup/amc/actions/workflows/ubuntu.yml/badge.svg)](https://github.com/AmadeusITGroup/amc/actions/workflows/ubuntu.yml) [![Windows](https://github.com/AmadeusITGroup/amc/actions/workflows/windows.yml/badge.svg)](https://github.com/AmadeusITGroup/amc/actions/workflows/windows.yml) [![MacOS](https://github.com/AmadeusITGroup/amc/actions/workflows/macos.yml/badge.svg)](https://github.com/AmadeusITGroup/amc/actions/workflows/macos.yml) +[![Coverage Status](https://coveralls.io/repos/github/AmadeusITGroup/amc/badge.svg)](https://coveralls.io/github/AmadeusITGroup/amc) # AMadeus (C++) Containers diff --git a/src/benchmark/CMakeLists.txt b/src/benchmark/CMakeLists.txt index 57c0bc2..39638d1 100644 --- a/src/benchmark/CMakeLists.txt +++ b/src/benchmark/CMakeLists.txt @@ -23,6 +23,9 @@ function(add_bench name) target_include_directories(${name} PRIVATE ../include) target_include_directories(${name} PRIVATE ../test) target_link_libraries(${name} PRIVATE benchmark::benchmark) + if(AMC_ENABLE_GCOV) + target_link_libraries(${name} PRIVATE gcov) + endif(AMC_ENABLE_GCOV) endfunction() add_bench( diff --git a/src/test/CMakeLists.txt b/src/test/CMakeLists.txt index 5bd0805..9295711 100644 --- a/src/test/CMakeLists.txt +++ b/src/test/CMakeLists.txt @@ -22,6 +22,9 @@ function(add_unit_test name) add_executable(${name} ${MY_UNPARSED_ARGUMENTS}) target_link_libraries(${name} PRIVATE gtest gmock gmock_main) target_include_directories(${name} PRIVATE ../include) + if(AMC_ENABLE_GCOV) + target_link_libraries(${name} PRIVATE gcov) + endif(AMC_ENABLE_GCOV) add_test(NAME ${name} COMMAND ${name}) set_tests_properties(${name} PROPERTIES