6
6
// - Check that the ICE files contain some of the expected strings.
7
7
// See https://github.com/rust-lang/rust/pull/108714
8
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} ;
9
+ use run_make_support:: { cwd, has_extension, has_prefix, rfs, rustc, shallow_find_files} ;
12
10
13
11
fn main ( ) {
14
12
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 ( ) ) ;
16
18
let default_set = ice_text. lines ( ) . count ( ) ;
17
19
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| {
21
21
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}" ) ;
25
28
26
29
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 ( ) ;
29
37
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 ( ) ;
32
45
clear_ice_files ( ) ;
33
46
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.
35
48
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.
37
53
38
54
// The line count should not change.
39
55
assert_eq ! ( short, default_set) ;
56
+ assert_eq ! ( short, default ) ;
40
57
assert_eq ! ( full, default_set) ;
58
+ assert ! ( default > 0 ) ;
41
59
// Some of the expected strings in an ICE file should appear.
42
60
assert ! ( content. contains( "thread 'rustc' panicked at" ) ) ;
43
61
assert ! ( content. contains( "stack backtrace:" ) ) ;
@@ -48,17 +66,16 @@ fn clear_ice_files() {
48
66
has_prefix ( path, "rustc-ice" ) && has_extension ( path, "txt" )
49
67
} ) ;
50
68
for file in ice_files {
51
- fs_wrapper :: remove_file ( file) ;
69
+ rfs :: remove_file ( file) ;
52
70
}
53
71
}
54
72
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) ;
63
80
output
64
81
}
0 commit comments