|
| 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