Skip to content

Commit

Permalink
Add integration test for cargo nextest run on the example test harness
Browse files Browse the repository at this point in the history
  • Loading branch information
zaneduffield authored and sunshowers committed Apr 25, 2024
1 parent 1611ee2 commit 54f8020
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,7 @@ walkdir = "2.5.0"
[[test]]
name = "example"
harness = false

[[test]]
name = "run_example"
harness = true
42 changes: 42 additions & 0 deletions tests/run_example.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright (c) The datatest-stable Contributors
// SPDX-License-Identifier: MIT OR Apache-2.0

#[test]
fn run_example() {
let output = std::process::Command::new("cargo")
.args(["nextest", "run", "--test=example", "--color=never"])
.env("__DATATEST_FULL_SCAN_FORBIDDEN", "1")
.output()
.expect("Failed to run `cargo nextest`");

// It's a pain to make assertions on byte slices (even a subslice check isn't easy)
// and it's also difficult to print nice error messages. So we just assume all
// nextest output will be utf8 and convert it.
let stderr = std::str::from_utf8(&output.stderr).expect("cargo nextest stderr should be utf-8");

assert!(
output.status.success(),
"Command failed (exit status: {}, stderr: {stderr})",
output.status
);

let lines: &[&str] = &[
"datatest-stable::example test_artifact::::colon::dir/::.txt",
"datatest-stable::example test_artifact::::colon::dir/a.txt",
"datatest-stable::example test_artifact::a.txt",
"datatest-stable::example test_artifact_utf8::::colon::dir/::.txt",
"datatest-stable::example test_artifact::b.txt",
"datatest-stable::example test_artifact_utf8::::colon::dir/a.txt",
"datatest-stable::example test_artifact_utf8::a.txt",
"datatest-stable::example test_artifact_utf8::c.skip.txt",
"datatest-stable::example test_artifact_utf8::b.txt",
"9 tests run: 9 passed, 0 skipped",
];

for line in lines {
assert!(
stderr.contains(line),
"Expected to find substring\n {line}\nin stderr\n {stderr}",
);
}
}

0 comments on commit 54f8020

Please sign in to comment.