Skip to content

Commit 3799e6b

Browse files
committed
Add integration test for cargo nextest run on the example test harness
1 parent 6ec18d5 commit 3799e6b

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,7 @@ walkdir = "2.5.0"
2020
[[test]]
2121
name = "example"
2222
harness = false
23+
24+
[[test]]
25+
name = "run_example"
26+
harness = true

tests/run_example.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#[test]
2+
fn run_example() {
3+
let output = std::process::Command::new("cargo")
4+
.args(["nextest", "run", "--test=example"])
5+
.env("DATATEST_FULL_SCAN_FORBIDDEN", "1")
6+
.output()
7+
.expect("Failed to run `cargo nextest`");
8+
9+
// It's a pain to make assertions on byte slices (even a subslice check isn't easy)
10+
// and it's also difficult to print nice error messages. So we just assume all
11+
// nextest output will be utf8 and convert it.
12+
let stderr = std::str::from_utf8(&output.stderr).expect("Failed to convert stderr to utf-8");
13+
14+
assert!(
15+
output.status.success(),
16+
"Command failed (exit status: {}, stderr: {stderr})",
17+
output.status
18+
);
19+
20+
let lines: &[&str] = &[
21+
"datatest-stable::example test_artifact::::colon::dir/::.txt",
22+
"datatest-stable::example test_artifact::::colon::dir/a.txt",
23+
"datatest-stable::example test_artifact::a.txt",
24+
"datatest-stable::example test_artifact_utf8::::colon::dir/::.txt",
25+
"datatest-stable::example test_artifact::b.txt",
26+
"datatest-stable::example test_artifact_utf8::::colon::dir/a.txt",
27+
"datatest-stable::example test_artifact_utf8::a.txt",
28+
"datatest-stable::example test_artifact_utf8::c.skip.txt",
29+
"datatest-stable::example test_artifact_utf8::b.txt",
30+
"9 tests run: 9 passed, 0 skipped",
31+
];
32+
33+
for line in lines {
34+
assert!(
35+
stderr.contains(line),
36+
"Expected to find substring\n {line}\nin stderr\n {stderr}",
37+
);
38+
}
39+
}

0 commit comments

Comments
 (0)