|
| 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