4
4
// or full.
5
5
// - Check that disabling ICE logging results in zero files created.
6
6
// - Check that the ICE files contain some of the expected strings.
7
+ // - exercise the -Zmetrics-dir nightly flag
8
+ // - verify what happens when both the nightly flag and env variable are set
9
+ // - test the RUST_BACKTRACE=0 behavior against the file creation
10
+
7
11
// See https://github.com/rust-lang/rust/pull/108714
8
12
9
13
use run_make_support:: { cwd, has_extension, has_prefix, rfs, rustc, shallow_find_files} ;
10
14
11
15
fn main ( ) {
12
16
rustc ( ) . input ( "lib.rs" ) . arg ( "-Ztreat-err-as-bug=1" ) . run_fail ( ) ;
13
17
let default = get_text_from_ice ( "." ) . lines ( ) . count ( ) ;
14
- clear_ice_files ( ) ;
15
18
19
+ clear_ice_files ( ) ;
16
20
rustc ( ) . env ( "RUSTC_ICE" , cwd ( ) ) . input ( "lib.rs" ) . arg ( "-Ztreat-err-as-bug=1" ) . run_fail ( ) ;
17
21
let ice_text = get_text_from_ice ( cwd ( ) ) ;
18
22
let default_set = ice_text. lines ( ) . count ( ) ;
@@ -25,7 +29,28 @@ fn main() {
25
29
ice_files. first ( ) . and_then ( |f| f. file_name ( ) ) . and_then ( |n| n. to_str ( ) ) . unwrap ( ) ;
26
30
// Ensure that the ICE dump path doesn't contain `:`, because they cause problems on Windows.
27
31
assert ! ( !ice_file_name. contains( ":" ) , "{ice_file_name}" ) ;
32
+ assert_eq ! ( default , default_set) ;
33
+ assert ! ( default > 0 ) ;
34
+ // Some of the expected strings in an ICE file should appear.
35
+ assert ! ( content. contains( "thread 'rustc' panicked at" ) ) ;
36
+ assert ! ( content. contains( "stack backtrace:" ) ) ;
37
+
38
+ test_backtrace_short ( default) ;
39
+ test_backtrace_full ( default) ;
40
+ test_backtrace_disabled ( default) ;
41
+
42
+ clear_ice_files ( ) ;
43
+ // The ICE dump is explicitly disabled. Therefore, this should produce no files.
44
+ rustc ( ) . env ( "RUSTC_ICE" , "0" ) . input ( "lib.rs" ) . arg ( "-Ztreat-err-as-bug=1" ) . run_fail ( ) ;
45
+ let ice_files = shallow_find_files ( cwd ( ) , |path| {
46
+ has_prefix ( path, "rustc-ice" ) && has_extension ( path, "txt" )
47
+ } ) ;
48
+ assert ! ( ice_files. is_empty( ) ) ; // There should be 0 ICE files.
49
+
50
+ metrics_dir ( default) ;
51
+ }
28
52
53
+ fn test_backtrace_short ( baseline : usize ) {
29
54
clear_ice_files ( ) ;
30
55
rustc ( )
31
56
. env ( "RUSTC_ICE" , cwd ( ) )
@@ -34,6 +59,11 @@ fn main() {
34
59
. arg ( "-Ztreat-err-as-bug=1" )
35
60
. run_fail ( ) ;
36
61
let short = get_text_from_ice ( cwd ( ) ) . lines ( ) . count ( ) ;
62
+ // backtrace length in dump shouldn't be changed by RUST_BACKTRACE
63
+ assert_eq ! ( short, baseline) ;
64
+ }
65
+
66
+ fn test_backtrace_full ( baseline : usize ) {
37
67
clear_ice_files ( ) ;
38
68
rustc ( )
39
69
. env ( "RUSTC_ICE" , cwd ( ) )
@@ -42,23 +72,49 @@ fn main() {
42
72
. arg ( "-Ztreat-err-as-bug=1" )
43
73
. run_fail ( ) ;
44
74
let full = get_text_from_ice ( cwd ( ) ) . lines ( ) . count ( ) ;
75
+ // backtrace length in dump shouldn't be changed by RUST_BACKTRACE
76
+ assert_eq ! ( full, baseline) ;
77
+ }
78
+
79
+ fn test_backtrace_disabled ( baseline : usize ) {
45
80
clear_ice_files ( ) ;
81
+ rustc ( )
82
+ . env ( "RUSTC_ICE" , cwd ( ) )
83
+ . input ( "lib.rs" )
84
+ . env ( "RUST_BACKTRACE" , "0" )
85
+ . arg ( "-Ztreat-err-as-bug=1" )
86
+ . run_fail ( ) ;
87
+ let disabled = get_text_from_ice ( cwd ( ) ) . lines ( ) . count ( ) ;
88
+ // backtrace length in dump shouldn't be changed by RUST_BACKTRACE
89
+ assert_eq ! ( disabled, baseline) ;
90
+ }
46
91
47
- // The ICE dump is explicitly disabled. Therefore, this should produce no files.
48
- rustc ( ) . env ( "RUSTC_ICE" , "0" ) . input ( "lib.rs" ) . arg ( "-Ztreat-err-as-bug=1" ) . run_fail ( ) ;
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.
92
+ fn metrics_dir ( baseline : usize ) {
93
+ test_flag_only ( baseline) ;
94
+ test_flag_and_env ( baseline) ;
95
+ }
53
96
54
- // The line count should not change.
55
- assert_eq ! ( short, default_set) ;
56
- assert_eq ! ( short, default ) ;
57
- assert_eq ! ( full, default_set) ;
58
- assert ! ( default > 0 ) ;
59
- // Some of the expected strings in an ICE file should appear.
60
- assert ! ( content. contains( "thread 'rustc' panicked at" ) ) ;
61
- assert ! ( content. contains( "stack backtrace:" ) ) ;
97
+ fn test_flag_only ( baseline : usize ) {
98
+ clear_ice_files ( ) ;
99
+ let metrics_arg = format ! ( "-Zmetrics-dir={}" , cwd( ) . display( ) ) ;
100
+ rustc ( ) . input ( "lib.rs" ) . arg ( "-Ztreat-err-as-bug=1" ) . arg ( metrics_arg) . run_fail ( ) ;
101
+ let output = get_text_from_ice ( cwd ( ) ) . lines ( ) . count ( ) ;
102
+ assert_eq ! ( output, baseline) ;
103
+ }
104
+
105
+ fn test_flag_and_env ( baseline : usize ) {
106
+ clear_ice_files ( ) ;
107
+ let metrics_arg = format ! ( "-Zmetrics-dir={}" , cwd( ) . display( ) ) ;
108
+ let real_dir = cwd ( ) . join ( "actually_put_ice_here" ) ;
109
+ rfs:: create_dir ( real_dir. clone ( ) ) ;
110
+ rustc ( )
111
+ . input ( "lib.rs" )
112
+ . env ( "RUSTC_ICE" , real_dir. clone ( ) )
113
+ . arg ( "-Ztreat-err-as-bug=1" )
114
+ . arg ( metrics_arg)
115
+ . run_fail ( ) ;
116
+ let output = get_text_from_ice ( real_dir) . lines ( ) . count ( ) ;
117
+ assert_eq ! ( output, baseline) ;
62
118
}
63
119
64
120
fn clear_ice_files ( ) {
0 commit comments