|
12 | 12 | // - FIXME(#143198): On `x86_64-pc-windows-msvc`: full backtrace sometimes do not contain matching |
13 | 13 | // count of short backtrace markers (e.g. 5x end marker, but 3x start marker). |
14 | 14 |
|
15 | | -use run_make_support::rustc; |
| 15 | +use run_make_support::CompletedProcess; |
16 | 16 |
|
17 | 17 | fn main() { |
18 | | - let rust_test_1 = |
19 | | - rustc().set_backtrace_level("1").input("src/lib.rs").arg("-Ztreat-err-as-bug=1").run_fail(); |
20 | | - let rust_test_2 = rustc() |
21 | | - .set_backtrace_level("full") |
22 | | - .input("src/lib.rs") |
23 | | - .arg("-Ztreat-err-as-bug=1") |
24 | | - .run_fail(); |
| 18 | + // Run the same command twice with `RUST_BACKTRACE=1` and `RUST_BACKTRACE=full`. |
| 19 | + let configure_rustc = || { |
| 20 | + let mut rustc = run_make_support::rustc(); |
| 21 | + rustc.input("src/lib.rs").arg("-Ztreat-err-as-bug=1"); |
| 22 | + rustc |
| 23 | + }; |
| 24 | + let rustc_bt_short = configure_rustc().set_backtrace_level("1").run_fail(); |
| 25 | + let rustc_bt_full = configure_rustc().set_backtrace_level("full").run_fail(); |
25 | 26 |
|
26 | | - let mut rust_test_log_1 = rust_test_1.stderr_utf8(); |
27 | | - rust_test_log_1.push_str(&rust_test_1.stdout_utf8()); |
28 | | - let rust_test_log_1 = rust_test_log_1.as_str(); |
| 27 | + // Combine stderr and stdout for subsequent checks. |
| 28 | + let concat_stderr_stdout = |
| 29 | + |proc: &CompletedProcess| format!("{}\n{}", proc.stderr_utf8(), proc.stdout_utf8()); |
| 30 | + let output_bt_short = &concat_stderr_stdout(&rustc_bt_short); |
| 31 | + let output_bt_full = &concat_stderr_stdout(&rustc_bt_full); |
29 | 32 |
|
30 | | - let mut rust_test_log_2 = rust_test_2.stderr_utf8(); |
31 | | - rust_test_log_2.push_str(&rust_test_2.stdout_utf8()); |
32 | | - let rust_test_log_2 = rust_test_log_2.as_str(); |
| 33 | + // Count how many lines of output mention symbols or paths in |
| 34 | + // `rustc_query_system` or `rustc_query_impl`, which are the kinds of |
| 35 | + // stack frames we want to be omitting in short backtraces. |
| 36 | + let rustc_query_count_short = count_lines_with(output_bt_short, "rustc_query_"); |
| 37 | + let rustc_query_count_full = count_lines_with(output_bt_full, "rustc_query_"); |
33 | 38 |
|
34 | | - let rustc_query_count_full = count_lines_with(rust_test_log_2, "rustc_query_"); |
| 39 | + // Dump both outputs in full to make debugging easier, especially on CI. |
| 40 | + // Use `--no-capture --force-rerun` to view output even when the test is passing. |
| 41 | + println!("=== BEGIN SHORT BACKTRACE ===\n{output_bt_short}\n=== END SHORT BACKTRACE === "); |
| 42 | + println!("=== BEGIN FULL BACKTRACE ===\n{output_bt_full}\n=== END FULL BACKTRACE === "); |
35 | 43 |
|
36 | 44 | assert!( |
37 | | - rust_test_log_1.lines().count() < rust_test_log_2.lines().count(), |
38 | | - "Short backtrace should be shorter than full backtrace.\nShort backtrace:\n\ |
39 | | - {rust_test_log_1}\nFull backtrace:\n{rust_test_log_2}" |
| 45 | + output_bt_short.lines().count() < output_bt_full.lines().count(), |
| 46 | + "Short backtrace should be shorter than full backtrace" |
40 | 47 | ); |
| 48 | + |
| 49 | + let n_begin = count_lines_with(output_bt_full, "__rust_begin_short_backtrace"); |
| 50 | + let n_end = count_lines_with(output_bt_full, "__rust_end_short_backtrace"); |
| 51 | + assert!(n_begin + n_end > 0, "Full backtrace should contain short-backtrace markers"); |
41 | 52 | assert_eq!( |
42 | | - count_lines_with(rust_test_log_2, "__rust_begin_short_backtrace"), |
43 | | - count_lines_with(rust_test_log_2, "__rust_end_short_backtrace"), |
44 | | - "Full backtrace should contain the short backtrace markers.\nFull backtrace:\n\ |
45 | | - {rust_test_log_2}" |
| 53 | + n_begin, n_end, |
| 54 | + "Full backtrace should contain equal numbers of begin and end markers" |
| 55 | + ); |
| 56 | + |
| 57 | + assert!( |
| 58 | + rustc_query_count_short + 5 < rustc_query_count_full, |
| 59 | + "Short backtrace should have omitted more query plumbing lines \ |
| 60 | + (actual: {rustc_query_count_short} vs {rustc_query_count_full})" |
46 | 61 | ); |
47 | | - assert!(count_lines_with(rust_test_log_1, "rustc_query_") + 5 < rustc_query_count_full); |
48 | | - assert!(rustc_query_count_full > 5); |
49 | 62 | } |
50 | 63 |
|
51 | 64 | fn count_lines_with(s: &str, search: &str) -> usize { |
|
0 commit comments