Skip to content

Commit

Permalink
Add set_backtrace_level helper function to run_make_support
Browse files Browse the repository at this point in the history
  • Loading branch information
Oneirical committed Jun 11, 2024
1 parent f88c647 commit 2e4eff7
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 13 deletions.
6 changes: 6 additions & 0 deletions src/tools/run-make-support/src/rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
36 changes: 23 additions & 13 deletions tests/run-make/short-ice/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,36 @@
// was shortened down to an appropriate length.
// See https://github.com/rust-lang/rust/issues/107910

// FIXME do not ignore windows

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 {
Expand Down

0 comments on commit 2e4eff7

Please sign in to comment.