66// - Check that the ICE files contain some of the expected strings.
77// See https://github.com/rust-lang/rust/pull/108714
88
9- // FIXME(Oneirical): try it on Windows!
10-
11- use run_make_support:: { cwd, fs_wrapper, has_extension, has_prefix, rustc, shallow_find_files} ;
9+ use run_make_support:: { cwd, has_extension, has_prefix, rfs, rustc, shallow_find_files} ;
1210
1311fn main ( ) {
1412 rustc ( ) . input ( "lib.rs" ) . arg ( "-Ztreat-err-as-bug=1" ) . run_fail ( ) ;
15- let ice_text = get_text_from_ice ( ) ;
13+ let default = get_text_from_ice ( "." ) . lines ( ) . count ( ) ;
14+ clear_ice_files ( ) ;
15+
16+ rustc ( ) . env ( "RUSTC_ICE" , cwd ( ) ) . input ( "lib.rs" ) . arg ( "-Ztreat-err-as-bug=1" ) . run_fail ( ) ;
17+ let ice_text = get_text_from_ice ( cwd ( ) ) ;
1618 let default_set = ice_text. lines ( ) . count ( ) ;
1719 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| {
20+ let ice_files = shallow_find_files ( cwd ( ) , |path| {
2121 has_prefix ( path, "rustc-ice" ) && has_extension ( path, "txt" )
22- } ) {
23- assert ! ( !file. display( ) . to_string( ) . contains( ":" ) ) ;
24- }
22+ } ) ;
23+ assert_eq ! ( ice_files. len( ) , 1 ) ; // There should only be 1 ICE file.
24+ let ice_file_name =
25+ ice_files. first ( ) . and_then ( |f| f. file_name ( ) ) . and_then ( |n| n. to_str ( ) ) . unwrap ( ) ;
26+ // Ensure that the ICE dump path doesn't contain `:`, because they cause problems on Windows.
27+ assert ! ( !ice_file_name. contains( ":" ) , "{ice_file_name}" ) ;
2528
2629 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 ( ) ;
30+ rustc ( )
31+ . env ( "RUSTC_ICE" , cwd ( ) )
32+ . input ( "lib.rs" )
33+ . env ( "RUST_BACKTRACE" , "short" )
34+ . arg ( "-Ztreat-err-as-bug=1" )
35+ . run_fail ( ) ;
36+ let short = get_text_from_ice ( cwd ( ) ) . lines ( ) . count ( ) ;
2937 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 ( ) ;
38+ rustc ( )
39+ . env ( "RUSTC_ICE" , cwd ( ) )
40+ . input ( "lib.rs" )
41+ . env ( "RUST_BACKTRACE" , "full" )
42+ . arg ( "-Ztreat-err-as-bug=1" )
43+ . run_fail ( ) ;
44+ let full = get_text_from_ice ( cwd ( ) ) . lines ( ) . count ( ) ;
3245 clear_ice_files ( ) ;
3346
34- // The ICE dump is explicitely disabled. Therefore, this should produce no files.
47+ // The ICE dump is explicitly disabled. Therefore, this should produce no files.
3548 rustc ( ) . env ( "RUSTC_ICE" , "0" ) . input ( "lib.rs" ) . arg ( "-Ztreat-err-as-bug=1" ) . run_fail ( ) ;
36- assert ! ( get_text_from_ice( ) . is_empty( ) ) ;
49+ let ice_files = shallow_find_files ( cwd ( ) , |path| {
50+ has_prefix ( path, "rustc-ice" ) && has_extension ( path, "txt" )
51+ } ) ;
52+ assert ! ( ice_files. is_empty( ) ) ; // There should be 0 ICE files.
3753
3854 // The line count should not change.
3955 assert_eq ! ( short, default_set) ;
56+ assert_eq ! ( short, default ) ;
4057 assert_eq ! ( full, default_set) ;
58+ assert ! ( default > 0 ) ;
4159 // Some of the expected strings in an ICE file should appear.
4260 assert ! ( content. contains( "thread 'rustc' panicked at" ) ) ;
4361 assert ! ( content. contains( "stack backtrace:" ) ) ;
@@ -48,17 +66,16 @@ fn clear_ice_files() {
4866 has_prefix ( path, "rustc-ice" ) && has_extension ( path, "txt" )
4967 } ) ;
5068 for file in ice_files {
51- fs_wrapper :: remove_file ( file) ;
69+ rfs :: remove_file ( file) ;
5270 }
5371}
5472
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- }
73+ #[ track_caller]
74+ fn get_text_from_ice ( dir : impl AsRef < std:: path:: Path > ) -> String {
75+ let ice_files =
76+ shallow_find_files ( dir, |path| has_prefix ( path, "rustc-ice" ) && has_extension ( path, "txt" ) ) ;
77+ assert_eq ! ( ice_files. len( ) , 1 ) ; // There should only be 1 ICE file.
78+ let ice_file = ice_files. get ( 0 ) . unwrap ( ) ;
79+ let output = rfs:: read_to_string ( ice_file) ;
6380 output
6481}
0 commit comments