From 715362bfe7835bd1a9071a9cbdce0b11846248d8 Mon Sep 17 00:00:00 2001 From: Martin Nordholts Date: Thu, 3 Jul 2025 23:24:14 +0200 Subject: [PATCH] tests: Don't check for self-printed output in std-backtrace.rs test The `Display` implementation for `Backtrace` used to print stack backtrace: but that print was later removed. To make the existing test pass, the print was added to the existing test. But it doesn't make sense to check for something that the test itself does since that will not detect any regressions in the implementation of `Backtrace`. What the test _should_ check is that "stack backtrace:" is _not_ printed in `Display` of `Backtrace`. So do that instead. --- tests/ui/backtrace/std-backtrace.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/tests/ui/backtrace/std-backtrace.rs b/tests/ui/backtrace/std-backtrace.rs index 7ccbd46152bbf..1694ddcdfe5d6 100644 --- a/tests/ui/backtrace/std-backtrace.rs +++ b/tests/ui/backtrace/std-backtrace.rs @@ -13,9 +13,9 @@ use std::str; fn main() { let args: Vec = env::args().collect(); if args.len() >= 2 && args[1] == "force" { - println!("stack backtrace:\n{}", std::backtrace::Backtrace::force_capture()); + println!("{}", std::backtrace::Backtrace::force_capture()); } else if args.len() >= 2 { - println!("stack backtrace:\n{}", std::backtrace::Backtrace::capture()); + println!("{}", std::backtrace::Backtrace::capture()); } else { runtest(&args[0]); println!("test ok"); @@ -28,7 +28,9 @@ fn runtest(me: &str) { let p = Command::new(me).arg("a").env("RUST_BACKTRACE", "1").output().unwrap(); assert!(p.status.success()); - assert!(String::from_utf8_lossy(&p.stdout).contains("stack backtrace:\n")); + // Make sure there is no header. The header to use (if any) is up the user. + // See https://github.com/rust-lang/rust/pull/69042. + assert!(!String::from_utf8_lossy(&p.stdout).contains("stack backtrace:")); assert!(String::from_utf8_lossy(&p.stdout).contains("backtrace::main")); let p = Command::new(me).arg("a").env("RUST_BACKTRACE", "0").output().unwrap(); @@ -46,7 +48,7 @@ fn runtest(me: &str) { .output() .unwrap(); assert!(p.status.success()); - assert!(String::from_utf8_lossy(&p.stdout).contains("stack backtrace:\n")); + assert!(!String::from_utf8_lossy(&p.stdout).contains("stack backtrace:")); let p = Command::new(me) .arg("a") @@ -64,9 +66,9 @@ fn runtest(me: &str) { .output() .unwrap(); assert!(p.status.success()); - assert!(String::from_utf8_lossy(&p.stdout).contains("stack backtrace:\n")); + assert!(!String::from_utf8_lossy(&p.stdout).contains("stack backtrace:")); let p = Command::new(me).arg("force").output().unwrap(); assert!(p.status.success()); - assert!(String::from_utf8_lossy(&p.stdout).contains("stack backtrace:\n")); + assert!(!String::from_utf8_lossy(&p.stdout).contains("stack backtrace:")); }