|
| 1 | +// This test checks if internal compilation error (ICE) log files work as expected. |
| 2 | +// - Get the number of lines from the log files without any configuration options, |
| 3 | +// then check that the line count doesn't change if the backtrace gets configured to be short |
| 4 | +// or full. |
| 5 | +// - Check that disabling ICE logging results in zero files created. |
| 6 | +// - Check that the ICE files contain some of the expected strings. |
| 7 | +// See https://github.com/rust-lang/rust/pull/108714 |
| 8 | + |
| 9 | +// FIXME(Oneirical): try it on Windows! |
| 10 | + |
| 11 | +use run_make_support::{cwd, fs_wrapper, has_extension, has_prefix, rustc, shallow_find_files}; |
| 12 | + |
| 13 | +fn main() { |
| 14 | + rustc().input("lib.rs").arg("-Ztreat-err-as-bug=1").run_fail(); |
| 15 | + let ice_text = get_text_from_ice(); |
| 16 | + let default_set = ice_text.lines().count(); |
| 17 | + let content = ice_text; |
| 18 | + // Ensure that the ICE files don't contain `:` in their filename because |
| 19 | + // this causes problems on Windows. |
| 20 | + for file in shallow_find_files(cwd(), |path| { |
| 21 | + has_prefix(path, "rustc-ice") && has_extension(path, "txt") |
| 22 | + }) { |
| 23 | + println!("{}", file.display().to_string()); //FIXME(Oneirical): Remove this |
| 24 | + // assert!(!file.display().to_string().contains(":")); |
| 25 | + } |
| 26 | + |
| 27 | + clear_ice_files(); |
| 28 | + rustc().input("lib.rs").env("RUST_BACKTRACE", "short").arg("-Ztreat-err-as-bug=1").run_fail(); |
| 29 | + let short = get_text_from_ice().lines().count(); |
| 30 | + clear_ice_files(); |
| 31 | + rustc().input("lib.rs").env("RUST_BACKTRACE", "full").arg("-Ztreat-err-as-bug=1").run_fail(); |
| 32 | + let full = get_text_from_ice().lines().count(); |
| 33 | + clear_ice_files(); |
| 34 | + |
| 35 | + // The ICE dump is explicitely disabled. Therefore, this should produce no files. |
| 36 | + rustc().env("RUSTC_ICE", "0").input("lib.rs").arg("-Ztreat-err-as-bug=1").run_fail(); |
| 37 | + assert!(get_text_from_ice().is_empty()); |
| 38 | + |
| 39 | + // The line count should not change. |
| 40 | + assert_eq!(short, default_set); |
| 41 | + assert_eq!(full, default_set); |
| 42 | + // Some of the expected strings in an ICE file should appear. |
| 43 | + assert!(content.contains("thread 'rustc' panicked at")); |
| 44 | + assert!(content.contains("stack backtrace:")); |
| 45 | +} |
| 46 | + |
| 47 | +fn clear_ice_files() { |
| 48 | + let ice_files = shallow_find_files(cwd(), |path| { |
| 49 | + has_prefix(path, "rustc-ice") && has_extension(path, "txt") |
| 50 | + }); |
| 51 | + for file in ice_files { |
| 52 | + fs_wrapper::remove_file(file); |
| 53 | + } |
| 54 | +} |
| 55 | + |
| 56 | +fn get_text_from_ice() -> String { |
| 57 | + let ice_files = shallow_find_files(cwd(), |path| { |
| 58 | + has_prefix(path, "rustc-ice") && has_extension(path, "txt") |
| 59 | + }); |
| 60 | + let mut output = String::new(); |
| 61 | + for file in ice_files { |
| 62 | + output.push_str(&fs_wrapper::read_to_string(file)); |
| 63 | + } |
| 64 | + output |
| 65 | +} |
0 commit comments