about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorYamakaky <yamakaky@yamaworld.fr>2016-12-04 16:38:27 -0500
committerYamakaky <yamakaky@yamaworld.fr>2017-02-15 14:24:37 -0500
commitd50e4cc0640e54a64d0f7ccb05a77fd4a2fe0741 (patch)
tree2c403c3c5fb8e02b5d5bbe493eec5375c47fd137 /src/test
parente0044bd3896456afb346d06e91a97ac515930ccf (diff)
downloadrust-d50e4cc0640e54a64d0f7ccb05a77fd4a2fe0741.tar.gz
rust-d50e4cc0640e54a64d0f7ccb05a77fd4a2fe0741.zip
Improve backtrace formating while panicking.
- `RUST_BACKTRACE=full` prints all the informations (old behaviour)
- `RUST_BACKTRACE=(0|no)` disables the backtrace.
- `RUST_BACKTRACE=<everything else>` (including `1`) shows a simplified
  backtrace, without the function addresses and with cleaned filenames
  and symbols. Also removes some unneded frames at the beginning and the
  end.

Fixes #37783.

PR is #38165.
Diffstat (limited to 'src/test')
-rw-r--r--src/test/run-pass/backtrace-debuginfo.rs4
-rw-r--r--src/test/run-pass/backtrace.rs49
2 files changed, 50 insertions, 3 deletions
diff --git a/src/test/run-pass/backtrace-debuginfo.rs b/src/test/run-pass/backtrace-debuginfo.rs
index 626eccfc9ec..88fee9ed25b 100644
--- a/src/test/run-pass/backtrace-debuginfo.rs
+++ b/src/test/run-pass/backtrace-debuginfo.rs
@@ -141,12 +141,12 @@ fn run_test(me: &str) {
     use std::process::Command;
 
     let mut template = Command::new(me);
-    template.env("RUST_BACKTRACE", "1");
+    template.env("RUST_BACKTRACE", "full");
 
     let mut i = 0;
     loop {
         let out = Command::new(me)
-                          .env("RUST_BACKTRACE", "1")
+                          .env("RUST_BACKTRACE", "full")
                           .arg(i.to_string()).output().unwrap();
         let output = str::from_utf8(&out.stdout).unwrap();
         let error = str::from_utf8(&out.stderr).unwrap();
diff --git a/src/test/run-pass/backtrace.rs b/src/test/run-pass/backtrace.rs
index 834ce984e66..dcdf82682f3 100644
--- a/src/test/run-pass/backtrace.rs
+++ b/src/test/run-pass/backtrace.rs
@@ -47,7 +47,7 @@ fn template(me: &str) -> Command {
 }
 
 fn expected(fn_name: &str) -> String {
-    format!(" - backtrace::{}", fn_name)
+    format!(" backtrace::{}", fn_name)
 }
 
 fn runtest(me: &str) {
@@ -59,6 +59,53 @@ fn runtest(me: &str) {
     assert!(s.contains("stack backtrace") && s.contains(&expected("foo")),
             "bad output: {}", s);
 
+    // Make sure than the short version cleans the backtrace.
+    let p = template(me).arg("fail").env("RUST_BACKTRACE", "1").spawn().unwrap();
+    let out = p.wait_with_output().unwrap();
+    assert!(!out.status.success());
+    let s = str::from_utf8(&out.stderr).unwrap();
+    let removed_symbols = &[
+        "std::sys::imp::backtrace",
+        "std::sys_common::backtrace",
+        "std::panicking",
+        "core::panicking",
+        "rust_begin_unwind",
+        "code::result::unwrap_failed",
+        "std::panicking::try::do_call",
+        "__rust_maybe_catch_panic",
+        "__libc_start_main",
+        "__rust_try",
+        "_start",
+    ];
+    for symbol in removed_symbols {
+        assert!(!s.contains(symbol),
+                "{} should be removed from the backtrace",
+                symbol);
+    }
+    assert!(s.contains(" 0:"), "the frame number should start at 0");
+
+    // Only on linux for _start and __libc_start_main
+    #[cfg(target_os="linux")]
+    {
+        // Make sure than the short version cleans the backtrace.
+        let p = template(me).arg("fail").env("RUST_BACKTRACE", "full").spawn().unwrap();
+        let out = p.wait_with_output().unwrap();
+        assert!(!out.status.success());
+        let s = str::from_utf8(&out.stderr).unwrap();
+        let should_be_present = &[
+            "std::panicking",
+            "__rust_maybe_catch_panic",
+            "__libc_start_main",
+            "_start",
+        ];
+        for symbol in should_be_present {
+            // May give false positive due to inlining.
+            assert!(s.contains(symbol),
+            "the full version of the backtrace should contain {}",
+            symbol);
+        }
+    }
+
     // Make sure the stack trace is *not* printed
     // (Remove RUST_BACKTRACE from our own environment, in case developer
     // is running `make check` with it on.)