From 710beccadea89a52feda1eb2d2eb31a0b708d7e4 Mon Sep 17 00:00:00 2001 From: Yevhenii Babichenko Date: Fri, 15 Nov 2024 20:44:24 +0200 Subject: [PATCH] fix code coverage --- .github/workflows/tests.yml | 48 ++++++++++++++++++------------------- tests/fish.rs | 2 -- 2 files changed, 24 insertions(+), 26 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index cc01c85..a883dbd 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -39,6 +39,10 @@ jobs: tests: name: cargo test runs-on: ubuntu-latest + env: + RUSTFLAGS: -C instrument-coverage + RUST_BACKTRACE: 1 + LLVM_PROFILE_FILE: default_%m.profraw steps: - name: Checkout uses: actions/checkout@v4 @@ -46,13 +50,28 @@ jobs: - name: Install dependencies run: sudo apt-get install -y zsh fish - - name: Rust cache - uses: Swatinem/rust-cache@v2 + - name: Install coverage tools + run: | + rustup component add llvm-tools + curl -LsSf https://get.nexte.st/latest/linux | tar zxf - -C ${CARGO_HOME:-~/.cargo}/bin - name: Run tests - env: - RUST_BACKTRACE: 1 - run: cargo test --locked -- --nocapture + run: cargo nextest run + + - name: Generate coverage report + run: | + toolchain="$(grep '^default_toolchain' ~/.rustup/settings.toml | cut -d'"' -f2)" + PATH="$HOME/.rustup/toolchains/$toolchain/lib/rustlib/${toolchain#*-}/bin:$PATH" + BINARIES="$(cargo nextest list --list-type binaries-only --message-format json | jq -r '.["rust-binaries"] | .[] | "--object \(.["binary-path"])"' | tr '\n' ' ')" + ARGS="-instr-profile fixit.profdata $BINARIES --object $PWD/target/debug/fixit" + llvm-profdata merge -sparse default_*.profraw -o fixit.profdata + llvm-cov report --use-color --ignore-filename-regex='/.cargo/registry' $ARGS + llvm-cov export -format=lcov $ARGS -sources src/{,**/}*.rs > fixit.lcov + + - name: Upload coverage report + uses: coverallsapp/github-action@v2 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} audit: name: Check security advisory database @@ -70,22 +89,3 @@ jobs: tar -xvzf cargo-audit-x86_64-unknown-linux-musl-*.tgz cp cargo-audit-x86_64-unknown-linux-musl-*/cargo-audit . ./cargo-audit audit - - coverage: - name: Code coverage - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Install dependencies - run: sudo apt-get install -y zsh fish - - - name: Rust cache - uses: Swatinem/rust-cache@v2 - - - name: Run cargo-tarpaulin - run: | - gh release download --repo xd009642/tarpaulin --pattern 'cargo-tarpaulin-x86_64-unknown-linux-musl.tar.gz' - tar -xvzf cargo-tarpaulin-x86_64-unknown-linux-musl.tar.gz - ./cargo-tarpaulin --follow-exec --engine llvm --skip-clean --coveralls ${{ secrets.COVERALLS_TOKEN }} diff --git a/tests/fish.rs b/tests/fish.rs index 8934447..c597056 100644 --- a/tests/fish.rs +++ b/tests/fish.rs @@ -24,7 +24,6 @@ fn fish() -> (Session, NamedTempFile) { let mut p = Session::spawn(fish).expect("Failed to spawn fish"); - // Initialize Fish p.send_line("fixit init fish | source").unwrap(); (p, histfile) @@ -37,7 +36,6 @@ fn fixed(fish: (Session, NamedTempFile)) { p.set_expect_timeout(Some(Duration::from_secs(5))); p.send_line("eco 'Hello, world!'").unwrap(); - p.expect("Unknown command").unwrap(); p.send_line("fix").unwrap(); p.send_line("").unwrap(); p.expect("Hello, world!").unwrap();