Skip to content

Commit e972aac

Browse files
committed
update for test directive rename; split out comparison code
1 parent 92768e5 commit e972aac

8 files changed

+97
-96
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/** If at all possible, rather
2+
than removing the assert that the different revisions behave the same, move
3+
only the revisions that are failing into a separate test, so that the rest
4+
are still kept the same.
5+
*/
6+
use std::collections::BTreeMap;
7+
8+
use run_make_support::path_helpers::source_root;
9+
10+
fn main() {
11+
// compiletest generates a bunch of files for each revision. make sure they're all the same.
12+
let mut files = BTreeMap::new();
13+
// let dir = Path::new(env!("SOURCE_DIR")).join("backtrace");
14+
let dir = source_root().join("tests").join("ui").join("backtrace");
15+
for file in std::fs::read_dir(dir).unwrap() {
16+
let file = file.unwrap();
17+
let name = file.file_name().into_string().unwrap();
18+
if !file.file_type().unwrap().is_file()
19+
|| !name.starts_with("std-backtrace-skip-frames.")
20+
|| !name.ends_with(".run.stderr")
21+
{
22+
continue;
23+
}
24+
files.insert(name, std::fs::read_to_string(file.path()).unwrap());
25+
}
26+
27+
let mut first_line_tables = None;
28+
let mut first_full = None;
29+
30+
for (name, contents) in &files {
31+
// These have different output. Rather than duplicating this whole test,
32+
// just special-case them here.
33+
let target = if name.contains(".full.") || name.contains(".limited.") {
34+
&mut first_full
35+
} else {
36+
&mut first_line_tables
37+
};
38+
if let Some((target_name, target_contents)) = target {
39+
if contents != *target_contents {
40+
eprintln!(
41+
"are you *sure* that you want {name} to have different backtrace output\
42+
than {target_name}?"
43+
);
44+
eprintln!(
45+
"NOTE: this test is stateful; run \
46+
`rm tests/ui/backtrace/std-backtrace-skip-frames.*.stderr` to reset it"
47+
);
48+
std::process::exit(0);
49+
}
50+
} else {
51+
// compiletest doesn't support negative matching for `error-pattern`. Do that here.
52+
assert!(!contents.contains("FnOnce::call_once"));
53+
*target = Some((name, contents));
54+
}
55+
}
56+
}

tests/ui/backtrace/std-backtrace-skip-frames.full.run.stderr

+4-5
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,14 @@ thread 'main' panicked at $DIR/std-backtrace-skip-frames.rs:LL:CC:
6868
explicit panic
6969
stack backtrace:
7070
[... omitted N frames ...]
71-
0: std_backtrace_skip_frames::check_all_panics
72-
at $DIR/std-backtrace-skip-frames.rs:LL:CC
73-
1: std_backtrace_skip_frames::main::{{closure}}
71+
0: std_backtrace_skip_frames::check_all_panics::{{closure}}
7472
at $DIR/std-backtrace-skip-frames.rs:LL:CC
7573
[... omitted N frames ...]
76-
2: std::panic::catch_unwind
74+
1: std::panic::catch_unwind
7775
at $SRC_DIR/std/src/panic.rs:LL:COL
76+
2: std_backtrace_skip_frames::check_all_panics
77+
at $DIR/std-backtrace-skip-frames.rs:LL:CC
7878
3: std_backtrace_skip_frames::main
7979
at $DIR/std-backtrace-skip-frames.rs:LL:CC
8080
[... omitted N frames ...]
8181
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
82-
finished all checks

tests/ui/backtrace/std-backtrace-skip-frames.limited.run.stderr

+4-5
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,14 @@ thread 'main' panicked at $DIR/std-backtrace-skip-frames.rs:LL:CC:
6868
explicit panic
6969
stack backtrace:
7070
[... omitted N frames ...]
71-
0: std_backtrace_skip_frames::check_all_panics
72-
at $DIR/std-backtrace-skip-frames.rs:LL:CC
73-
1: std_backtrace_skip_frames::main::{{closure}}
71+
0: std_backtrace_skip_frames::check_all_panics::{{closure}}
7472
at $DIR/std-backtrace-skip-frames.rs:LL:CC
7573
[... omitted N frames ...]
76-
2: std::panic::catch_unwind
74+
1: std::panic::catch_unwind
7775
at $SRC_DIR/std/src/panic.rs:LL:COL
76+
2: std_backtrace_skip_frames::check_all_panics
77+
at $DIR/std-backtrace-skip-frames.rs:LL:CC
7878
3: std_backtrace_skip_frames::main
7979
at $DIR/std-backtrace-skip-frames.rs:LL:CC
8080
[... omitted N frames ...]
8181
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
82-
finished all checks

tests/ui/backtrace/std-backtrace-skip-frames.line-tables.run.stderr

