|
| 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-fuchsia Backtraces not symbolized |
| 13 | +//@ needs-unwind |
| 14 | +//@ aux-build: line-tables-only-helper.rs |
| 15 | + |
| 16 | +#![feature(backtrace_frames)] |
| 17 | + |
| 18 | +extern crate line_tables_only_helper; |
| 19 | + |
| 20 | +use std::backtrace::Backtrace; |
| 21 | + |
| 22 | +fn assert_contains( |
| 23 | + backtrace: &Backtrace, |
| 24 | + expected_name: &str, |
| 25 | + expected_file: &str, |
| 26 | + expected_line: u32, |
| 27 | +) { |
| 28 | + // FIXME(jieyouxu): fix this ugly fragile test when `BacktraceFrame` has accessors like... |
| 29 | + // `symbols()`. |
| 30 | + let backtrace = format!("{:#?}", backtrace); |
| 31 | + eprintln!("{}", backtrace); |
| 32 | + assert!(backtrace.contains(expected_name), "backtrace does not contain expected name {}", expected_name); |
| 33 | + assert!(backtrace.contains(expected_file), "backtrace does not contain expected file {}", expected_file); |
| 34 | + assert!(backtrace.contains(&expected_line.to_string()), "backtrace does not contain expected line {}", expected_line); |
| 35 | +} |
| 36 | + |
| 37 | +fn main() { |
| 38 | + std::env::set_var("RUST_BACKTRACE", "1"); |
| 39 | + let backtrace = line_tables_only_helper::capture_backtrace(); |
| 40 | + |
| 41 | + // FIXME(jieyouxu): for some forsaken reason on i686-msvc `foo` doesn't have an entry in the |
| 42 | + // line tables? |
| 43 | + #[cfg(not(all(target_pointer_width = "32", target_env = "msvc")))] |
| 44 | + { |
| 45 | + assert_contains(&backtrace, "foo", "line-tables-only-helper.rs", 5); |
| 46 | + } |
| 47 | + assert_contains(&backtrace, "bar", "line-tables-only-helper.rs", 10); |
| 48 | + assert_contains(&backtrace, "baz", "line-tables-only-helper.rs", 15); |
| 49 | +} |
0 commit comments