1818//@ ignore-visionos needs the `.dSYM` files to be moved to the device
1919//@ needs-unwind
2020//@ aux-build: line-tables-only-helper.rs
21-
21+ //@ edition: 2021
22+ #![ feature( backtrace_frames) ]
2223
2324extern crate line_tables_only_helper;
2425
@@ -30,13 +31,27 @@ fn assert_contains(
3031 expected_file : & str ,
3132 expected_line : u32 ,
3233) {
33- // FIXME(jieyouxu): fix this ugly fragile test when `BacktraceFrame` has accessors like...
34- // `symbols()`.
35- let backtrace = format ! ( "{:#?}" , backtrace) ;
36- eprintln ! ( "{}" , backtrace) ;
37- assert ! ( backtrace. contains( expected_name) , "backtrace does not contain expected name {}" , expected_name) ;
38- assert ! ( backtrace. contains( expected_file) , "backtrace does not contain expected file {}" , expected_file) ;
39- assert ! ( backtrace. contains( & expected_line. to_string( ) ) , "backtrace does not contain expected line {}" , expected_line) ;
34+ // The formatted frames look like this:
35+ // `{ fn: "backtrace_with_baz_in_it", file: ".../tests/ui/backtrace/auxiliary/line-tables-only-helper.rs", line: 5 }`
36+ // or this:
37+ // `{ fn: "line_tables_only_helper::backtrace_with_baz_in_it<line_tables_only_helper::capture_backtrace::closure_env$0>", file: "...\tests\ui\backtrace\auxiliary\line-tables-only-helper.rs", line: 5 },`
38+ // Make sure we match the right part when searching for the function name and line number.
39+ let expected_line_str = format ! ( "line: {expected_line} " ) ;
40+ eprintln ! ( "{:#?}" , backtrace) ;
41+ for frame in backtrace. frames ( ) {
42+ // FIXME: we use string matching. Replace this by getting the actual data out of the frame,
43+ // once that is possible.
44+ let frame = format ! ( "{:#?}" , frame) ;
45+ if frame. contains ( expected_name)
46+ && frame. contains ( expected_file)
47+ && frame. contains ( & expected_line_str)
48+ {
49+ return ;
50+ }
51+ }
52+ panic ! (
53+ "backtrace does not contain expected frame with name={expected_name}, file={expected_file}, line={expected_line}"
54+ ) ;
4055}
4156
4257fn main ( ) {
@@ -48,8 +63,8 @@ fn main() {
4863 // And with #143208 we also lost `bar` in the line tables.
4964 #[ cfg( not( all( target_pointer_width = "32" , target_env = "msvc" ) ) ) ]
5065 {
51- assert_contains ( & backtrace, "foo " , "line-tables-only-helper.rs" , 5 ) ;
52- assert_contains ( & backtrace, "bar " , "line-tables-only-helper.rs" , 10 ) ;
66+ assert_contains ( & backtrace, "backtrace_with_foo_in_it " , "line-tables-only-helper.rs" , 15 ) ;
67+ assert_contains ( & backtrace, "backtrace_with_bar_in_it " , "line-tables-only-helper.rs" , 10 ) ;
5368 }
54- assert_contains ( & backtrace, "baz " , "line-tables-only-helper.rs" , 5 ) ;
69+ assert_contains ( & backtrace, "backtrace_with_baz_in_it " , "line-tables-only-helper.rs" , 5 ) ;
5570}
0 commit comments