From 8a6bc13cfe2fe90237f76c58933d10d76fc8a29c Mon Sep 17 00:00:00 2001 From: Oneirical Date: Sun, 9 Jun 2024 14:24:36 -0400 Subject: [PATCH] Add set_backtrace_level helper function to run_make_support --- src/tools/run-make-support/src/rustc.rs | 6 ++++ tests/run-make/short-ice/rmake.rs | 37 ++++++++++++++++--------- 2 files changed, 30 insertions(+), 13 deletions(-) diff --git a/src/tools/run-make-support/src/rustc.rs b/src/tools/run-make-support/src/rustc.rs index d4c00d23b8b..2538c475cae 100644 --- a/src/tools/run-make-support/src/rustc.rs +++ b/src/tools/run-make-support/src/rustc.rs @@ -100,6 +100,12 @@ pub fn input>(&mut self, path: P) -> &mut Self { self } + //Adjust the backtrace level, displaying more detailed information at higher levels. + pub fn set_backtrace_level>(&mut self, level: R) -> &mut Self { + self.cmd.env("RUST_BACKTRACE", level); + self + } + /// Specify path to the output file. Equivalent to `-o`` in rustc. pub fn output>(&mut self, path: P) -> &mut Self { self.cmd.arg("-o"); diff --git a/tests/run-make/short-ice/rmake.rs b/tests/run-make/short-ice/rmake.rs index 0aa1df61dbe..81403931c78 100644 --- a/tests/run-make/short-ice/rmake.rs +++ b/tests/run-make/short-ice/rmake.rs @@ -4,26 +4,37 @@ // was shortened down to an appropriate length. // See https://github.com/rust-lang/rust/issues/107910 +//@ ignore-windows +// Reason: the assert_eq! on line 32 fails, as error output on Windows is different. + use run_make_support::rustc; -use std::env; fn main() { - env::set_var("RUST_BACKTRACE", "1"); - let mut rust_test_1 = rustc().input("src/lib.rs").arg("-Ztreat-err-as-bug=1").run_fail(); - env::set_var("RUST_BACKTRACE", "full"); - let mut rust_test_2 = rustc().input("src/lib.rs").arg("-Ztreat-err-as-bug=1").run_fail(); - let rust_test_log_1 = rust_test_1.stderr_utf8().push_str(&rust_test_1.stdout_utf8()).as_str(); - let rust_test_log_2 = rust_test_2.stderr_utf8().push_str(&rust_test_2.stdout_utf8()).as_str(); + let rust_test_1 = + rustc().set_backtrace_level("1").input("src/lib.rs").arg("-Ztreat-err-as-bug=1").run_fail(); + let rust_test_2 = rustc() + .set_backtrace_level("full") + .input("src/lib.rs") + .arg("-Ztreat-err-as-bug=1") + .run_fail(); + + let mut rust_test_log_1 = rust_test_1.stderr_utf8(); + rust_test_log_1.push_str(&rust_test_1.stdout_utf8()); + let rust_test_log_1 = rust_test_log_1.as_str(); + + let mut rust_test_log_2 = rust_test_2.stderr_utf8(); + rust_test_log_2.push_str(&rust_test_2.stdout_utf8()); + let rust_test_log_2 = rust_test_log_2.as_str(); let rustc_query_count_full = count_lines_with(rust_test_log_2, "rustc_query_"); - assert!( - rust_test_log_1.lines().count() < rust_test_log_2.lines().count() - && count_lines_with(rust_test_log_2, "__rust_begin_short_backtrace") - == count_lines_with(rust_test_log_2, "__rust_end_short_backtrace") - && count_lines_with(rust_test_log_1, "rustc_query_") + 5 < rustc_query_count_full - && rustc_query_count_full > 5 + assert!(rust_test_log_1.lines().count() < rust_test_log_2.lines().count()); + assert_eq!( + count_lines_with(rust_test_log_2, "__rust_begin_short_backtrace"), + count_lines_with(rust_test_log_2, "__rust_end_short_backtrace") ); + assert!(count_lines_with(rust_test_log_1, "rustc_query_") + 5 < rustc_query_count_full); + assert!(rustc_query_count_full > 5); } fn count_lines_with(s: &str, search: &str) -> usize {