Skip to content

Commit

Permalink
PR testing: add a coverage report for Rust tests
Browse files Browse the repository at this point in the history
This is using the still-experimental -Zinstrument-coverage, so it may
not be perfect, but hopefully it gives us a starting point.
  • Loading branch information
jrose-signal committed Oct 30, 2020
1 parent 5de9769 commit a16f600
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ env:

jobs:
build:
runs-on: ubuntu-latest
runs-on: ubuntu-20.04

steps:
- name: Install nightly rust
Expand All @@ -22,7 +22,7 @@ jobs:
toolchain: nightly
override: true
profile: minimal
components: rustfmt, clippy
components: rustfmt, clippy, llvm-tools-preview
- uses: actions/checkout@v2
- name: Rustfmt check
run: cargo fmt -- --check
Expand All @@ -32,3 +32,25 @@ jobs:
run: cargo test --verbose
- name: Clippy
run: cargo clippy

- name: Install LLVM tools (for llvm-cov)
run: sudo apt-get install llvm

- name: Rerun tests for coverage
run: cargo test
env:
RUSTFLAGS: -Zinstrument-coverage
CARGO_TARGET_DIR: target-cov
LLVM_PROFILE_FILE: "${{ github.workspace }}/test.%p.profraw"

- name: Merge coverage data
run: $(rustc --print target-libdir)/../bin/llvm-profdata merge --sparse test.*.profraw -o test.profdata

- name: Generate coverage report
run: find target-cov/debug/deps -type f -perm -u+x ! -name '*.so' | sed '2,$ s/^/--object /' | xargs llvm-cov show --format=html --instr-profile test.profdata --output-dir coverage-report

- name: Upload coverage report
uses: actions/upload-artifact@v2
with:
name: Rust Coverage
path: coverage-report

0 comments on commit a16f600

Please sign in to comment.