|  | 
|  | 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 | +        assert!(!file.display().to_string().contains(":")); | 
|  | 24 | +    } | 
|  | 25 | + | 
|  | 26 | +    clear_ice_files(); | 
|  | 27 | +    rustc().input("lib.rs").env("RUST_BACKTRACE", "short").arg("-Ztreat-err-as-bug=1").run_fail(); | 
|  | 28 | +    let short = get_text_from_ice().lines().count(); | 
|  | 29 | +    clear_ice_files(); | 
|  | 30 | +    rustc().input("lib.rs").env("RUST_BACKTRACE", "full").arg("-Ztreat-err-as-bug=1").run_fail(); | 
|  | 31 | +    let full = get_text_from_ice().lines().count(); | 
|  | 32 | +    clear_ice_files(); | 
|  | 33 | + | 
|  | 34 | +    // The ICE dump is explicitely disabled. Therefore, this should produce no files. | 
|  | 35 | +    rustc().env("RUSTC_ICE", "0").input("lib.rs").arg("-Ztreat-err-as-bug=1").run_fail(); | 
|  | 36 | +    assert!(get_text_from_ice().is_empty()); | 
|  | 37 | + | 
|  | 38 | +    // The line count should not change. | 
|  | 39 | +    assert_eq!(short, default_set); | 
|  | 40 | +    assert_eq!(full, default_set); | 
|  | 41 | +    // Some of the expected strings in an ICE file should appear. | 
|  | 42 | +    assert!(content.contains("thread 'rustc' panicked at")); | 
|  | 43 | +    assert!(content.contains("stack backtrace:")); | 
|  | 44 | +} | 
|  | 45 | + | 
|  | 46 | +fn clear_ice_files() { | 
|  | 47 | +    let ice_files = shallow_find_files(cwd(), |path| { | 
|  | 48 | +        has_prefix(path, "rustc-ice") && has_extension(path, "txt") | 
|  | 49 | +    }); | 
|  | 50 | +    for file in ice_files { | 
|  | 51 | +        fs_wrapper::remove_file(file); | 
|  | 52 | +    } | 
|  | 53 | +} | 
|  | 54 | + | 
|  | 55 | +fn get_text_from_ice() -> String { | 
|  | 56 | +    let ice_files = shallow_find_files(cwd(), |path| { | 
|  | 57 | +        has_prefix(path, "rustc-ice") && has_extension(path, "txt") | 
|  | 58 | +    }); | 
|  | 59 | +    let mut output = String::new(); | 
|  | 60 | +    for file in ice_files { | 
|  | 61 | +        output.push_str(&fs_wrapper::read_to_string(file)); | 
|  | 62 | +    } | 
|  | 63 | +    output | 
|  | 64 | +} | 
0 commit comments