Skip to content

Commit d7026cd

Browse files
authored
Switch to nextest for testing (#753)
* Tweak comment * Add nextest to CI * Add nextest as default test task * Add a `justfile` for easy test running * Add nextest and just info to `BUILDING.md`
1 parent d2d3766 commit d7026cd

File tree

8 files changed

+92
-16
lines changed

8 files changed

+92
-16
lines changed

.config/nextest.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[profile.ci]
2+
# Print out output for failing tests as soon as they fail, and also at the end
3+
# of the run (for easy scrollability).
4+
failure-output = "immediate-final"
5+
6+
# Do not cancel the test run on the first failure.
7+
fail-fast = false
8+
9+
# Mark tests that take longer than 60s as slow.
10+
# Terminate after 60s as a stop-gap measure to terminate on deadlock.
11+
slow-timeout = { period = "60s", terminate-after = 1 }

.github/workflows/test-linux.yml

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ on:
55
workflow_dispatch:
66
inputs:
77
ssh:
8-
description: 'Set up an SSH session before running `cargo test`?'
8+
description: 'Set up an SSH session before running `cargo nextest run`?'
99
type: boolean
1010
required: true
1111
default: false
@@ -45,6 +45,11 @@ jobs:
4545
# Cache isn't useful on nightly, it would be thrown away every day
4646
if: matrix.config.rust != 'nightly'
4747

48+
- name: Install nextest
49+
uses: taiki-e/install-action@v2
50+
with:
51+
tool: cargo-nextest
52+
4853
- name: Install R
4954
uses: r-lib/actions/setup-r@v2
5055
with:
@@ -72,8 +77,10 @@ jobs:
7277

7378
- name: Build
7479
run: |
75-
cargo build
80+
cargo build
7681
77-
- name: Run Unit Tests
82+
- name: Run Tests
83+
env:
84+
NEXTEST_PROFILE: "ci"
7885
run: |
79-
cargo test --verbose -- --nocapture
86+
cargo nextest run

.github/workflows/test-macos.yml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ jobs:
2525
- name: Rust Cache
2626
uses: Swatinem/rust-cache@v2
2727

28+
- name: Install nextest
29+
uses: taiki-e/install-action@v2
30+
with:
31+
tool: cargo-nextest
32+
2833
- name: Install R
2934
uses: r-lib/actions/setup-r@v2
3035
with:
@@ -43,8 +48,10 @@ jobs:
4348

4449
- name: Build
4550
run: |
46-
cargo build
51+
cargo build
4752
48-
- name: Run Unit Tests
53+
- name: Run Tests
54+
env:
55+
NEXTEST_PROFILE: "ci"
4956
run: |
50-
cargo test --verbose -- --nocapture
57+
cargo nextest run

.github/workflows/test-windows.yml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ jobs:
2525
- name: Rust Cache
2626
uses: Swatinem/rust-cache@v2
2727

28+
- name: Install nextest
29+
uses: taiki-e/install-action@v2
30+
with:
31+
tool: cargo-nextest
32+
2833
- name: Install R
2934
uses: r-lib/actions/setup-r@v2
3035
with:
@@ -43,9 +48,10 @@ jobs:
4348

4449
- name: Build
4550
run: |
46-
cargo build
51+
cargo build
4752
48-
- name: Run Unit Tests
49-
# Very loud on windows CI, which has been a source of instability
53+
- name: Run Tests
54+
env:
55+
NEXTEST_PROFILE: "ci"
5056
run: |
51-
cargo test -vv -- --nocapture
57+
cargo nextest run

.vscode/tasks.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
},
1616
{
1717
"type": "cargo",
18-
"command": "test",
18+
"command": "nextest",
1919
"problemMatcher": [
2020
"$rustc",
2121
"$rust-panic"
@@ -24,7 +24,10 @@
2424
"kind": "test",
2525
"isDefault": true
2626
},
27-
"label": "rust: cargo test"
27+
"args": [
28+
"run"
29+
],
30+
"label": "rust: cargo nextest run"
2831
}
2932
]
3033
}

BUILDING.md

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ You will usually want to tweak the **ark** environment for development; add this
3535

3636
This enables backtrace capturing in [anyhow](https://docs.rs/anyhow) errors and sets internal crates to log at TRACE level and external dependencies to log at WARN. Setting the latter to more verbose levels can dramatically decrease performance. See the documentation in the [tracing_subscriber](https://docs.rs/tracing-subscriber/latest/tracing_subscriber/filter/struct.EnvFilter.html) crate for more fine-grained tuning of the `RUST_LOG` environment variable.
3737

38-
## Test with Positron
38+
## Test with Release Positron
3939

40-
To test the dev build of ARK on Positron, you can open Positron's user settings
40+
To test the dev build of ARK on Release Positron, you can open Positron's user settings
4141
and change option `Positron > R > Kernel: Path` (ID: `positron.r.kernel.path`)
4242
to the location of the binary.
4343

@@ -46,3 +46,31 @@ to the location of the binary.
4646
"positron.r.kernel.path": "/path/to/ark/target/debug/ark",
4747
}
4848
```
49+
50+
With a development version of Positron, a development version of Ark is automatically detected as long as the `positron/` and `ark/` folders are at the same depth, i.e.:
51+
52+
```
53+
| files/
54+
| |- ark/
55+
| |- positron/
56+
```
57+
58+
## Testing
59+
60+
We use [nextest](https://nexte.st/) for testing rather than a standard `cargo test`, primarily because nextest runs each test in its own process rather than in its own thread.
61+
This is critical for us, as Ark has global objects that can only be set up once per process (such as setup around the R process itself).
62+
Additionally, using one process per test means that it is impossible for one test to interfere with another (so you don't have to worry about test cleanup, particularly if you add objects to R's global environment).
63+
Tests are still run in parallel, using multiple processes, and this ends up being quite fast and reliable.
64+
65+
Install the nextest cli tool using a [prebuilt binary](https://nexte.st/docs/installation/pre-built-binaries/).
66+
67+
Run tests locally with `just test` (which runs `cargo nextest run`) or `Tasks: Run Test Task` in VS Code (which you can bind to a keyboard shortcut).
68+
Run insta snapshot tests in "update" mode with `just test-insta` (which runs `cargo insta test --test-runner nextest`).
69+
70+
On CI we use the nextest profile found in `.config/nextest.toml`.
71+
72+
## Just
73+
74+
We use [just](https://github.com/casey/just) as a simple command runner, and the shortcuts live in `justfile`.
75+
On macOS, install just with `brew install just`.
76+
For other platforms, see the just README.

crates/harp/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ fn main() {
1717
//
1818
// We also do this for ark.
1919
//
20-
// We don't generate a main `harp.exe` binary, but `cargo test` does generate a `harp-*.exe`
20+
// We don't generate a main `harp.exe` binary, but `cargo nextest run` does generate a `harp-*.exe`
2121
// binary for unit testing, and those unit tests also start R and test UTF-8 related capabilities!
2222
// So we need that test executable to include a manifest file too.
2323
let resource = Path::new("resources")

justfile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
# Run the tests
3+
test:
4+
cargo nextest run
5+
6+
# Run the tests in verbose mode
7+
# `--no-capture` forces stdout/stderr to be shown for all tests, not just failing ones,
8+
# and also forces them to be run sequentially so you don't see interleaved live output
9+
test-verbose:
10+
cargo nextest run --no-capture
11+
12+
# Run the insta tests in update mode
13+
test-insta:
14+
cargo insta test --test-runner nextest

0 commit comments

Comments
 (0)