Skip to content

Commit

Permalink
fix(test): improve sensitivity of hygene tests
Browse files Browse the repository at this point in the history
The change in 07f855d introduced a
trailing numeral of some kind after the `extern crate
compiler_builtins`, which appears to have caused at least two false
negatives (654b924 and 657fd24). Instead, this change normalizes the
test output to ignore the number (of symbols rustc recognizes?) to avoid
needing to re-`--bless` these two tests for unrelated changes.
  • Loading branch information
sethp committed Aug 9, 2023
1 parent d88ab22 commit 26bd86d
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
4 changes: 3 additions & 1 deletion tests/ui/proc-macro/meta-macro-hygiene.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
// edition:2018
// compile-flags: -Z span-debug -Z macro-backtrace -Z unpretty=expanded,hygiene -Z trim-diagnostic-paths=no
// check-pass
// ignore-tidy-linelength
// normalize-stdout-test "\d+#" -> "0#"
// normalize-stdout-test "expn\d{3,}" -> "expnNNN"
// normalize-stdout-test "extern crate compiler_builtins /\* \d+ \*/" -> "extern crate compiler_builtins /* NNN */"
//
// We don't care about symbol ids, so we set them all to 0
// in the stdout
Expand All @@ -22,7 +24,7 @@ macro_rules! produce_it {
// the fact that `print_def_site` is produced by a
// `macro_rules!` macro in `make_macro`).
meta_macro::print_def_site!($crate::dummy!());
}
};
}

