@@ -377,32 +377,7 @@ pub fn run_in_tmpdir<F: FnOnce()>(callback: F) {
377
377
fs:: remove_dir_all ( tmpdir) . unwrap ( ) ;
378
378
}
379
379
380
- /// Implement common helpers for command wrappers. This assumes that the command wrapper is a struct
381
- /// containing a `cmd: Command` field. The provided helpers are:
382
- ///
383
- /// 1. Generic argument acceptors: `arg` and `args` (delegated to [`Command`]). These are intended
384
- /// to be *fallback* argument acceptors, when specific helpers don't make sense. Prefer to add
385
- /// new specific helper methods over relying on these generic argument providers.
386
- /// 2. Environment manipulation methods: `env`, `env_remove` and `env_clear`: these delegate to
387
- /// methods of the same name on [`Command`].
388
- /// 3. Output and execution: `run` and `run_fail` are provided. These are
389
- /// higher-level convenience methods which wait for the command to finish running and assert
390
- /// that the command successfully ran or failed as expected. They return
391
- /// [`CompletedProcess`], which can be used to assert the stdout/stderr/exit code of the executed
392
- /// process.
393
- ///
394
- /// Example usage:
395
- ///
396
- /// ```ignore (illustrative)
397
- /// struct CommandWrapper { cmd: Command } // <- required `cmd` field
398
- ///
399
- /// crate::impl_common_helpers!(CommandWrapper);
400
- ///
401
- /// impl CommandWrapper {
402
- /// // ... additional specific helper methods
403
- /// }
404
- /// ```
405
- macro_rules! impl_common_helpers {
380
+ macro_rules! impl_common_helpers_without_run {
406
381
( $wrapper: ident) => {
407
382
impl $wrapper {
408
383
/// Specify an environment variable.
@@ -446,13 +421,50 @@ macro_rules! impl_common_helpers {
446
421
self
447
422
}
448
423
449
- /// Inspect what the underlying [`Command`] is up to the
450
- /// current construction.
451
424
pub fn inspect<I >( & mut self , inspector: I ) -> & mut Self
452
425
where
453
426
I : FnOnce ( & :: std:: process:: Command ) ,
454
427
{
455
- self . cmd. inspect( inspector) ;
428
+ inspector( & self . cmd) ;
429
+ self
430
+ }
431
+ }
432
+ } ;
433
+ }
434
+
435
+ /// Implement common helpers for command wrappers. This assumes that the command wrapper is a struct
436
+ /// containing a `cmd: Command` field. The provided helpers are:
437
+ ///
438
+ /// 1. Generic argument acceptors: `arg` and `args` (delegated to [`Command`]). These are intended
439
+ /// to be *fallback* argument acceptors, when specific helpers don't make sense. Prefer to add
440
+ /// new specific helper methods over relying on these generic argument providers.
441
+ /// 2. Environment manipulation methods: `env`, `env_remove` and `env_clear`: these delegate to
442
+ /// methods of the same name on [`Command`].
443
+ /// 3. Output and execution: `run` and `run_fail` are provided. These are
444
+ /// higher-level convenience methods which wait for the command to finish running and assert
445
+ /// that the command successfully ran or failed as expected. They return
446
+ /// [`CompletedProcess`], which can be used to assert the stdout/stderr/exit code of the executed
447
+ /// process.
448
+ ///
449
+ /// Example usage:
450
+ ///
451
+ /// ```ignore (illustrative)
452
+ /// struct CommandWrapper { cmd: Command } // <- required `cmd` field
453
+ ///
454
+ /// crate::impl_common_helpers!(CommandWrapper);
455
+ ///
456
+ /// impl CommandWrapper {
457
+ /// // ... additional specific helper methods
458
+ /// }
459
+ /// ```
460
+ macro_rules! impl_common_helpers {
461
+ ( $wrapper: ident) => {
462
+ crate :: impl_common_helpers_without_run!( $wrapper) ;
463
+
464
+ impl $wrapper {
465
+ /// Set the path where the command will be run.
466
+ pub fn current_dir<P : AsRef <Path >>( & mut self , path: P ) -> & mut Self {
467
+ self . cmd. current_dir( path) ;
456
468
self
457
469
}
458
470
@@ -467,15 +479,10 @@ macro_rules! impl_common_helpers {
467
479
pub fn run_fail( & mut self ) -> crate :: command:: CompletedProcess {
468
480
self . cmd. run_fail( )
469
481
}
470
-
471
- /// Set the path where the command will be run.
472
- pub fn current_dir<P : AsRef <:: std:: path:: Path >>( & mut self , path: P ) -> & mut Self {
473
- self . cmd. current_dir( path) ;
474
- self
475
- }
476
482
}
477
483
} ;
478
484
}
479
485
480
486
use crate :: command:: { Command , CompletedProcess } ;
481
487
pub ( crate ) use impl_common_helpers;
488
+ pub ( crate ) use impl_common_helpers_without_run;
0 commit comments