diff --git a/.github/workflows/unix.yml b/.github/workflows/unix.yml index 254e30eb50..8396d7cd52 100644 --- a/.github/workflows/unix.yml +++ b/.github/workflows/unix.yml @@ -38,10 +38,13 @@ jobs: restore-keys: | libmamba-${{ matrix.os }} - name: Build libmamba + env: + enable_cov: ${{ ((matrix.os == 'ubuntu-latest') && (matrix.build_type == 'Debug')) || false }} shell: bash -l {0} run: | cmake -B build/ \ -D CMAKE_BUILD_TYPE=${{ matrix.build_type }} \ + -D ENABLE_COVERAGE=${{ env.enable_cov }} \ -D BUILD_LIBMAMBA=ON \ -D BUILD_SHARED=ON \ -D BUILD_LIBMAMBA_TESTS=ON \ @@ -54,6 +57,21 @@ jobs: run: | unset CONDARC # Interferes with tests cd build && ninja test + - name: Coverage + if: ${{ ((matrix.os == 'ubuntu-latest') && (matrix.build_type == 'Debug')) || false }} + shell: bash -l {0} + run: | + cd build && ninja coverage + - name: Upload coverage to Coveralls + if: ${{ ((matrix.os == 'ubuntu-latest') && (matrix.build_type == 'Debug')) || false }} + uses: coverallsapp/github-action@v2 + env: + NODE_COVERALLS_DEBUG: 1 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + file: ${{github.workspace}}/build/coverage.info + format: lcov + git-branch: gcov - name: Show build cache statistics run: sccache --show-stats diff --git a/libmamba/CMakeLists.txt b/libmamba/CMakeLists.txt index bcd1b2eac6..a39df60040 100644 --- a/libmamba/CMakeLists.txt +++ b/libmamba/CMakeLists.txt @@ -65,24 +65,31 @@ endif () option(ENABLE_ASAN "Enable Address-Sanitizer (currently only supported on GCC and Clang)" OFF) -if(ENABLE_ASAN) +if (ENABLE_ASAN) message(WARNING "Address-Sanitizer instrumentation will be injected into binaries - do not release these binaries") add_compile_options(-fno-omit-frame-pointer -fsanitize=address) add_link_options(-fno-omit-frame-pointer -fsanitize=address) endif() -if(ENABLE_TSAN) +if (ENABLE_TSAN) message(WARNING "Thread-Sanitizer instrumentation will be injected into binaries - do not release these binaries") add_compile_options(-fno-omit-frame-pointer -fsanitize=thread) add_link_options(-fno-omit-frame-pointer -fsanitize=thread) endif() -if(ENABLE_USAN) +if (ENABLE_USAN) message(WARNING "Undefined-Sanitizer instrumentation will be injected into binaries - do not release these binaries") add_compile_options(-fno-omit-frame-pointer -fsanitize=undefined) add_link_options(-fno-omit-frame-pointer -fsanitize=undefined) endif() +# Code coverage +option(ENABLE_COVERAGE "Enable code testing coverage" OFF) + +if (ENABLE_COVERAGE) + add_compile_options(--coverage) + add_link_options(--coverage) +endif() # Source files # ============ diff --git a/libmamba/environment-dev.yml b/libmamba/environment-dev.yml index e66f1407ae..c8eca2d679 100644 --- a/libmamba/environment-dev.yml +++ b/libmamba/environment-dev.yml @@ -18,4 +18,5 @@ dependencies: - cli11 >=2.2 - spdlog - fmt + - lcov - sel(win): winreg diff --git a/libmamba/tests/CMakeLists.txt b/libmamba/tests/CMakeLists.txt index 3a2a964862..92c6167c2d 100644 --- a/libmamba/tests/CMakeLists.txt +++ b/libmamba/tests/CMakeLists.txt @@ -116,3 +116,16 @@ target_compile_definitions( target_compile_features(test_libmamba PUBLIC cxx_std_17) add_custom_target(test COMMAND test_libmamba DEPENDS test_libmamba) + +# Generate tests coverage report +if (ENABLE_COVERAGE) + find_program(LCOV lcov REQUIRED) + find_program(GENHTML genhtml REQUIRED) + + add_custom_target(coverage + # Gather data + COMMAND ${LCOV} --directory . --capture --output-file coverage.info + # Generate report + COMMAND ${GENHTML} --demangle-cpp -o coverage coverage.info + WORKING_DIRECTORY ${CMAKE_BINARY_DIR}) +endif()