fn main() {
Expand Down
8 changes: 5 additions & 3 deletions tests/ui/proc-macro/meta-macro-hygiene.stdout
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
Def site: $DIR/auxiliary/make-macro.rs:7:9: 7:56 (#4)
Input: TokenStream [Ident { ident: "$crate", span: $DIR/meta-macro-hygiene.rs:24:37: 24:43 (#3) }, Punct { ch: ':', spacing: Joint, span: $DIR/meta-macro-hygiene.rs:24:43: 24:44 (#3) }, Punct { ch: ':', spacing: Alone, span: $DIR/meta-macro-hygiene.rs:24:44: 24:45 (#3) }, Ident { ident: "dummy", span: $DIR/meta-macro-hygiene.rs:24:45: 24:50 (#3) }, Punct { ch: '!', spacing: Alone, span: $DIR/meta-macro-hygiene.rs:24:50: 24:51 (#3) }, Group { delimiter: Parenthesis, stream: TokenStream [], span: $DIR/meta-macro-hygiene.rs:24:51: 24:53 (#3) }]
Input: TokenStream [Ident { ident: "$crate", span: $DIR/meta-macro-hygiene.rs:26:37: 26:43 (#3) }, Punct { ch: ':', spacing: Joint, span: $DIR/meta-macro-hygiene.rs:26:43: 26:44 (#3) }, Punct { ch: ':', spacing: Alone, span: $DIR/meta-macro-hygiene.rs:26:44: 26:45 (#3) }, Ident { ident: "dummy", span: $DIR/meta-macro-hygiene.rs:26:45: 26:50 (#3) }, Punct { ch: '!', spacing: Alone, span: $DIR/meta-macro-hygiene.rs:26:50: 26:51 (#3) }, Group { delimiter: Parenthesis, stream: TokenStream [], span: $DIR/meta-macro-hygiene.rs:26:51: 26:53 (#3) }]
Respanned: TokenStream [Ident { ident: "$crate", span: $DIR/auxiliary/make-macro.rs:7:9: 7:56 (#4) }, Punct { ch: ':', spacing: Joint, span: $DIR/auxiliary/make-macro.rs:7:9: 7:56 (#4) }, Punct { ch: ':', spacing: Alone, span: $DIR/auxiliary/make-macro.rs:7:9: 7:56 (#4) }, Ident { ident: "dummy", span: $DIR/auxiliary/make-macro.rs:7:9: 7:56 (#4) }, Punct { ch: '!', spacing: Alone, span: $DIR/auxiliary/make-macro.rs:7:9: 7:56 (#4) }, Group { delimiter: Parenthesis, stream: TokenStream [], span: $DIR/auxiliary/make-macro.rs:7:9: 7:56 (#4) }]
#![feature /* 0#0 */(prelude_import)]
// aux-build:make-macro.rs
// aux-build:meta-macro.rs
// edition:2018
// compile-flags: -Z span-debug -Z macro-backtrace -Z unpretty=expanded,hygiene -Z trim-diagnostic-paths=no
// check-pass
// ignore-tidy-linelength
// normalize-stdout-test "\d+#" -> "0#"
// normalize-stdout-test "expn\d{3,}" -> "expnNNN"
// normalize-stdout-test "extern crate compiler_builtins /\* \d+ \*/" -> "extern crate compiler_builtins /* NNN */"
//
// We don't care about symbol ids, so we set them all to 0
// in the stdout
Expand All @@ -18,7 +20,7 @@ Respanned: TokenStream [Ident { ident: "$crate", span: $DIR/auxiliary/make-macro
use core /* 0#1 */::prelude /* 0#1 */::rust_2018 /* 0#1 */::*;
#[macro_use /* 0#1 */]
extern crate core /* 0#1 */;
extern crate compiler_builtins /* 445 */ as _ /* 0#1 */;
extern crate compiler_builtins /* NNN */ as _ /* 0#1 */;
// Don't load unnecessary hygiene information from std
extern crate std /* 0#0 */;

Expand All @@ -36,7 +38,7 @@ macro_rules! produce_it
// relative to `meta_macro`, *not* `make_macro` (despite
// the fact that `print_def_site` is produced by a
// `macro_rules!` macro in `make_macro`).
}
} ;
}

fn main /* 0#0 */() { ; }
Expand Down
3 changes: 2 additions & 1 deletion tests/ui/proc-macro/nonterminal-token-hygiene.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
// check-pass
// compile-flags: -Z span-debug -Z macro-backtrace -Z unpretty=expanded,hygiene
// compile-flags: -Z trim-diagnostic-paths=no
// ignore-tidy-linelength
// normalize-stdout-test "\d+#" -> "0#"
// normalize-stdout-test "expn\d{3,}" -> "expnNNN"
// normalize-stdout-test "extern crate compiler_builtins /\* \d+ \*/" -> "extern crate compiler_builtins /* NNN */"
// aux-build:test-macros.rs

#![feature(decl_macro)]

#![no_std] // Don't load unnecessary hygiene information from std
extern crate std;

Expand Down
13 changes: 7 additions & 6 deletions tests/ui/proc-macro/nonterminal-token-hygiene.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ PRINT-BANG INPUT (DEBUG): TokenStream [
stream: TokenStream [
Ident {
ident: "struct",
span: $DIR/nonterminal-token-hygiene.rs:31:5: 31:11 (#4),
span: $DIR/nonterminal-token-hygiene.rs:32:5: 32:11 (#4),
},
Ident {
ident: "S",
span: $DIR/nonterminal-token-hygiene.rs:31:12: 31:13 (#4),
span: $DIR/nonterminal-token-hygiene.rs:32:12: 32:13 (#4),
},
Punct {
ch: ';',
spacing: Alone,
span: $DIR/nonterminal-token-hygiene.rs:31:13: 31:14 (#4),
span: $DIR/nonterminal-token-hygiene.rs:32:13: 32:14 (#4),
},
],
span: $DIR/nonterminal-token-hygiene.rs:21:27: 21:32 (#5),
span: $DIR/nonterminal-token-hygiene.rs:22:27: 22:32 (#5),
},
]
#![feature /* 0#0 */(prelude_import)]
Expand All @@ -28,18 +28,19 @@ PRINT-BANG INPUT (DEBUG): TokenStream [
// check-pass
// compile-flags: -Z span-debug -Z macro-backtrace -Z unpretty=expanded,hygiene
// compile-flags: -Z trim-diagnostic-paths=no
// ignore-tidy-linelength
// normalize-stdout-test "\d+#" -> "0#"
// normalize-stdout-test "expn\d{3,}" -> "expnNNN"
// normalize-stdout-test "extern crate compiler_builtins /\* \d+ \*/" -> "extern crate compiler_builtins /* NNN */"
// aux-build:test-macros.rs

#![feature /* 0#0 */(decl_macro)]

#![no_std /* 0#0 */]
#[prelude_import /* 0#1 */]
use ::core /* 0#1 */::prelude /* 0#1 */::rust_2015 /* 0#1 */::*;
#[macro_use /* 0#1 */]
extern crate core /* 0#2 */;
extern crate compiler_builtins /* 445 */ as _ /* 0#2 */;
extern crate compiler_builtins /* NNN */ as _ /* 0#2 */;
// Don't load unnecessary hygiene information from std
extern crate std /* 0#0 */;

Expand Down

0 comments on commit 26bd86d

Please sign in to comment.