From 153856fe141108d7e10b2f67d82c8e5b1f3d7287 Mon Sep 17 00:00:00 2001 From: Weihang Lo Date: Tue, 18 Jun 2024 13:58:13 -0400 Subject: [PATCH 1/2] test: prefer raw string for regex reduction --- crates/cargo-test-support/src/compare.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/crates/cargo-test-support/src/compare.rs b/crates/cargo-test-support/src/compare.rs index 9a7f93bc557..919e33be460 100644 --- a/crates/cargo-test-support/src/compare.rs +++ b/crates/cargo-test-support/src/compare.rs @@ -149,32 +149,32 @@ fn add_common_redactions(subs: &mut snapbox::Redactions) { // For e2e tests subs.insert( "[ELAPSED]", - regex!("[FINISHED].*in (?[0-9]+(\\.[0-9]+))s"), + regex!(r"[FINISHED].*in (?[0-9]+(\.[0-9]+))s"), ) .unwrap(); // for UI tests subs.insert( "[ELAPSED]", - regex!("Finished.*in (?[0-9]+(\\.[0-9]+))s"), + regex!(r"Finished.*in (?[0-9]+(\.[0-9]+))s"), ) .unwrap(); // output from libtest subs.insert( "[ELAPSED]", - regex!("; finished in (?[0-9]+(\\.[0-9]+))s"), + regex!(r"; finished in (?[0-9]+(\.[0-9]+))s"), ) .unwrap(); subs.insert( "[FILE_SIZE]", - regex!("(?[0-9]+(\\.[0-9]+)([a-zA-Z]i)?)B"), + regex!(r"(?[0-9]+(\.[0-9]+)([a-zA-Z]i)?)B"), ) .unwrap(); subs.insert( "[HASH]", - regex!("home/\\.cargo/registry/src/-(?[a-z0-9]+)"), + regex!(r"home/\.cargo/registry/src/-(?[a-z0-9]+)"), ) .unwrap(); - subs.insert("[HASH]", regex!("/[a-z0-9\\-_]+-(?[0-9a-f]{16})")) + subs.insert("[HASH]", regex!(r"/[a-z0-9\-_]+-(?[0-9a-f]{16})")) .unwrap(); subs.insert("[HOST_TARGET]", rustc_host()).unwrap(); if let Some(alt_target) = try_alternate() { @@ -182,12 +182,12 @@ fn add_common_redactions(subs: &mut snapbox::Redactions) { } subs.insert( "[AVG_ELAPSED]", - regex!("(?[0-9]+(\\.[0-9]+)?) ns/iter"), + regex!(r"(?[0-9]+(\.[0-9]+)?) ns/iter"), ) .unwrap(); subs.insert( "[JITTER]", - regex!("ns/iter \\(\\+/- (?[0-9]+(\\.[0-9]+)?)\\)"), + regex!(r"ns/iter \(\+/- (?[0-9]+(\.[0-9]+)?)\)"), ) .unwrap(); } From 6a684edcb636a4b98755d9833fa31e79841df1fd Mon Sep 17 00:00:00 2001 From: Weihang Lo Date: Tue, 18 Jun 2024 13:58:56 -0400 Subject: [PATCH 2/2] test: fix the `[FINISHED]` escape --- crates/cargo-test-support/src/compare.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/cargo-test-support/src/compare.rs b/crates/cargo-test-support/src/compare.rs index 919e33be460..22dadef53ef 100644 --- a/crates/cargo-test-support/src/compare.rs +++ b/crates/cargo-test-support/src/compare.rs @@ -149,7 +149,7 @@ fn add_common_redactions(subs: &mut snapbox::Redactions) { // For e2e tests subs.insert( "[ELAPSED]", - regex!(r"[FINISHED].*in (?[0-9]+(\.[0-9]+))s"), + regex!(r"\[FINISHED\].*in (?[0-9]+(\.[0-9]+))s"), ) .unwrap(); // for UI tests