diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-30 18:31:44 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-30 18:31:44 +0000 |
commit | c23a457e72abe608715ac76f076f47dc42af07a5 (patch) | |
tree | 2772049aaf84b5c9d0ed12ec8d86812f7a7904b6 /vendor/tracing-tree/tests | |
parent | Releasing progress-linux version 1.73.0+dfsg1-1~progress7.99u1. (diff) | |
download | rustc-c23a457e72abe608715ac76f076f47dc42af07a5.tar.xz rustc-c23a457e72abe608715ac76f076f47dc42af07a5.zip |
Merging upstream version 1.74.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/tracing-tree/tests')
-rw-r--r-- | vendor/tracing-tree/tests/ui.rs | 98 |
1 files changed, 21 insertions, 77 deletions
diff --git a/vendor/tracing-tree/tests/ui.rs b/vendor/tracing-tree/tests/ui.rs index 68c54e66e..cca8241d1 100644 --- a/vendor/tracing-tree/tests/ui.rs +++ b/vendor/tracing-tree/tests/ui.rs @@ -1,79 +1,23 @@ -use assert_cmd::prelude::*; +use ui_test::{color_eyre::Result, run_tests, Config, Mode, OutputConflictHandling}; -use std::process::Command; - -// Timings are flaky, so tests would spuriously fail. -// Thus we replace all `/([0-9]+)ms/` with underscores -fn replace_ms(data: &[u8]) -> Vec<u8> { - let mut skip = false; - let mut seen_s = false; - let mut v: Vec<u8> = data - .iter() - .rev() - .filter_map(|&b| match (b, skip, seen_s) { - (b'0'..=b'9', true, _) => None, - (_, true, _) => { - skip = false; - Some(b) - } - (b's', _, _) => { - seen_s = true; - Some(b) - } - (b'm', _, true) => { - seen_s = false; - skip = true; - Some(b) - } - _ => Some(b), - }) - .collect(); - v.reverse(); - v -} - -fn main() { - for entry in glob::glob("examples/*.rs").expect("Failed to read glob pattern") { - let entry = entry.unwrap(); - let mut cmd = Command::cargo_bin(entry.with_extension("").to_str().unwrap()).unwrap(); - let output = cmd.unwrap(); - let stderr = entry.with_extension("stderr"); - let stdout = entry.with_extension("stdout"); - - if std::env::args().any(|arg| arg == "--bless") { - if output.stderr.is_empty() { - let _ = std::fs::remove_file(stderr); - } else { - std::fs::write(stderr, replace_ms(&output.stderr)).unwrap(); - } - if output.stdout.is_empty() { - let _ = std::fs::remove_file(stdout); - } else { - std::fs::write(stdout, replace_ms(&output.stdout)).unwrap(); - } - } else { - if output.stderr.is_empty() { - assert!( - !stderr.exists(), - "{} exists but there was no stderr output", - stderr.display() - ); - } else { - assert!( - std::fs::read(&stderr).unwrap() == replace_ms(&output.stderr), - "{} is not the expected output, rerun the test with `cargo test -- -- --bless`", - stderr.display() - ); - } - if output.stdout.is_empty() { - assert!(!stdout.exists()); - } else { - assert!( - std::fs::read(&stdout).unwrap() == replace_ms(&output.stdout), - "{} is not the expected output, rerun the test with `cargo test -- -- --bless`", - stdout.display() - ); - } - } - } +fn main() -> Result<()> { + let mut config = Config::default(); + config.root_dir = "examples".into(); + config.dependencies_crate_manifest_path = Some("test_dependencies/Cargo.toml".into()); + config.args.push("--cfg".into()); + config.args.push("feature=\"tracing-log\"".into()); + config.out_dir = Some("target/ui_test".into()); + config.mode = Mode::Run { exit_code: 0 }; + config.stdout_filter("[0-9]{3}(ms|s|m)", " X$1"); + config.stdout_filter("[0-9]{2}(ms|s|m)", " X$1"); + config.stdout_filter("[0-9]{1}(ms|s|m)", "X$1"); + config.stderr_filter("[0-9]{3}(ms|s|m)", " X$1"); + config.stderr_filter("[0-9]{2}(ms|s|m)", " X$1"); + config.stderr_filter("[0-9]{1}(ms|s|m)", "X$1"); + config.output_conflict_handling = if std::env::args().any(|arg| arg == "--bless") { + OutputConflictHandling::Bless + } else { + OutputConflictHandling::Error + }; + run_tests(config) } |