Use cargo nextest to run tests

Cargo nextest is faster, and handles flaky tests (tests that can fail even
though nothing changed). Both the regular test run and the coverage run include
it.
This commit is contained in:
Martijn Pieters 2022-10-28 14:19:02 +01:00
parent 6ccefcab0e
commit e355e38f9b
No known key found for this signature in database
4 changed files with 55 additions and 5 deletions

40
.config/nextest.toml Normal file
View file

@ -0,0 +1,40 @@
# See https://nexte.st/book/configuration.html for format and defaults
# Profiles defined here inherit from profile.default
# profile used in GitHub test runs
# - Retry a few times to detect flaky tests
# - Call out every test as it finishes, including slow, skipped and flaky tests
# - List failures again at the end.
# - Run all tests even if some failed.
[profile.ci]
# "retries" defines the number of times a test should be retried. If set to a
# non-zero value, tests that succeed on a subsequent attempt will be marked as
# non-flaky. Can be overridden through the `--retries` option.
retries = 2
# * none: no output
# * fail: show failed (including exec-failed) tests
# * retry: show flaky and retried tests
# * slow: show slow tests
# * pass: show passed tests
# * skip: show skipped tests (most useful for CI)
# * all: all of the above
#
# Each value includes all the values above it; for example, "slow" includes
# failed and retried tests.
status-level = "all"
# * "immediate-final": output failures as soon as they happen and at the end of
# the test run; combination of "immediate" and "final"
failure-output = "immediate-final"
# Cancel the test run on the first failure. For CI runs, consider setting this
# to false.
fail-fast = false
# profile used in GitHub coverage runs
# - lower retry count as a compromise between speed and resilience
# - no fail-fast to at least keep coverage percentages accurate.
[profile.coverage]
retries = 1
fail-fast = false

View file

@ -48,11 +48,15 @@ jobs:
restore-keys: |
${{ runner.os }}-cargo-${{ matrix.target }}-
- name: Install cargo-llvm-cov
uses: taiki-e/install-action@cargo-llvm-cov
- name: Install cargo-llvm-cov and nextest
uses: taiki-e/install-action@v1
with:
tool: cargo-llvm-cov,nextest
- name: Generate code coverage
run: cargo llvm-cov --all-features --workspace --lcov --output-path lcov.info
env:
NEXTEST_PROFILE: coverage # defined in .config/nextest.toml
run: cargo llvm-cov nextest --all-features --workspace --lcov --output-path lcov.info
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3

View file

@ -75,6 +75,9 @@ jobs:
components: llvm-tools-preview
target: ${{ matrix.target }}
- name: Install cargo-nextest
uses: taiki-e/install-action@nextest
- uses: actions/cache@v3
with:
path: |
@ -97,7 +100,9 @@ jobs:
- name: cargo test
uses: actions-rs/cargo@v1
if: ${{ !matrix.cross }}
env:
NEXTEST_PROFILE: ci # defined in .config/nextest.toml
with:
command: test
args: --workspace --target=${{ matrix.target }}
command: nextest
args: run --workspace --target=${{ matrix.target }}
use-cross: ${{ matrix.cross }}

View file

@ -32,6 +32,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Continuation of testing the `pueue` client, pushing the test coverage from ~70% to ~73%.
- A codecov.yml syntax error was corrected, which prevented Codecov from applying the
repository-specific configuration.
- CI tests are now run using cargo nextest, for faster test execution, flaky test handling and better test output.
## [2.1.0] - 2022-07-21