44// or full.
55// - Check that disabling ICE logging results in zero files created.
66// - Check that the ICE files contain some of the expected strings.
7+ // - exercise the -Zerror-metrics 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+
711// See https://github.com/rust-lang/rust/pull/108714
812
913use run_make_support:: { cwd, has_extension, has_prefix, rfs, rustc, shallow_find_files} ;
1014
1115fn main ( ) {
1216 rustc ( ) . input ( "lib.rs" ) . arg ( "-Ztreat-err-as-bug=1" ) . run_fail ( ) ;
1317 let default = get_text_from_ice ( "." ) . lines ( ) . count ( ) ;
14- clear_ice_files ( ) ;
1518
19+ clear_ice_files ( ) ;
1620 rustc ( ) . env ( "RUSTC_ICE" , cwd ( ) ) . input ( "lib.rs" ) . arg ( "-Ztreat-err-as-bug=1" ) . run_fail ( ) ;
1721 let ice_text = get_text_from_ice ( cwd ( ) ) ;
1822 let default_set = ice_text. lines ( ) . count ( ) ;
@@ -25,7 +29,28 @@ fn main() {
2529 ice_files. first ( ) . and_then ( |f| f. file_name ( ) ) . and_then ( |n| n. to_str ( ) ) . unwrap ( ) ;
2630 // Ensure that the ICE dump path doesn't contain `:`, because they cause problems on Windows.
2731 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+ test_error_metrics_flag ( default) ;
51+ }
2852
53+ fn test_backtrace_short ( baseline : usize ) {
2954 clear_ice_files ( ) ;
3055 rustc ( )
3156 . env ( "RUSTC_ICE" , cwd ( ) )
@@ -34,6 +59,11 @@ fn main() {
3459 . arg ( "-Ztreat-err-as-bug=1" )
3560 . run_fail ( ) ;
3661 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 ) {
3767 clear_ice_files ( ) ;
3868 rustc ( )
3969 . env ( "RUSTC_ICE" , cwd ( ) )
@@ -42,23 +72,49 @@ fn main() {
4272 . arg ( "-Ztreat-err-as-bug=1" )
4373 . run_fail ( ) ;
4474 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 ) {
4580 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+ }
4691
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 test_error_metrics_flag ( baseline : usize ) {
93+ test_flag_only ( baseline) ;
94+ test_flag_and_env ( baseline) ;
95+ }
5396
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 ! ( "-Zerror-metrics={}" , 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 ! ( "-Zerror-metrics={}" , cwd( ) . display( ) ) ;
108+ let real_dir = cwd ( ) . join ( "actually_put_ice_here" ) ;
109+ rfs:: create_dir ( real_dir. clone ( ) ) . unwrap ( ) ;
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) ;
62118}
63119
64120fn clear_ice_files ( ) {
0 commit comments