Add set_backtrace_level helper function to run_make_support

This commit is contained in:
Oneirical 2024-06-09 14:24:36 -04:00
parent f88c647cda
commit 8a6bc13cfe
2 changed files with 30 additions and 13 deletions

View File

@ -100,6 +100,12 @@ impl Rustc {
self
}
//Adjust the backtrace level, displaying more detailed information at higher levels.
pub fn set_backtrace_level<R: AsRef<OsStr>>(&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<P: AsRef<Path>>(&mut self, path: P) -> &mut Self {
self.cmd.arg("-o");

View File

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