+4-5
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,14 @@ thread 'main' panicked at $DIR/std-backtrace-skip-frames.rs:LL:CC:
6868
explicit panic
6969
stack backtrace:
7070
[... omitted N frames ...]
71-
0: check_all_panics
72-
at $DIR/std-backtrace-skip-frames.rs:LL:CC
73-
1: {closure#0}
71+
0: {closure#2}
7472
at $DIR/std-backtrace-skip-frames.rs:LL:CC
7573
[... omitted N frames ...]
76-
2: catch_unwind<std_backtrace_skip_frames::main::{closure_env#0}, ()>
74+
1: catch_unwind<std_backtrace_skip_frames::check_all_panics::{closure_env#2}, ()>
7775
at $SRC_DIR/std/src/panic.rs:LL:COL
76+
2: check_all_panics
77+
at $DIR/std-backtrace-skip-frames.rs:LL:CC
7878
3: main
7979
at $DIR/std-backtrace-skip-frames.rs:LL:CC
8080
[... omitted N frames ...]
8181
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
82-
finished all checks

tests/ui/backtrace/std-backtrace-skip-frames.no-split.run.stderr

+4-5
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,14 @@ thread 'main' panicked at $DIR/std-backtrace-skip-frames.rs:LL:CC:
6868
explicit panic
6969
stack backtrace:
7070
[... omitted N frames ...]
71-
0: check_all_panics
72-
at $DIR/std-backtrace-skip-frames.rs:LL:CC
73-
1: {closure#0}
71+
0: {closure#2}
7472
at $DIR/std-backtrace-skip-frames.rs:LL:CC
7573
[... omitted N frames ...]
76-
2: catch_unwind<std_backtrace_skip_frames::main::{closure_env#0}, ()>
74+
1: catch_unwind<std_backtrace_skip_frames::check_all_panics::{closure_env#2}, ()>
7775
at $SRC_DIR/std/src/panic.rs:LL:COL
76+
2: check_all_panics
77+
at $DIR/std-backtrace-skip-frames.rs:LL:CC
7878
3: main
7979
at $DIR/std-backtrace-skip-frames.rs:LL:CC
8080
[... omitted N frames ...]
8181
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
82-
finished all checks

tests/ui/backtrace/std-backtrace-skip-frames.packed.run.stderr

+4-5
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,14 @@ thread 'main' panicked at $DIR/std-backtrace-skip-frames.rs:LL:CC:
6868
explicit panic
6969
stack backtrace:
7070
[... omitted N frames ...]
71-
0: check_all_panics
72-
at $DIR/std-backtrace-skip-frames.rs:LL:CC
73-
1: {closure#0}
71+
0: {closure#2}
7472
at $DIR/std-backtrace-skip-frames.rs:LL:CC
7573
[... omitted N frames ...]
76-
2: catch_unwind<std_backtrace_skip_frames::main::{closure_env#0}, ()>
74+
1: catch_unwind<std_backtrace_skip_frames::check_all_panics::{closure_env#2}, ()>
7775
at $SRC_DIR/std/src/panic.rs:LL:COL
76+
2: check_all_panics
77+
at $DIR/std-backtrace-skip-frames.rs:LL:CC
7878
3: main
7979
at $DIR/std-backtrace-skip-frames.rs:LL:CC
8080
[... omitted N frames ...]
8181
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
82-
finished all checks
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
/* This tests a lot of fiddly platform-specific impl details.
2-
It will probably flake a lot for a while. Feel free to split it up into
3-
different tests or add more `ignore-` directives. If at all possible, rather
4-
than removing the assert that the different revisions behave the same, move
5-
only the revisions that are failing into a separate test, so that the rest
6-
are still kept the same.
7-
8-
TODO: this test is megacursed, either split it into a separate run-make test
9-
that looks at the .stderr files or get `compare-mode` working
10-
*/
2+
It will probably flake a lot for a while. Feel free to split it up into
3+
different tests or add more `ignore-` directives.
4+
*/
115

126
//@ ignore-android FIXME #17520
137
//@ ignore-wasm32 spawning processes is not supported
@@ -18,13 +12,11 @@
1812

1913
//@ run-pass
2014
//@ check-run-results
21-
//@ normalize-stderr-test: "omitted [0-9]+ frames" -> "omitted N frames"
22-
//@ normalize-stderr-test: ".rs:[0-9]+:[0-9]+" -> ".rs:LL:CC"
15+
//@ normalize-stderr: "omitted [0-9]+ frames" -> "omitted N frames"
16+
//@ normalize-stderr: ".rs:[0-9]+:[0-9]+" -> ".rs:LL:CC"
2317
//@ error-pattern:stack backtrace:
2418
//@ regex-error-pattern:omitted [0-9]+ frames
2519
//@ error-pattern:main
26-
// NOTE: if this is missing it's probably because the check that .stderr files match failed.
27-
//@ error-pattern:finished all checks
2820

2921
//@ exec-env:RUST_BACKTRACE=1
3022
//@ unset-exec-env:RUST_LIB_BACKTRACE
@@ -42,71 +34,28 @@
4234
//@[limited] compile-flags:-Cdebuginfo=limited
4335
//@[full] compile-flags:-Cdebuginfo=full
4436

45-
use std::collections::BTreeMap;
46-
use std::env;
47-
use std::path::Path;
48-
4937
fn main() {
50-
// Make sure this comes first. Otherwise the error message when the check
51-
// below fails prevents you from using --bless to see the actual output.
52-
std::panic::catch_unwind(|| check_all_panics()).unwrap_err();
53-
54-
// compiletest generates a bunch of files for each revision. make sure they're all the same.
55-
let mut files = BTreeMap::new();
56-
let dir = Path::new(env!("SOURCE_DIR")).join("backtrace");
57-
for file in std::fs::read_dir(dir).unwrap() {
58-
let file = file.unwrap();
59-
let name = file.file_name().into_string().unwrap();
60-
if !file.file_type().unwrap().is_file() || !name.starts_with("std-backtrace-skip-frames.")
61-
|| !name.ends_with(".run.stderr") {
62-
continue;
63-
}
64-
files.insert(name, std::fs::read_to_string(file.path()).unwrap());
65-
}
66-
67-
let mut first_line_tables = None;
68-
let mut first_full = None;
69-
70-
for (name, contents) in &files {
71-
// These have different output. Rather than duplicating this whole test,
72-
// just special-case them here.
73-
let target = if name.contains(".full.") || name.contains(".limited.") {
74-
&mut first_full
75-
} else {
76-
&mut first_line_tables
77-
};
78-
if let Some((target_name, target_contents)) = target {
79-
if contents != *target_contents {
80-
eprintln!("are you *sure* that you want {name} to have different backtrace output\
81-
than {target_name}?");
82-
eprintln!("NOTE: this test is stateful; run \
83-
`rm tests/ui/backtrace/std-backtrace-skip-frames.*.stderr` to reset it");
84-
std::process::exit(0);
85-
}
86-
} else {
87-
// compiletest doesn't support negative matching for `error-pattern`. Do that here.
88-
assert!(!contents.contains("FnOnce::call_once"));
89-
*target = Some((name, contents));
90-
}
91-
}
92-
93-
// We need this so people don't --bless away the assertion failure by accident.
94-
eprintln!("finished all checks");
38+
check_all_panics();
9539
}
9640

9741
fn check_all_panics() {
9842
// Spawn a bunch of threads and make sure all of them hide panic details we don't care about.
9943
let tests = [
100-
unwrap_result, expect_result, unwrap_option, expect_option, explicit_panic, literal_panic,
101-
/*panic_nounwind*/
44+
unwrap_result,
45+
expect_result,
46+
unwrap_option,
47+
expect_option,
48+
explicit_panic,
49+
literal_panic,
50+
/*panic_nounwind*/
10251
];
10352
for func in tests {
10453
std::thread::spawn(move || func()).join().unwrap_err();
10554
}
10655
std::thread::spawn(|| panic_fmt(3)).join().unwrap_err();
10756

10857
// Finally, panic ourselves so we can make sure `lang_start`, etc. frames are hidden.
109-
panic!();
58+
std::panic::catch_unwind(|| panic!()).unwrap_err();
11059
}
11160

11261
fn unwrap_result() {
@@ -141,5 +90,7 @@ fn panic_fmt(x: u32) {
14190
// TODO: separate test
14291
#[allow(dead_code)]
14392
fn panic_nounwind() {
144-
unsafe { [0].get_unchecked(1); }
93+
unsafe {
94+
[0].get_unchecked(1);
95+
}
14596
}

tests/ui/backtrace/std-backtrace-skip-frames.unpacked.run.stderr

+4-5
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,14 @@ thread 'main' panicked at $DIR/std-backtrace-skip-frames.rs:LL:CC:
6868
explicit panic
6969
stack backtrace:
7070
[... omitted N frames ...]
71-
0: check_all_panics
72-
at $DIR/std-backtrace-skip-frames.rs:LL:CC
73-
1: {closure#0}
71+
0: {closure#2}
7472
at $DIR/std-backtrace-skip-frames.rs:LL:CC
7573
[... omitted N frames ...]
76-
2: catch_unwind<std_backtrace_skip_frames::main::{closure_env#0}, ()>
74+
1: catch_unwind<std_backtrace_skip_frames::check_all_panics::{closure_env#2}, ()>
7775
at $SRC_DIR/std/src/panic.rs:LL:COL
76+
2: check_all_panics
77+
at $DIR/std-backtrace-skip-frames.rs:LL:CC
7878
3: main
7979
at $DIR/std-backtrace-skip-frames.rs:LL:CC
8080
[... omitted N frames ...]
8181
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
82-
finished all checks

0 commit comments

Comments
 (0)