Skip to content

Commit a07f1f0

Browse files
committed
Port over backtrace's line-tables-only test to a ui test
1 parent 83d0a94 commit a07f1f0

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//@ compile-flags: -Cstrip=none -Cdebuginfo=line-tables-only
2+
3+
#[no_mangle]
4+
pub fn baz<F>(mut cb: F, data: u32) where F: FnMut(u32) {
5+
cb(data);
6+
}
7+
8+
#[no_mangle]
9+
pub fn bar<F>(cb: F, data: u32) where F: FnMut(u32) {
10+
baz(cb, data);
11+
}
12+
13+
#[no_mangle]
14+
pub fn foo<F>(cb: F, data: u32) where F: FnMut(u32) {
15+
bar(cb, data);
16+
}
17+
18+
pub fn capture_backtrace() -> std::backtrace::Backtrace {
19+
let mut bt = None;
20+
foo(|_| bt = Some(std::backtrace::Backtrace::capture()), 42);
21+
bt.unwrap()
22+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Test that when debug info only includes line tables that backtrace is still generated
2+
// successfully.
3+
// Original test:
4+
// <https://github.com/rust-lang/backtrace-rs/tree/6fa4b85b9962c3e1be8c2e5cc605cd078134152b/crates/line-tables-only>.
5+
// Part of <https://github.com/rust-lang/rust/issues/122899> porting some backtrace tests to rustc.
6+
// This test diverges from the original test in that it now uses a Rust library auxiliary because
7+
// rustc now has `-Cdebuginfo=line-tables-only`.
8+
// ignore-tidy-linelength
9+
//@ run-pass
10+
//@ compile-flags: -Cstrip=none -Cdebuginfo=line-tables-only
11+
//@ ignore-android FIXME #17520
12+
//@ ignore-openbsd no support for libbacktrace without filename
13+
//@ ignore-fuchsia Backtraces not symbolized
14+
//@ needs-unwind
15+
//@ aux-build: line-tables-only-helper.rs
16+
17+
#![feature(backtrace_frames)]
18+
19+
extern crate line_tables_only_helper;
20+
21+
use std::backtrace::Backtrace;
22+
23+
fn assert_contains(
24+
backtrace: &Backtrace,
25+
expected_name: &str,
26+
expected_file: &str,
27+
expected_line: u32,
28+
) {
29+
// FIXME(jieyouxu): fix this ugly fragile test when `BacktraceFrame` has accessors like...
30+
// `symbols()`.
31+
let backtrace = format!("{:#?}", backtrace);
32+
eprintln!("{}", backtrace);
33+
assert!(backtrace.contains(expected_name), "backtrace does not contain expected name {}", expected_name);
34+
assert!(backtrace.contains(expected_file), "backtrace does not contain expected file {}", expected_file);
35+
assert!(backtrace.contains(&expected_line.to_string()), "backtrace does not contain expected line {}", expected_line);
36+
}
37+
38+
fn main() {
39+
std::env::set_var("RUST_BACKTRACE", "1");
40+
let backtrace = line_tables_only_helper::capture_backtrace();
41+
assert_contains(&backtrace, "foo", "line-tables-only-helper.rs", 5);
42+
assert_contains(&backtrace, "bar", "line-tables-only-helper.rs", 10);
43+
assert_contains(&backtrace, "baz", "line-tables-only-helper.rs", 15);
44+
}

0 commit comments

Comments
 (0)