From 5ea1c8fea94dba5956ae3970b9403d50c9ff1557 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Fri, 24 May 2024 12:59:29 -0500 Subject: [PATCH] feat(test): Auto-redact elapsed time --- Cargo.lock | 2 ++ Cargo.toml | 2 +- crates/cargo-test-support/Cargo.toml | 1 + crates/cargo-test-support/src/compare.rs | 5 +++++ tests/testsuite/lints/warning/stderr.term.svg | 2 +- 5 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index dcb4f31e1b6..c5e99f26c5f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -426,6 +426,7 @@ dependencies = [ "glob", "itertools 0.12.1", "pasetors", + "regex", "serde", "serde_json", "snapbox", @@ -3220,6 +3221,7 @@ dependencies = [ "escargot", "filetime", "normalize-line-endings", + "regex", "serde_json", "similar", "snapbox-macros", diff --git a/Cargo.toml b/Cargo.toml index c429c94bd65..36dbed8218a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -91,7 +91,7 @@ sha1 = "0.10.6" sha2 = "0.10.8" shell-escape = "0.1.5" supports-hyperlinks = "3.0.0" -snapbox = { version = "0.6.5", features = ["diff", "dir", "term-svg"] } +snapbox = { version = "0.6.5", features = ["diff", "dir", "term-svg", "regex"] } tar = { version = "0.4.40", default-features = false } tempfile = "3.10.1" thiserror = "1.0.59" diff --git a/crates/cargo-test-support/Cargo.toml b/crates/cargo-test-support/Cargo.toml index b5f01bab76d..9d6ca7303ef 100644 --- a/crates/cargo-test-support/Cargo.toml +++ b/crates/cargo-test-support/Cargo.toml @@ -24,6 +24,7 @@ git2.workspace = true glob.workspace = true itertools.workspace = true pasetors.workspace = true +regex.workspace = true serde = { workspace = true, features = ["derive"] } serde_json.workspace = true snapbox.workspace = true diff --git a/crates/cargo-test-support/src/compare.rs b/crates/cargo-test-support/src/compare.rs index 92745bb8690..2d33c61109c 100644 --- a/crates/cargo-test-support/src/compare.rs +++ b/crates/cargo-test-support/src/compare.rs @@ -86,6 +86,11 @@ pub fn assert_ui() -> snapbox::Assert { .unwrap(); subs.insert("[ROOT]", root).unwrap(); subs.insert("[ROOTURL]", root_url).unwrap(); + subs.insert( + "[ELAPSED]", + regex::Regex::new("Finished.*in (?[0-9]+(\\.[0-9]+))s").unwrap(), + ) + .unwrap(); snapbox::Assert::new() .action_env(snapbox::assert::DEFAULT_ACTION_ENV) .redact_with(subs) diff --git a/tests/testsuite/lints/warning/stderr.term.svg b/tests/testsuite/lints/warning/stderr.term.svg index 91ac9abde01..438823102be 100644 --- a/tests/testsuite/lints/warning/stderr.term.svg +++ b/tests/testsuite/lints/warning/stderr.term.svg @@ -37,7 +37,7 @@ Checking foo v0.0.1 ([ROOT]/foo) - Finished [..] + Finished `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s