From cd1d0bc20cd2c18ec844f6447396dadf90b762e9 Mon Sep 17 00:00:00 2001 From: Tim Neumann Date: Fri, 6 Jan 2023 11:49:07 +0000 Subject: [PATCH] ui tests: Remap test base directory by default. --- src/tools/compiletest/src/header.rs | 3 ++ .../ui-fulldeps/mod_dir_path_canonicalized.rs | 1 + tests/ui/errors/auxiliary/remapped_dep.rs | 1 + ...emap-path-prefix-reverse.local-self.stderr | 6 ++-- ...p-path-prefix-reverse.remapped-self.stderr | 6 ++-- tests/ui/errors/remap-path-prefix-reverse.rs | 12 ++----- tests/ui/errors/remap-path-prefix.rs | 1 + tests/ui/errors/remap-path-prefix.stderr | 2 +- tests/ui/proc-macro/expand-expr.rs | 4 ++- tests/ui/proc-macro/expand-expr.stderr | 14 ++++---- .../pretty-print-hack-show.remapped.stderr | 32 +++++++++---------- .../pretty-print-hack-show.remapped.stdout | 16 +++++----- tests/ui/proc-macro/pretty-print-hack-show.rs | 7 ++-- 13 files changed, 52 insertions(+), 53 deletions(-) diff --git a/src/tools/compiletest/src/header.rs b/src/tools/compiletest/src/header.rs index fd4b51d637c1..899f068bd3d0 100644 --- a/src/tools/compiletest/src/header.rs +++ b/src/tools/compiletest/src/header.rs @@ -278,6 +278,9 @@ impl TestProps { /// `//[foo]`), then the property is ignored unless `cfg` is /// `Some("foo")`. fn load_from(&mut self, testfile: &Path, cfg: Option<&str>, config: &Config) { + // Mode-dependent defaults. + self.remap_src_base = config.mode == Mode::Ui && !config.suite.contains("rustdoc"); + let mut has_edition = false; if !testfile.is_dir() { let file = File::open(testfile).unwrap(); diff --git a/tests/ui-fulldeps/mod_dir_path_canonicalized.rs b/tests/ui-fulldeps/mod_dir_path_canonicalized.rs index ff1be0804151..bdfd9628c480 100644 --- a/tests/ui-fulldeps/mod_dir_path_canonicalized.rs +++ b/tests/ui-fulldeps/mod_dir_path_canonicalized.rs @@ -2,6 +2,7 @@ // Testing that a librustc_ast can parse modules with canonicalized base path // ignore-cross-compile // ignore-remote +// no-remap-src-base: Reading `file!()` (expectedly) fails when enabled. #![feature(rustc_private)] diff --git a/tests/ui/errors/auxiliary/remapped_dep.rs b/tests/ui/errors/auxiliary/remapped_dep.rs index ef26f1cd883f..f9bb7bf89870 100644 --- a/tests/ui/errors/auxiliary/remapped_dep.rs +++ b/tests/ui/errors/auxiliary/remapped_dep.rs @@ -1,3 +1,4 @@ // compile-flags: --remap-path-prefix={{src-base}}/errors/auxiliary=remapped-aux +// no-remap-src-base: Manually remap, so the remapped path remains in .stderr file. pub struct SomeStruct {} // This line should be show as part of the error. diff --git a/tests/ui/errors/remap-path-prefix-reverse.local-self.stderr b/tests/ui/errors/remap-path-prefix-reverse.local-self.stderr index 2584e3e88a6e..51e3b776cb2c 100644 --- a/tests/ui/errors/remap-path-prefix-reverse.local-self.stderr +++ b/tests/ui/errors/remap-path-prefix-reverse.local-self.stderr @@ -1,10 +1,10 @@ error[E0423]: expected value, found struct `remapped_dep::SomeStruct` - --> $DIR/remap-path-prefix-reverse.rs:22:13 + --> $DIR/remap-path-prefix-reverse.rs:16:13 | -LL | let _ = remapped_dep::SomeStruct; +LL | let _ = remapped_dep::SomeStruct; // ~ERROR E0423 | ^^^^^^^^^^^^^^^^^^^^^^^^ help: use struct literal syntax instead: `remapped_dep::SomeStruct {}` | - ::: remapped-aux/remapped_dep.rs:3:1 + ::: remapped-aux/remapped_dep.rs:4:1 | LL | pub struct SomeStruct {} // This line should be show as part of the error. | --------------------- `remapped_dep::SomeStruct` defined here diff --git a/tests/ui/errors/remap-path-prefix-reverse.remapped-self.stderr b/tests/ui/errors/remap-path-prefix-reverse.remapped-self.stderr index e710183322ac..51e3b776cb2c 100644 --- a/tests/ui/errors/remap-path-prefix-reverse.remapped-self.stderr +++ b/tests/ui/errors/remap-path-prefix-reverse.remapped-self.stderr @@ -1,10 +1,10 @@ error[E0423]: expected value, found struct `remapped_dep::SomeStruct` - --> remapped/errors/remap-path-prefix-reverse.rs:22:13 + --> $DIR/remap-path-prefix-reverse.rs:16:13 | -LL | let _ = remapped_dep::SomeStruct; +LL | let _ = remapped_dep::SomeStruct; // ~ERROR E0423 | ^^^^^^^^^^^^^^^^^^^^^^^^ help: use struct literal syntax instead: `remapped_dep::SomeStruct {}` | - ::: remapped-aux/remapped_dep.rs:3:1 + ::: remapped-aux/remapped_dep.rs:4:1 | LL | pub struct SomeStruct {} // This line should be show as part of the error. | --------------------- `remapped_dep::SomeStruct` defined here diff --git a/tests/ui/errors/remap-path-prefix-reverse.rs b/tests/ui/errors/remap-path-prefix-reverse.rs index 635c4164e0f8..71c80063c320 100644 --- a/tests/ui/errors/remap-path-prefix-reverse.rs +++ b/tests/ui/errors/remap-path-prefix-reverse.rs @@ -1,15 +1,9 @@ // aux-build:remapped_dep.rs // compile-flags: --remap-path-prefix={{src-base}}/errors/auxiliary=remapped-aux -// The remapped paths are not normalized by compiletest. -// normalize-stderr-test: "\\(errors)" -> "/$1" - // revisions: local-self remapped-self -// [remapped-self]compile-flags: --remap-path-prefix={{src-base}}=remapped - -// The paths from `remapped-self` aren't recognized by compiletest, so we -// cannot use line-specific patterns for the actual error. -// error-pattern: E0423 +// [local-self] no-remap-src-base: The hack should work regardless of remapping. +// [remapped-self] remap-src-base // Verify that the expected source code is shown. // error-pattern: pub struct SomeStruct {} // This line should be show @@ -19,5 +13,5 @@ extern crate remapped_dep; fn main() { // The actual error is irrelevant. The important part it that is should show // a snippet of the dependency's source. - let _ = remapped_dep::SomeStruct; + let _ = remapped_dep::SomeStruct; // ~ERROR E0423 } diff --git a/tests/ui/errors/remap-path-prefix.rs b/tests/ui/errors/remap-path-prefix.rs index 29b9c7be3012..393b8e22f1c1 100644 --- a/tests/ui/errors/remap-path-prefix.rs +++ b/tests/ui/errors/remap-path-prefix.rs @@ -1,4 +1,5 @@ // compile-flags: --remap-path-prefix={{src-base}}=remapped +// no-remap-src-base: Manually remap, so the remapped path remains in .stderr file. // The remapped paths are not normalized by compiletest. // normalize-stderr-test: "\\(errors)" -> "/$1" diff --git a/tests/ui/errors/remap-path-prefix.stderr b/tests/ui/errors/remap-path-prefix.stderr index 2f421283e699..62dbd4b8881a 100644 --- a/tests/ui/errors/remap-path-prefix.stderr +++ b/tests/ui/errors/remap-path-prefix.stderr @@ -1,5 +1,5 @@ error[E0425]: cannot find value `ferris` in this scope - --> remapped/errors/remap-path-prefix.rs:15:5 + --> remapped/errors/remap-path-prefix.rs:16:5 | LL | ferris | ^^^^^^ not found in this scope diff --git a/tests/ui/proc-macro/expand-expr.rs b/tests/ui/proc-macro/expand-expr.rs index 901b3a951023..700aac41c449 100644 --- a/tests/ui/proc-macro/expand-expr.rs +++ b/tests/ui/proc-macro/expand-expr.rs @@ -1,4 +1,6 @@ // aux-build:expand-expr.rs +// no-remap-src-base: check_expand_expr_file!() fails when enabled. + #![feature(concat_bytes)] extern crate expand_expr; @@ -8,7 +10,7 @@ use expand_expr::{ // Check builtin macros can be expanded. -expand_expr_is!(11u32, line!()); +expand_expr_is!(13u32, line!()); expand_expr_is!(24u32, column!()); expand_expr_is!("Hello, World!", concat!("Hello, ", "World", "!")); diff --git a/tests/ui/proc-macro/expand-expr.stderr b/tests/ui/proc-macro/expand-expr.stderr index 0004f2fe17f0..df61e9972896 100644 --- a/tests/ui/proc-macro/expand-expr.stderr +++ b/tests/ui/proc-macro/expand-expr.stderr @@ -1,29 +1,29 @@ error: expected one of `.`, `?`, or an operator, found `;` - --> $DIR/expand-expr.rs:106:27 + --> $DIR/expand-expr.rs:108:27 | LL | expand_expr_fail!("string"; hello); | ^ expected one of `.`, `?`, or an operator error: expected expression, found `$` - --> $DIR/expand-expr.rs:109:19 + --> $DIR/expand-expr.rs:111:19 | LL | expand_expr_fail!($); | ^ expected expression error: expected expression, found `$` - --> $DIR/expand-expr.rs:38:23 + --> $DIR/expand-expr.rs:40:23 | LL | ($($t:tt)*) => { $($t)* }; | ^^^^ expected expression error: expected expression, found `$` - --> $DIR/expand-expr.rs:111:28 + --> $DIR/expand-expr.rs:113:28 | LL | expand_expr_fail!(echo_pm!($)); | ^ expected expression error: macro expansion ignores token `hello` and any following - --> $DIR/expand-expr.rs:115:47 + --> $DIR/expand-expr.rs:117:47 | LL | expand_expr_is!("string", echo_tts!("string"; hello)); | --------------------^^^^^- caused by the macro expansion here @@ -35,7 +35,7 @@ LL | expand_expr_is!("string", echo_tts!("string"; hello);); | + error: macro expansion ignores token `;` and any following - --> $DIR/expand-expr.rs:116:44 + --> $DIR/expand-expr.rs:118:44 | LL | expand_expr_is!("string", echo_pm!("string"; hello)); | -----------------^------- caused by the macro expansion here @@ -47,7 +47,7 @@ LL | expand_expr_is!("string", echo_pm!("string"; hello);); | + error: recursion limit reached while expanding `recursive_expand!` - --> $DIR/expand-expr.rs:124:16 + --> $DIR/expand-expr.rs:126:16 | LL | const _: u32 = recursive_expand!(); | ^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/proc-macro/pretty-print-hack-show.remapped.stderr b/tests/ui/proc-macro/pretty-print-hack-show.remapped.stderr index ab5013848891..873054927c96 100644 --- a/tests/ui/proc-macro/pretty-print-hack-show.remapped.stderr +++ b/tests/ui/proc-macro/pretty-print-hack-show.remapped.stderr @@ -1,5 +1,5 @@ error: using an old version of `rental` - --> remapped/proc-macro/pretty-print-hack/allsorts-rental-0.5.6/src/lib.rs:4:6 + --> $DIR/pretty-print-hack/allsorts-rental-0.5.6/src/lib.rs:4:6 | LL | enum ProceduralMasqueradeDummyType { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -10,7 +10,7 @@ LL | enum ProceduralMasqueradeDummyType { = note: `#[deny(proc_macro_back_compat)]` on by default error: using an old version of `rental` - --> remapped/proc-macro/pretty-print-hack/allsorts-rental-0.5.6/src/lib.rs:4:6 + --> $DIR/pretty-print-hack/allsorts-rental-0.5.6/src/lib.rs:4:6 | LL | enum ProceduralMasqueradeDummyType { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -20,7 +20,7 @@ LL | enum ProceduralMasqueradeDummyType { = note: older versions of the `rental` crate will stop compiling in future versions of Rust; please update to `rental` v0.5.6, or switch to one of the `rental` alternatives error: using an old version of `rental` - --> remapped/proc-macro/pretty-print-hack/allsorts-rental-0.5.6/src/lib.rs:4:6 + --> $DIR/pretty-print-hack/allsorts-rental-0.5.6/src/lib.rs:4:6 | LL | enum ProceduralMasqueradeDummyType { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -30,7 +30,7 @@ LL | enum ProceduralMasqueradeDummyType { = note: older versions of the `rental` crate will stop compiling in future versions of Rust; please update to `rental` v0.5.6, or switch to one of the `rental` alternatives error: using an old version of `rental` - --> remapped/proc-macro/pretty-print-hack/allsorts-rental-0.5.6/src/lib.rs:4:6 + --> $DIR/pretty-print-hack/allsorts-rental-0.5.6/src/lib.rs:4:6 | LL | enum ProceduralMasqueradeDummyType { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -40,7 +40,7 @@ LL | enum ProceduralMasqueradeDummyType { = note: older versions of the `rental` crate will stop compiling in future versions of Rust; please update to `rental` v0.5.6, or switch to one of the `rental` alternatives error: using an old version of `rental` - --> remapped/proc-macro/pretty-print-hack/rental-0.5.5/src/lib.rs:4:6 + --> $DIR/pretty-print-hack/rental-0.5.5/src/lib.rs:4:6 | LL | enum ProceduralMasqueradeDummyType { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -50,7 +50,7 @@ LL | enum ProceduralMasqueradeDummyType { = note: older versions of the `rental` crate will stop compiling in future versions of Rust; please update to `rental` v0.5.6, or switch to one of the `rental` alternatives error: using an old version of `rental` - --> remapped/proc-macro/pretty-print-hack/rental-0.5.5/src/lib.rs:4:6 + --> $DIR/pretty-print-hack/rental-0.5.5/src/lib.rs:4:6 | LL | enum ProceduralMasqueradeDummyType { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -60,7 +60,7 @@ LL | enum ProceduralMasqueradeDummyType { = note: older versions of the `rental` crate will stop compiling in future versions of Rust; please update to `rental` v0.5.6, or switch to one of the `rental` alternatives error: using an old version of `rental` - --> remapped/proc-macro/pretty-print-hack/rental-0.5.5/src/lib.rs:4:6 + --> $DIR/pretty-print-hack/rental-0.5.5/src/lib.rs:4:6 | LL | enum ProceduralMasqueradeDummyType { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -70,7 +70,7 @@ LL | enum ProceduralMasqueradeDummyType { = note: older versions of the `rental` crate will stop compiling in future versions of Rust; please update to `rental` v0.5.6, or switch to one of the `rental` alternatives error: using an old version of `rental` - --> remapped/proc-macro/pretty-print-hack/rental-0.5.5/src/lib.rs:4:6 + --> $DIR/pretty-print-hack/rental-0.5.5/src/lib.rs:4:6 | LL | enum ProceduralMasqueradeDummyType { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -83,7 +83,7 @@ error: aborting due to 8 previous errors Future incompatibility report: Future breakage diagnostic: error: using an old version of `rental` - --> remapped/proc-macro/pretty-print-hack/allsorts-rental-0.5.6/src/lib.rs:4:6 + --> $DIR/pretty-print-hack/allsorts-rental-0.5.6/src/lib.rs:4:6 | LL | enum ProceduralMasqueradeDummyType { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -95,7 +95,7 @@ LL | enum ProceduralMasqueradeDummyType { Future breakage diagnostic: error: using an old version of `rental` - --> remapped/proc-macro/pretty-print-hack/allsorts-rental-0.5.6/src/lib.rs:4:6 + --> $DIR/pretty-print-hack/allsorts-rental-0.5.6/src/lib.rs:4:6 | LL | enum ProceduralMasqueradeDummyType { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -107,7 +107,7 @@ LL | enum ProceduralMasqueradeDummyType { Future breakage diagnostic: error: using an old version of `rental` - --> remapped/proc-macro/pretty-print-hack/allsorts-rental-0.5.6/src/lib.rs:4:6 + --> $DIR/pretty-print-hack/allsorts-rental-0.5.6/src/lib.rs:4:6 | LL | enum ProceduralMasqueradeDummyType { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -119,7 +119,7 @@ LL | enum ProceduralMasqueradeDummyType { Future breakage diagnostic: error: using an old version of `rental` - --> remapped/proc-macro/pretty-print-hack/allsorts-rental-0.5.6/src/lib.rs:4:6 + --> $DIR/pretty-print-hack/allsorts-rental-0.5.6/src/lib.rs:4:6 | LL | enum ProceduralMasqueradeDummyType { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -131,7 +131,7 @@ LL | enum ProceduralMasqueradeDummyType { Future breakage diagnostic: error: using an old version of `rental` - --> remapped/proc-macro/pretty-print-hack/rental-0.5.5/src/lib.rs:4:6 + --> $DIR/pretty-print-hack/rental-0.5.5/src/lib.rs:4:6 | LL | enum ProceduralMasqueradeDummyType { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -143,7 +143,7 @@ LL | enum ProceduralMasqueradeDummyType { Future breakage diagnostic: error: using an old version of `rental` - --> remapped/proc-macro/pretty-print-hack/rental-0.5.5/src/lib.rs:4:6 + --> $DIR/pretty-print-hack/rental-0.5.5/src/lib.rs:4:6 | LL | enum ProceduralMasqueradeDummyType { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -155,7 +155,7 @@ LL | enum ProceduralMasqueradeDummyType { Future breakage diagnostic: error: using an old version of `rental` - --> remapped/proc-macro/pretty-print-hack/rental-0.5.5/src/lib.rs:4:6 + --> $DIR/pretty-print-hack/rental-0.5.5/src/lib.rs:4:6 | LL | enum ProceduralMasqueradeDummyType { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -167,7 +167,7 @@ LL | enum ProceduralMasqueradeDummyType { Future breakage diagnostic: error: using an old version of `rental` - --> remapped/proc-macro/pretty-print-hack/rental-0.5.5/src/lib.rs:4:6 + --> $DIR/pretty-print-hack/rental-0.5.5/src/lib.rs:4:6 | LL | enum ProceduralMasqueradeDummyType { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/proc-macro/pretty-print-hack-show.remapped.stdout b/tests/ui/proc-macro/pretty-print-hack-show.remapped.stdout index 61ca53b28d40..3d793d2a0145 100644 --- a/tests/ui/proc-macro/pretty-print-hack-show.remapped.stdout +++ b/tests/ui/proc-macro/pretty-print-hack-show.remapped.stdout @@ -3,21 +3,21 @@ PRINT-DERIVE RE-COLLECTED (DISPLAY): enum ProceduralMasqueradeDummyType { Input PRINT-DERIVE INPUT (DEBUG): TokenStream [ Ident { ident: "enum", - span: remapped/proc-macro/pretty-print-hack/allsorts-rental-0.5.6/src/lib.rs:4:1: 4:5 (#0), + span: $DIR/pretty-print-hack/allsorts-rental-0.5.6/src/lib.rs:4:1: 4:5 (#0), }, Ident { ident: "ProceduralMasqueradeDummyType", - span: remapped/proc-macro/pretty-print-hack/allsorts-rental-0.5.6/src/lib.rs:4:6: 4:35 (#0), + span: $DIR/pretty-print-hack/allsorts-rental-0.5.6/src/lib.rs:4:6: 4:35 (#0), }, Group { delimiter: Brace, stream: TokenStream [ Ident { ident: "Input", - span: remapped/proc-macro/pretty-print-hack/allsorts-rental-0.5.6/src/lib.rs:13:5: 13:10 (#0), + span: $DIR/pretty-print-hack/allsorts-rental-0.5.6/src/lib.rs:13:5: 13:10 (#0), }, ], - span: remapped/proc-macro/pretty-print-hack/allsorts-rental-0.5.6/src/lib.rs:4:36: 14:2 (#0), + span: $DIR/pretty-print-hack/allsorts-rental-0.5.6/src/lib.rs:4:36: 14:2 (#0), }, ] PRINT-DERIVE INPUT (DISPLAY): enum ProceduralMasqueradeDummyType { Input, } @@ -25,20 +25,20 @@ PRINT-DERIVE RE-COLLECTED (DISPLAY): enum ProceduralMasqueradeDummyType { Input PRINT-DERIVE INPUT (DEBUG): TokenStream [ Ident { ident: "enum", - span: remapped/proc-macro/pretty-print-hack/rental-0.5.5/src/lib.rs:4:1: 4:5 (#0), + span: $DIR/pretty-print-hack/rental-0.5.5/src/lib.rs:4:1: 4:5 (#0), }, Ident { ident: "ProceduralMasqueradeDummyType", - span: remapped/proc-macro/pretty-print-hack/rental-0.5.5/src/lib.rs:4:6: 4:35 (#0), + span: $DIR/pretty-print-hack/rental-0.5.5/src/lib.rs:4:6: 4:35 (#0), }, Group { delimiter: Brace, stream: TokenStream [ Ident { ident: "Input", - span: remapped/proc-macro/pretty-print-hack/rental-0.5.5/src/lib.rs:13:5: 13:10 (#0), + span: $DIR/pretty-print-hack/rental-0.5.5/src/lib.rs:13:5: 13:10 (#0), }, ], - span: remapped/proc-macro/pretty-print-hack/rental-0.5.5/src/lib.rs:4:36: 14:2 (#0), + span: $DIR/pretty-print-hack/rental-0.5.5/src/lib.rs:4:36: 14:2 (#0), }, ] diff --git a/tests/ui/proc-macro/pretty-print-hack-show.rs b/tests/ui/proc-macro/pretty-print-hack-show.rs index e9ff66ba45a0..24a389c450ea 100644 --- a/tests/ui/proc-macro/pretty-print-hack-show.rs +++ b/tests/ui/proc-macro/pretty-print-hack-show.rs @@ -1,11 +1,8 @@ // aux-build:test-macros.rs // compile-flags: -Z span-debug // revisions: local remapped -// [remapped]compile-flags: --remap-path-prefix={{src-base}}=remapped - -// The remapped paths are not normalized by compiletest. -// normalize-stdout-test: "\\(proc-macro|pretty-print-hack)" -> "/$1" -// normalize-stderr-test: "\\(proc-macro|pretty-print-hack)" -> "/$1" +// [local] no-remap-src-base: The hack should work regardless of remapping. +// [remapped] remap-src-base #![no_std] // Don't load unnecessary hygiene information from std extern crate std;