Code coverage for swift package manager projects

In swift package managers, the test coverage report is not generated by default. It must be enabled via
swift test --enable-code-coverage
And even if enabled it is not in a format CodeCov can understand. Fortunately this post is excellent and shows how to convert reports for CodeCov.io. In recent versions of SPM it should be like this:
xcrun llvm-cov export -format="lcov" -instr-profile=$(find .build -name default.profdata) $(find .build -name [PackageNameHere]PackageTests) > info.lcov
Here is an example of one of my project NDHpple with github actions and the project in Codecov
jobs:
  build:

    runs-on: macos-latest

    steps:
    - uses: actions/checkout@v2
    - name: Build
      run: swift build -v
    - name: Run tests
      run: swift test -v --enable-code-coverage
    - name: Convert code coverage
      run: xcrun llvm-cov export -format="lcov" -instr-profile=$(find .build -name default.profdata) $(find .build -name NDHpplePackageTests) > info.lcov
    - name: Codecov
      uses: codecov/codecov-action@v1.0.13
      with:
        file: info.lcov
Hope it helps.

0 comments :

This work is licensed under BSD Zero Clause License | nacho4d ®