From db6e88014d36e6c5309efae3574639a9f552c049 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Mon, 25 Oct 2021 18:56:50 -0700 Subject: [PATCH 1/5] Add test for issue 136 --- src/tests.rs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/tests.rs b/src/tests.rs index e8ab77d..8c8b076 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -269,3 +269,33 @@ Additional crates such as `pyo3-asyncio` can be used to integrate async Rust and 10 | async fn async_function() {} | ^^^^^ "} + +// FIXME: should strip the line numbers on src/handler.rs +test_normalize! {test_dropshot_required_by + DIR="/git/dropshot/dropshot" + WORKSPACE="/git/dropshot" +" +error[E0277]: the trait bound `QueryParams: schemars::JsonSchema` is not satisfied + --> /git/dropshot/dropshot/tests/fail/bad_endpoint4.rs:24:14 + | +24 | _params: Query, + | ^^^^^^^^^^^^^^^^^^ the trait `schemars::JsonSchema` is not implemented for `QueryParams` + | +note: required by a bound in `dropshot::Query` + --> /git/dropshot/dropshot/src/handler.rs:547:48 + | +547 | pub struct Query { + | ^^^^^^^^^^ required by this bound in `dropshot::Query` +" " +error[E0277]: the trait bound `QueryParams: schemars::JsonSchema` is not satisfied + --> tests/fail/bad_endpoint4.rs:24:14 + | +24 | _params: Query, + | ^^^^^^^^^^^^^^^^^^ the trait `schemars::JsonSchema` is not implemented for `QueryParams` + | +note: required by a bound in `dropshot::Query` + --> src/handler.rs:547:48 + | +547 | pub struct Query { + | ^^^^^^^^^^ required by this bound in `dropshot::Query` +"} From d8c5756cbe98d20b55c42fa86a9c999ba1f3057b Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Mon, 25 Oct 2021 18:59:40 -0700 Subject: [PATCH 2/5] Add input file path to context for normalization --- src/normalize.rs | 2 ++ src/run.rs | 1 + src/tests.rs | 5 ++++- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/normalize.rs b/src/normalize.rs index a2111d1..2a034fb 100644 --- a/src/normalize.rs +++ b/src/normalize.rs @@ -4,12 +4,14 @@ mod tests; use crate::directory::Directory; use crate::run::PathDependency; +use std::path::Path; #[derive(Copy, Clone)] pub struct Context<'a> { pub krate: &'a str, pub source_dir: &'a Directory, pub workspace: &'a Directory, + pub input_file: &'a Path, pub path_dependencies: &'a [PathDependency], } diff --git a/src/run.rs b/src/run.rs index cc2f34e..cca7cf9 100644 --- a/src/run.rs +++ b/src/run.rs @@ -267,6 +267,7 @@ impl Test { krate: &name.0, source_dir: &project.source_dir, workspace: &project.workspace, + input_file: &self.path, path_dependencies: &project.path_dependencies, }, ); diff --git a/src/tests.rs b/src/tests.rs index 8c8b076..b4e432d 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -1,12 +1,14 @@ use crate::directory::Directory; use crate::run::PathDependency; +use std::path::Path; macro_rules! test_normalize { - ($name:ident $(DIR=$dir:literal)? $(WORKSPACE=$workspace:literal)? $original:literal $expected:literal) => { + ($name:ident $(DIR=$dir:literal)? $(WORKSPACE=$workspace:literal)? $(INPUT=$input:literal)? $original:literal $expected:literal) => { #[test] fn $name() { let context = super::Context { krate: "trybuild000", + input_file: Path::new({ "tests/ui/input.rs" $(; $input)? }), source_dir: &Directory::new({ "/git/trybuild/test_suite" $(; $dir)? }), workspace: &Directory::new({ "/git/trybuild" $(; $workspace)? }), path_dependencies: &[PathDependency { @@ -274,6 +276,7 @@ Additional crates such as `pyo3-asyncio` can be used to integrate async Rust and test_normalize! {test_dropshot_required_by DIR="/git/dropshot/dropshot" WORKSPACE="/git/dropshot" + INPUT="tests/fail/bad_endpoint4.rs" " error[E0277]: the trait bound `QueryParams: schemars::JsonSchema` is not satisfied --> /git/dropshot/dropshot/tests/fail/bad_endpoint4.rs:24:14 From 9db3ce59d868eb501d808e96351c47f10d991792 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Mon, 25 Oct 2021 19:16:18 -0700 Subject: [PATCH 3/5] Strip line numbers outside of the one input file --- src/normalize.rs | 43 ++++++++++++++++++++++++++++++++----------- src/tests.rs | 5 ++--- 2 files changed, 34 insertions(+), 14 deletions(-) diff --git a/src/normalize.rs b/src/normalize.rs index 2a034fb..13eabbc 100644 --- a/src/normalize.rs +++ b/src/normalize.rs @@ -58,6 +58,7 @@ pub fn diagnostics(output: Vec, context: Context) -> Variations { CargoRegistry, ArrowOtherCrate, RelativeToDir, + LinesOutsideInputFile, ] .iter() .map(|normalization| apply(&from_bytes, *normalization, context)) @@ -95,6 +96,7 @@ enum Normalization { CargoRegistry, ArrowOtherCrate, RelativeToDir, + LinesOutsideInputFile, // New normalization steps are to be inserted here at the end so that any // snapshots saved before your normalization change remain passing. } @@ -166,24 +168,43 @@ impl<'a> Filter<'a> { .to_string_lossy() .to_ascii_lowercase() .replace('\\', "/"); + let mut other_crate = false; if let Some(i) = line_lower.find(&source_dir_pat) { if self.normalization >= RelativeToDir && i == indent + 4 { line.replace_range(i..i + source_dir_pat.len(), ""); + if self.normalization < LinesOutsideInputFile { + return Some(line); + } + let input_file_pat = self + .context + .input_file + .to_string_lossy() + .to_ascii_lowercase() + .replace('\\', "/"); + if line_lower[i + source_dir_pat.len()..].starts_with(&input_file_pat) { + // Keep line numbers only within the input file (the + // path passed to our `fn compile_fail`. All other + // source files get line numbers erased below. + return Some(line); + } } else { line.replace_range(i..i + source_dir_pat.len() - 1, "$DIR"); + if self.normalization < LinesOutsideInputFile { + return Some(line); + } } - return Some(line); - } - let mut other_crate = false; - let workspace_pat = self - .context - .workspace - .to_string_lossy() - .to_ascii_lowercase() - .replace('\\', "/"); - if let Some(i) = line_lower.find(&workspace_pat) { - line.replace_range(i..i + workspace_pat.len() - 1, "$WORKSPACE"); other_crate = true; + } else { + let workspace_pat = self + .context + .workspace + .to_string_lossy() + .to_ascii_lowercase() + .replace('\\', "/"); + if let Some(i) = line_lower.find(&workspace_pat) { + line.replace_range(i..i + workspace_pat.len() - 1, "$WORKSPACE"); + other_crate = true; + } } if self.normalization >= PathDependencies && !other_crate { for path_dep in self.context.path_dependencies { diff --git a/src/tests.rs b/src/tests.rs index b4e432d..874e272 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -272,7 +272,6 @@ Additional crates such as `pyo3-asyncio` can be used to integrate async Rust and | ^^^^^ "} -// FIXME: should strip the line numbers on src/handler.rs test_normalize! {test_dropshot_required_by DIR="/git/dropshot/dropshot" WORKSPACE="/git/dropshot" @@ -297,8 +296,8 @@ error[E0277]: the trait bound `QueryParams: schemars::JsonSchema` is not satisfi | ^^^^^^^^^^^^^^^^^^ the trait `schemars::JsonSchema` is not implemented for `QueryParams` | note: required by a bound in `dropshot::Query` - --> src/handler.rs:547:48 + --> src/handler.rs | -547 | pub struct Query { + | pub struct Query { | ^^^^^^^^^^ required by this bound in `dropshot::Query` "} From 362c606914e814d2ee9e82bca825ea6acd0c1441 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Mon, 25 Oct 2021 19:40:54 -0700 Subject: [PATCH 4/5] Set appropriate input path on test cases to match prev result --- src/tests.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/tests.rs b/src/tests.rs index 874e272..f644e29 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -8,7 +8,7 @@ macro_rules! test_normalize { fn $name() { let context = super::Context { krate: "trybuild000", - input_file: Path::new({ "tests/ui/input.rs" $(; $input)? }), + input_file: Path::new({ "tests/ui/error.rs" $(; $input)? }), source_dir: &Directory::new({ "/git/trybuild/test_suite" $(; $dir)? }), workspace: &Directory::new({ "/git/trybuild" $(; $workspace)? }), path_dependencies: &[PathDependency { @@ -56,7 +56,9 @@ error[E0277]: the trait bound `QueryParams: serde::de::Deserialize<'de>` is not --> tests/ui/error.rs:22:61 "} -test_normalize! {test_rust_lib " +test_normalize! {test_rust_lib + INPUT="tests/ui/not-repeatable.rs" +" error[E0599]: no method named `quote_into_iter` found for struct `std::net::Ipv4Addr` in the current scope --> /git/trybuild/test_suite/tests/ui/not-repeatable.rs:6:13 | @@ -86,7 +88,9 @@ error[E0599]: no method named `quote_into_iter` found for struct `std::net::Ipv4 | doesn't satisfy `std::net::Ipv4Addr: quote::to_tokens::ToTokens` "} -test_normalize! {test_type_dir_backslash " +test_normalize! {test_type_dir_backslash + INPUT="tests/ui/compile-fail-3.rs" +" error[E0277]: `*mut _` cannot be shared between threads safely --> /git/trybuild/test_suite/tests/ui/compile-fail-3.rs:7:5 | From ae88a100fcd149bc90611bd5400e438de9e5dc23 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Mon, 25 Oct 2021 19:46:12 -0700 Subject: [PATCH 5/5] Link to issue 86 in dropshot test --- src/tests.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/tests.rs b/src/tests.rs index f644e29..604c1fb 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -292,7 +292,10 @@ note: required by a bound in `dropshot::Query` | 547 | pub struct Query { | ^^^^^^^^^^ required by this bound in `dropshot::Query` -" " +" +// TODO: it would be nice to also unindent the column of `|` by one column. +// https://github.com/dtolnay/trybuild/issues/86 +" error[E0277]: the trait bound `QueryParams: schemars::JsonSchema` is not satisfied --> tests/fail/bad_endpoint4.rs:24:14 |