|
1 |
| -use assert_cmd::prelude::*; |
| 1 | +use ui_test::{color_eyre::Result, run_tests, Config, Mode, OutputConflictHandling}; |
2 | 2 |
|
3 |
| -use std::process::Command; |
4 |
| - |
5 |
| -// Timings are flaky, so tests would spuriously fail. |
6 |
| -// Thus we replace all `/([0-9]+)ms/` with underscores |
7 |
| -fn replace_ms(data: &[u8]) -> Vec<u8> { |
8 |
| - let mut skip = false; |
9 |
| - let mut seen_s = false; |
10 |
| - let mut v: Vec<u8> = data |
11 |
| - .iter() |
12 |
| - .rev() |
13 |
| - .filter_map(|&b| match (b, skip, seen_s) { |
14 |
| - (b'0'..=b'9', true, _) => None, |
15 |
| - (_, true, _) => { |
16 |
| - skip = false; |
17 |
| - Some(b) |
18 |
| - } |
19 |
| - (b's', _, _) => { |
20 |
| - seen_s = true; |
21 |
| - Some(b) |
22 |
| - } |
23 |
| - (b'm', _, true) => { |
24 |
| - seen_s = false; |
25 |
| - skip = true; |
26 |
| - Some(b) |
27 |
| - } |
28 |
| - _ => Some(b), |
29 |
| - }) |
30 |
| - .collect(); |
31 |
| - v.reverse(); |
32 |
| - v |
33 |
| -} |
34 |
| - |
35 |
| -fn main() { |
36 |
| - for entry in glob::glob("examples/*.rs").expect("Failed to read glob pattern") { |
37 |
| - let entry = entry.unwrap(); |
38 |
| - let mut cmd = Command::cargo_bin(entry.with_extension("").to_str().unwrap()).unwrap(); |
39 |
| - let output = cmd.unwrap(); |
40 |
| - let stderr = entry.with_extension("stderr"); |
41 |
| - let stdout = entry.with_extension("stdout"); |
42 |
| - |
43 |
| - if std::env::args().any(|arg| arg == "--bless") { |
44 |
| - if output.stderr.is_empty() { |
45 |
| - let _ = std::fs::remove_file(stderr); |
46 |
| - } else { |
47 |
| - std::fs::write(stderr, replace_ms(&output.stderr)).unwrap(); |
48 |
| - } |
49 |
| - if output.stdout.is_empty() { |
50 |
| - let _ = std::fs::remove_file(stdout); |
51 |
| - } else { |
52 |
| - std::fs::write(stdout, replace_ms(&output.stdout)).unwrap(); |
53 |
| - } |
54 |
| - } else { |
55 |
| - if output.stderr.is_empty() { |
56 |
| - assert!( |
57 |
| - !stderr.exists(), |
58 |
| - "{} exists but there was no stderr output", |
59 |
| - stderr.display() |
60 |
| - ); |
61 |
| - } else { |
62 |
| - assert!( |
63 |
| - std::fs::read(&stderr).unwrap() == replace_ms(&output.stderr), |
64 |
| - "{} is not the expected output, rerun the test with `cargo test -- -- --bless`", |
65 |
| - stderr.display() |
66 |
| - ); |
67 |
| - } |
68 |
| - if output.stdout.is_empty() { |
69 |
| - assert!(!stdout.exists()); |
70 |
| - } else { |
71 |
| - assert!( |
72 |
| - std::fs::read(&stdout).unwrap() == replace_ms(&output.stdout), |
73 |
| - "{} is not the expected output, rerun the test with `cargo test -- -- --bless`", |
74 |
| - stdout.display() |
75 |
| - ); |
76 |
| - } |
77 |
| - } |
78 |
| - } |
| 3 | +fn main() -> Result<()> { |
| 4 | + let mut config = Config::default(); |
| 5 | + config.root_dir = "examples".into(); |
| 6 | + config.dependencies_crate_manifest_path = Some("test_dependencies/Cargo.toml".into()); |
| 7 | + config.args.push("--cfg".into()); |
| 8 | + config.args.push("feature=\"tracing-log\"".into()); |
| 9 | + config.out_dir = Some("target/ui_test".into()); |
| 10 | + config.mode = Mode::Run { exit_code: 0 }; |
| 11 | + config.stdout_filter("[0-9]+(ms|s|m)", "$1"); |
| 12 | + config.stderr_filter("[0-9]+(ms|s|m)", "$1"); |
| 13 | + config.output_conflict_handling = if std::env::args().any(|arg| arg == "--bless") { |
| 14 | + OutputConflictHandling::Bless |
| 15 | + } else { |
| 16 | + OutputConflictHandling::Error |
| 17 | + }; |
| 18 | + run_tests(config) |
79 | 19 | }
|
0 commit comments