From 508b39f622491569c3260d497aa036f3ebe453bb Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Thu, 7 Oct 2021 02:02:03 -0400 Subject: [PATCH] Omit leading $DIR on file paths --- src/normalize.rs | 9 ++++++++- src/tests.rs | 16 ++++++++-------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/normalize.rs b/src/normalize.rs index 416c466..09576b3 100644 --- a/src/normalize.rs +++ b/src/normalize.rs @@ -55,6 +55,7 @@ pub fn diagnostics(output: Vec, context: Context) -> Variations { PathDependencies, CargoRegistry, ArrowOtherCrate, + RelativeToDir, ] .iter() .map(|normalization| apply(&from_bytes, *normalization, context)) @@ -91,6 +92,7 @@ enum Normalization { PathDependencies, CargoRegistry, ArrowOtherCrate, + RelativeToDir, // New normalization steps are to be inserted here at the end so that any // snapshots saved before your normalization change remain passing. } @@ -136,6 +138,7 @@ impl<'a> Filter<'a> { } let trim_start = line.trim_start(); + let indent = line.len() - trim_start.len(); let prefix = if trim_start.starts_with("--> ") { Some("--> ") } else if trim_start.starts_with("::: ") { @@ -162,7 +165,11 @@ impl<'a> Filter<'a> { .to_ascii_lowercase() .replace('\\', "/"); if let Some(i) = line_lower.find(&source_dir_pat) { - line.replace_range(i..i + source_dir_pat.len() - 1, "$DIR"); + if self.normalization >= RelativeToDir && i == indent + 4 { + line.replace_range(i..i + source_dir_pat.len(), ""); + } else { + line.replace_range(i..i + source_dir_pat.len() - 1, "$DIR"); + } return Some(line); } let mut other_crate = false; diff --git a/src/tests.rs b/src/tests.rs index e8da4c2..79fe90e 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -27,7 +27,7 @@ macro_rules! test_normalize { test_normalize! {test_basic " error: `self` parameter is only allowed in associated functions - --> /git/trybuild/test_suite/ui/error.rs:11:23 + --> /git/trybuild/test_suite/tests/ui/error.rs:11:23 | 11 | async fn bad_endpoint(self) -> Result, HttpError> { | ^^^^ not semantically valid as function parameter @@ -40,7 +40,7 @@ error: could not compile `trybuild-tests`. To learn more, run the command again with --verbose. " " error: `self` parameter is only allowed in associated functions - --> $DIR/ui/error.rs:11:23 + --> tests/ui/error.rs:11:23 | 11 | async fn bad_endpoint(self) -> Result, HttpError> { | ^^^^ not semantically valid as function parameter @@ -48,15 +48,15 @@ error: `self` parameter is only allowed in associated functions test_normalize! {test_dir_backslash " error[E0277]: the trait bound `QueryParams: serde::de::Deserialize<'de>` is not satisfied - --> \\git\\trybuild\\test_suite\\ui\\error.rs:22:61 + --> \\git\\trybuild\\test_suite\\tests\\ui\\error.rs:22:61 " " error[E0277]: the trait bound `QueryParams: serde::de::Deserialize<'de>` is not satisfied - --> $DIR/ui/error.rs:22:61 + --> tests/ui/error.rs:22:61 "} test_normalize! {test_rust_lib " error[E0599]: no method named `quote_into_iter` found for struct `std::net::Ipv4Addr` in the current scope - --> /git/trybuild/test_suite/ui/not-repeatable.rs:6:13 + --> /git/trybuild/test_suite/tests/ui/not-repeatable.rs:6:13 | 6 | let _ = quote! { #(#ip)* }; | ^^^^^^^^^^^^^^^^^^ method not found in `std::net::Ipv4Addr` @@ -70,7 +70,7 @@ error[E0599]: no method named `quote_into_iter` found for struct `std::net::Ipv4 | doesn't satisfy `std::net::Ipv4Addr: quote::to_tokens::ToTokens` " " error[E0599]: no method named `quote_into_iter` found for struct `std::net::Ipv4Addr` in the current scope - --> $DIR/ui/not-repeatable.rs:6:13 + --> tests/ui/not-repeatable.rs:6:13 | 6 | let _ = quote! { #(#ip)* }; | ^^^^^^^^^^^^^^^^^^ method not found in `std::net::Ipv4Addr` @@ -86,7 +86,7 @@ error[E0599]: no method named `quote_into_iter` found for struct `std::net::Ipv4 test_normalize! {test_type_dir_backslash " error[E0277]: `*mut _` cannot be shared between threads safely - --> /git/trybuild/test_suite/ui/compile-fail-3.rs:7:5 + --> /git/trybuild/test_suite/tests/ui/compile-fail-3.rs:7:5 | 7 | thread::spawn(|| { | ^^^^^^^^^^^^^ `*mut _` cannot be shared between threads safely @@ -96,7 +96,7 @@ error[E0277]: `*mut _` cannot be shared between threads safely = note: required because it appears within the type `[closure@/git/trybuild/test_suite/ui/compile-fail-3.rs:7:19: 9:6 x:&*mut _]` " " error[E0277]: `*mut _` cannot be shared between threads safely - --> $DIR/ui/compile-fail-3.rs:7:5 + --> tests/ui/compile-fail-3.rs:7:5 | 7 | thread::spawn(|| { | ^^^^^^^^^^^^^ `*mut _` cannot be shared between threads safely