Skip to content

Commit 32942ad

Browse files
committed
Add integration test for cargo nextest run on the example test harness
1 parent a4a395a commit 32942ad

File tree

2 files changed

+46
-0
lines changed

2 files changed

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

0 commit comments

Comments
 (0)