@@ -38,6 +38,9 @@ use tracing::*;
38
38
use crate :: extract_gdb_version;
39
39
use crate :: is_android_gdb_target;
40
40
41
+ mod debugger;
42
+ use debugger:: { check_debugger_output, DebuggerCommands } ;
43
+
41
44
#[ cfg( test) ]
42
45
mod tests;
43
46
@@ -200,12 +203,6 @@ struct TestCx<'test> {
200
203
revision : Option < & ' test str > ,
201
204
}
202
205
203
- struct DebuggerCommands {
204
- commands : Vec < String > ,
205
- check_lines : Vec < String > ,
206
- breakpoint_lines : Vec < usize > ,
207
- }
208
-
209
206
enum ReadFrom {
210
207
Path ,
211
208
Stdin ( String ) ,
@@ -235,10 +232,8 @@ impl<'test> TestCx<'test> {
235
232
/// Code executed for each revision in turn (or, if there are no
236
233
/// revisions, exactly once, with revision == None).
237
234
fn run_revision ( & self ) {
238
- if self . props . should_ice {
239
- if self . config . mode != Incremental {
240
- self . fatal ( "cannot use should-ice in a test that is not cfail" ) ;
241
- }
235
+ if self . props . should_ice && self . config . mode != Incremental {
236
+ self . fatal ( "cannot use should-ice in a test that is not cfail" ) ;
242
237
}
243
238
match self . config . mode {
244
239
RunPassValgrind => self . run_valgrind_test ( ) ,
@@ -674,7 +669,10 @@ impl<'test> TestCx<'test> {
674
669
675
670
// Parse debugger commands etc from test files
676
671
let DebuggerCommands { commands, check_lines, breakpoint_lines, .. } =
677
- self . parse_debugger_commands ( prefixes) ;
672
+ match DebuggerCommands :: parse_from ( & self . testpaths . file , self . config , prefixes) {
673
+ Ok ( cmds) => cmds,
674
+ Err ( e) => self . fatal ( & e) ,
675
+ } ;
678
676
679
677
// https://docs.microsoft.com/en-us/windows-hardware/drivers/debugger/debugger-commands
680
678
let mut script_str = String :: with_capacity ( 2048 ) ;
@@ -726,7 +724,9 @@ impl<'test> TestCx<'test> {
726
724
self . fatal_proc_rec ( "Error while running CDB" , & debugger_run_result) ;
727
725
}
728
726
729
- self . check_debugger_output ( & debugger_run_result, & check_lines) ;
727
+ if let Err ( e) = check_debugger_output ( & debugger_run_result, & check_lines) {
728
+ self . fatal_proc_rec ( & e, & debugger_run_result) ;
729
+ }
730
730
}
731
731
732
732
fn run_debuginfo_gdb_test ( & self ) {
@@ -757,7 +757,10 @@ impl<'test> TestCx<'test> {
757
757
} ;
758
758
759
759
let DebuggerCommands { commands, check_lines, breakpoint_lines } =
760
- self . parse_debugger_commands ( prefixes) ;
760
+ match DebuggerCommands :: parse_from ( & self . testpaths . file , self . config , prefixes) {
761
+ Ok ( cmds) => cmds,
762
+ Err ( e) => self . fatal ( & e) ,
763
+ } ;
761
764
let mut cmds = commands. join ( "\n " ) ;
762
765
763
766
// compile test file (it should have 'compile-flags:-g' in the header)
@@ -960,7 +963,9 @@ impl<'test> TestCx<'test> {
960
963
self . fatal_proc_rec ( "gdb failed to execute" , & debugger_run_result) ;
961
964
}
962
965
963
- self . check_debugger_output ( & debugger_run_result, & check_lines) ;
966
+ if let Err ( e) = check_debugger_output ( & debugger_run_result, & check_lines) {
967
+ self . fatal_proc_rec ( & e, & debugger_run_result) ;
968
+ }
964
969
}
965
970
966
971
fn run_debuginfo_lldb_test ( & self ) {
@@ -1018,7 +1023,10 @@ impl<'test> TestCx<'test> {
1018
1023
1019
1024
// Parse debugger commands etc from test files
1020
1025
let DebuggerCommands { commands, check_lines, breakpoint_lines, .. } =
1021
- self . parse_debugger_commands ( prefixes) ;
1026
+ match DebuggerCommands :: parse_from ( & self . testpaths . file , self . config , prefixes) {
1027
+ Ok ( cmds) => cmds,
1028
+ Err ( e) => self . fatal ( & e) ,
1029
+ } ;
1022
1030
1023
1031
// Write debugger script:
1024
1032
// We don't want to hang when calling `quit` while the process is still running
@@ -1094,7 +1102,9 @@ impl<'test> TestCx<'test> {
1094
1102
self . fatal_proc_rec ( "Error while running LLDB" , & debugger_run_result) ;
1095
1103
}
1096
1104
1097
- self . check_debugger_output ( & debugger_run_result, & check_lines) ;
1105
+ if let Err ( e) = check_debugger_output ( & debugger_run_result, & check_lines) {
1106
+ self . fatal_proc_rec ( & e, & debugger_run_result) ;
1107
+ }
1098
1108
}
1099
1109
1100
1110
fn run_lldb (
@@ -1131,45 +1141,6 @@ impl<'test> TestCx<'test> {
1131
1141
ProcRes { status, stdout : out, stderr : err, cmdline : format ! ( "{:?}" , cmd) }
1132
1142
}
1133
1143
1134
- fn parse_debugger_commands ( & self , debugger_prefixes : & [ & str ] ) -> DebuggerCommands {
1135
- let directives = debugger_prefixes
1136
- . iter ( )
1137
- . map ( |prefix| ( format ! ( "{}-command" , prefix) , format ! ( "{}-check" , prefix) ) )
1138
- . collect :: < Vec < _ > > ( ) ;
1139
-
1140
- let mut breakpoint_lines = vec ! [ ] ;
1141
- let mut commands = vec ! [ ] ;
1142
- let mut check_lines = vec ! [ ] ;
1143
- let mut counter = 1 ;
1144
- let reader = BufReader :: new ( File :: open ( & self . testpaths . file ) . unwrap ( ) ) ;
1145
- for line in reader. lines ( ) {
1146
- match line {
1147
- Ok ( line) => {
1148
- let line =
1149
- if line. starts_with ( "//" ) { line[ 2 ..] . trim_start ( ) } else { line. as_str ( ) } ;
1150
-
1151
- if line. contains ( "#break" ) {
1152
- breakpoint_lines. push ( counter) ;
1153
- }
1154
-
1155
- for & ( ref command_directive, ref check_directive) in & directives {
1156
- self . config
1157
- . parse_name_value_directive ( & line, command_directive)
1158
- . map ( |cmd| commands. push ( cmd) ) ;
1159
-
1160
- self . config
1161
- . parse_name_value_directive ( & line, check_directive)
1162
- . map ( |cmd| check_lines. push ( cmd) ) ;
1163
- }
1164
- }
1165
- Err ( e) => self . fatal ( & format ! ( "Error while parsing debugger commands: {}" , e) ) ,
1166
- }
1167
- counter += 1 ;
1168
- }
1169
-
1170
- DebuggerCommands { commands, check_lines, breakpoint_lines }
1171
- }
1172
-
1173
1144
fn cleanup_debug_info_options ( & self , options : & Option < String > ) -> Option < String > {
1174
1145
if options. is_none ( ) {
1175
1146
return None ;
@@ -1216,66 +1187,6 @@ impl<'test> TestCx<'test> {
1216
1187
}
1217
1188
}
1218
1189
1219
- fn check_debugger_output ( & self , debugger_run_result : & ProcRes , check_lines : & [ String ] ) {
1220
- let num_check_lines = check_lines. len ( ) ;
1221
-
1222
- let mut check_line_index = 0 ;
1223
- for line in debugger_run_result. stdout . lines ( ) {
1224
- if check_line_index >= num_check_lines {
1225
- break ;
1226
- }
1227
-
1228
- if check_single_line ( line, & ( check_lines[ check_line_index] ) [ ..] ) {
1229
- check_line_index += 1 ;
1230
- }
1231
- }
1232
- if check_line_index != num_check_lines && num_check_lines > 0 {
1233
- self . fatal_proc_rec (
1234
- & format ! ( "line not found in debugger output: {}" , check_lines[ check_line_index] ) ,
1235
- debugger_run_result,
1236
- ) ;
1237
- }
1238
-
1239
- fn check_single_line ( line : & str , check_line : & str ) -> bool {
1240
- // Allow check lines to leave parts unspecified (e.g., uninitialized
1241
- // bits in the wrong case of an enum) with the notation "[...]".
1242
- let line = line. trim ( ) ;
1243
- let check_line = check_line. trim ( ) ;
1244
- let can_start_anywhere = check_line. starts_with ( "[...]" ) ;
1245
- let can_end_anywhere = check_line. ends_with ( "[...]" ) ;
1246
-
1247
- let check_fragments: Vec < & str > =
1248
- check_line. split ( "[...]" ) . filter ( |frag| !frag. is_empty ( ) ) . collect ( ) ;
1249
- if check_fragments. is_empty ( ) {
1250
- return true ;
1251
- }
1252
-
1253
- let ( mut rest, first_fragment) = if can_start_anywhere {
1254
- match line. find ( check_fragments[ 0 ] ) {
1255
- Some ( pos) => ( & line[ pos + check_fragments[ 0 ] . len ( ) ..] , 1 ) ,
1256
- None => return false ,
1257
- }
1258
- } else {
1259
- ( line, 0 )
1260
- } ;
1261
-
1262
- for current_fragment in & check_fragments[ first_fragment..] {
1263
- match rest. find ( current_fragment) {
1264
- Some ( pos) => {
1265
- rest = & rest[ pos + current_fragment. len ( ) ..] ;
1266
- }
1267
- None => return false ,
1268
- }
1269
- }
1270
-
1271
- if !can_end_anywhere && !rest. is_empty ( ) {
1272
- return false ;
1273
- }
1274
-
1275
- true
1276
- }
1277
- }
1278
-
1279
1190
fn check_error_patterns (
1280
1191
& self ,
1281
1192
output_to_check : & str ,
@@ -2154,9 +2065,9 @@ impl<'test> TestCx<'test> {
2154
2065
2155
2066
fn maybe_dump_to_stdout ( & self , out : & str , err : & str ) {
2156
2067
if self . config . verbose {
2157
- println ! ( "------{} ------------------------------" , "stdout ") ;
2068
+ println ! ( "------stdout ------------------------------" ) ;
2158
2069
println ! ( "{}" , out) ;
2159
- println ! ( "------{} ------------------------------" , "stderr ") ;
2070
+ println ! ( "------stderr ------------------------------" ) ;
2160
2071
println ! ( "{}" , err) ;
2161
2072
println ! ( "------------------------------------------" ) ;
2162
2073
}
@@ -3249,11 +3160,10 @@ impl<'test> TestCx<'test> {
3249
3160
if !proc_res. status . success ( ) {
3250
3161
self . fatal_proc_rec ( "test run failed!" , & proc_res) ;
3251
3162
}
3252
- } else {
3253
- if proc_res. status . success ( ) {
3254
- self . fatal_proc_rec ( "test run succeeded!" , & proc_res) ;
3255
- }
3163
+ } else if proc_res. status . success ( ) {
3164
+ self . fatal_proc_rec ( "test run succeeded!" , & proc_res) ;
3256
3165
}
3166
+
3257
3167
if !self . props . error_patterns . is_empty ( ) {
3258
3168
// "// error-pattern" comments
3259
3169
self . check_error_patterns ( & proc_res. stderr , & proc_res, pm) ;
@@ -3300,10 +3210,11 @@ impl<'test> TestCx<'test> {
3300
3210
if !res. status . success ( ) {
3301
3211
self . fatal_proc_rec ( "failed to compile fixed code" , & res) ;
3302
3212
}
3303
- if !res. stderr . is_empty ( ) && !self . props . rustfix_only_machine_applicable {
3304
- if !json:: rustfix_diagnostics_only ( & res. stderr ) . is_empty ( ) {
3305
- self . fatal_proc_rec ( "fixed code is still producing diagnostics" , & res) ;
3306
- }
3213
+ if !res. stderr . is_empty ( )
3214
+ && !self . props . rustfix_only_machine_applicable
3215
+ && !json:: rustfix_diagnostics_only ( & res. stderr ) . is_empty ( )
3216
+ {
3217
+ self . fatal_proc_rec ( "fixed code is still producing diagnostics" , & res) ;
3307
3218
}
3308
3219
}
3309
3220
}
0 commit comments