@@ -506,8 +506,20 @@ impl<'test> TestCx<'test> {
506
506
}
507
507
}
508
508
509
+ /// Runs a [`Command`] and waits for it to finish, then converts its exit
510
+ /// status and output streams into a [`ProcRes`].
511
+ ///
512
+ /// The command might have succeeded or failed; it is the caller's
513
+ /// responsibility to check the exit status and take appropriate action.
514
+ ///
515
+ /// # Panics
516
+ /// Panics if the command couldn't be executed at all
517
+ /// (e.g. because the executable could not be found).
518
+ #[ must_use = "caller should check whether the command succeeded" ]
509
519
fn run_command_to_procres ( & self , cmd : & mut Command ) -> ProcRes {
510
- let output = cmd. output ( ) . unwrap_or_else ( |e| panic ! ( "failed to exec `{cmd:?}`: {e:?}" ) ) ;
520
+ let output = cmd
521
+ . output ( )
522
+ . unwrap_or_else ( |e| self . fatal ( & format ! ( "failed to exec `{cmd:?}` because: {e}" ) ) ) ;
511
523
512
524
let proc_res = ProcRes {
513
525
status : output. status ,
@@ -1232,7 +1244,7 @@ impl<'test> TestCx<'test> {
1232
1244
} else {
1233
1245
self . config . lldb_python_dir . as_ref ( ) . unwrap ( ) . to_string ( )
1234
1246
} ;
1235
- self . cmd2procres (
1247
+ self . run_command_to_procres (
1236
1248
Command :: new ( & self . config . python )
1237
1249
. arg ( & lldb_script_path)
1238
1250
. arg ( test_executable)
@@ -1242,28 +1254,6 @@ impl<'test> TestCx<'test> {
1242
1254
)
1243
1255
}
1244
1256
1245
- fn cmd2procres ( & self , cmd : & mut Command ) -> ProcRes {
1246
- let ( status, out, err) = match cmd. output ( ) {
1247
- Ok ( Output { status, stdout, stderr } ) => {
1248
- ( status, String :: from_utf8 ( stdout) . unwrap ( ) , String :: from_utf8 ( stderr) . unwrap ( ) )
1249
- }
1250
- Err ( e) => self . fatal ( & format ! (
1251
- "Failed to setup Python process for \
1252
- LLDB script: {}",
1253
- e
1254
- ) ) ,
1255
- } ;
1256
-
1257
- self . dump_output ( & out, & err) ;
1258
- ProcRes {
1259
- status,
1260
- stdout : out,
1261
- stderr : err,
1262
- truncated : Truncated :: No ,
1263
- cmdline : format ! ( "{:?}" , cmd) ,
1264
- }
1265
- }
1266
-
1267
1257
fn cleanup_debug_info_options ( & self , options : & Vec < String > ) -> Vec < String > {
1268
1258
// Remove options that are either unwanted (-O) or may lead to duplicates due to RUSTFLAGS.
1269
1259
let options_to_remove = [ "-O" . to_owned ( ) , "-g" . to_owned ( ) , "--debuginfo" . to_owned ( ) ] ;
@@ -2683,7 +2673,7 @@ impl<'test> TestCx<'test> {
2683
2673
if self . config . bless {
2684
2674
cmd. arg ( "--bless" ) ;
2685
2675
}
2686
- let res = self . cmd2procres ( & mut cmd) ;
2676
+ let res = self . run_command_to_procres ( & mut cmd) ;
2687
2677
if !res. status . success ( ) {
2688
2678
self . fatal_proc_rec_with_ctx ( "htmldocck failed!" , & res, |mut this| {
2689
2679
this. compare_to_default_rustdoc ( & out_dir)
@@ -2860,7 +2850,7 @@ impl<'test> TestCx<'test> {
2860
2850
let root = self . config . find_rust_src_root ( ) . unwrap ( ) ;
2861
2851
let mut json_out = out_dir. join ( self . testpaths . file . file_stem ( ) . unwrap ( ) ) ;
2862
2852
json_out. set_extension ( "json" ) ;
2863
- let res = self . cmd2procres (
2853
+ let res = self . run_command_to_procres (
2864
2854
Command :: new ( self . config . jsondocck_path . as_ref ( ) . unwrap ( ) )
2865
2855
. arg ( "--doc-dir" )
2866
2856
. arg ( root. join ( & out_dir) )
@@ -2878,7 +2868,7 @@ impl<'test> TestCx<'test> {
2878
2868
let mut json_out = out_dir. join ( self . testpaths . file . file_stem ( ) . unwrap ( ) ) ;
2879
2869
json_out. set_extension ( "json" ) ;
2880
2870
2881
- let res = self . cmd2procres (
2871
+ let res = self . run_command_to_procres (
2882
2872
Command :: new ( self . config . jsondoclint_path . as_ref ( ) . unwrap ( ) ) . arg ( & json_out) ,
2883
2873
) ;
2884
2874
@@ -3526,7 +3516,7 @@ impl<'test> TestCx<'test> {
3526
3516
cmd. arg ( "--sysroot" ) . arg ( & stage0_sysroot) ;
3527
3517
}
3528
3518
3529
- let res = self . cmd2procres ( & mut cmd) ;
3519
+ let res = self . run_command_to_procres ( & mut cmd) ;
3530
3520
if !res. status . success ( ) {
3531
3521
self . fatal_proc_rec ( "run-make test failed: could not build `rmake.rs` recipe" , & res) ;
3532
3522
}
@@ -3687,7 +3677,7 @@ impl<'test> TestCx<'test> {
3687
3677
let root = self . config . find_rust_src_root ( ) . unwrap ( ) ;
3688
3678
let file_stem =
3689
3679
self . testpaths . file . file_stem ( ) . and_then ( |f| f. to_str ( ) ) . expect ( "no file stem" ) ;
3690
- let res = self . cmd2procres (
3680
+ let res = self . run_command_to_procres (
3691
3681
Command :: new ( & nodejs)
3692
3682
. arg ( root. join ( "src/tools/rustdoc-js/tester.js" ) )
3693
3683
. arg ( "--doc-folder" )
0 commit comments