@@ -317,32 +317,7 @@ pub fn run_in_tmpdir<F: FnOnce()>(callback: F) {
317
317
fs:: remove_dir_all ( tmpdir) . unwrap ( ) ;
318
318
}
319
319
320
- /// Implement common helpers for command wrappers. This assumes that the command wrapper is a struct
321
- /// containing a `cmd: Command` field. The provided helpers are:
322
- ///
323
- /// 1. Generic argument acceptors: `arg` and `args` (delegated to [`Command`]). These are intended
324
- /// to be *fallback* argument acceptors, when specific helpers don't make sense. Prefer to add
325
- /// new specific helper methods over relying on these generic argument providers.
326
- /// 2. Environment manipulation methods: `env`, `env_remove` and `env_clear`: these delegate to
327
- /// methods of the same name on [`Command`].
328
- /// 3. Output and execution: `run` and `run_fail` are provided. These are
329
- /// higher-level convenience methods which wait for the command to finish running and assert
330
- /// that the command successfully ran or failed as expected. They return
331
- /// [`CompletedProcess`], which can be used to assert the stdout/stderr/exit code of the executed
332
- /// process.
333
- ///
334
- /// Example usage:
335
- ///
336
- /// ```ignore (illustrative)
337
- /// struct CommandWrapper { cmd: Command } // <- required `cmd` field
338
- ///
339
- /// crate::impl_common_helpers!(CommandWrapper);
340
- ///
341
- /// impl CommandWrapper {
342
- /// // ... additional specific helper methods
343
- /// }
344
- /// ```
345
- macro_rules! impl_common_helpers {
320
+ macro_rules! impl_common_helpers_without_run {
346
321
( $wrapper: ident) => {
347
322
impl $wrapper {
348
323
/// Specify an environment variable.
@@ -401,6 +376,45 @@ macro_rules! impl_common_helpers {
401
376
inspector( & self . cmd) ;
402
377
self
403
378
}
379
+ }
380
+ } ;
381
+ }
382
+
383
+ /// Implement common helpers for command wrappers. This assumes that the command wrapper is a struct
384
+ /// containing a `cmd: Command` field. The provided helpers are:
385
+ ///
386
+ /// 1. Generic argument acceptors: `arg` and `args` (delegated to [`Command`]). These are intended
387
+ /// to be *fallback* argument acceptors, when specific helpers don't make sense. Prefer to add
388
+ /// new specific helper methods over relying on these generic argument providers.
389
+ /// 2. Environment manipulation methods: `env`, `env_remove` and `env_clear`: these delegate to
390
+ /// methods of the same name on [`Command`].
391
+ /// 3. Output and execution: `run` and `run_fail` are provided. These are
392
+ /// higher-level convenience methods which wait for the command to finish running and assert
393
+ /// that the command successfully ran or failed as expected. They return
394
+ /// [`CompletedProcess`], which can be used to assert the stdout/stderr/exit code of the executed
395
+ /// process.
396
+ ///
397
+ /// Example usage:
398
+ ///
399
+ /// ```ignore (illustrative)
400
+ /// struct CommandWrapper { cmd: Command } // <- required `cmd` field
401
+ ///
402
+ /// crate::impl_common_helpers!(CommandWrapper);
403
+ ///
404
+ /// impl CommandWrapper {
405
+ /// // ... additional specific helper methods
406
+ /// }
407
+ /// ```
408
+ macro_rules! impl_common_helpers {
409
+ ( $wrapper: ident) => {
410
+ crate :: impl_common_helpers_without_run!( $wrapper) ;
411
+
412
+ impl $wrapper {
413
+ /// Set the path where the command will be run.
414
+ pub fn current_dir<P : AsRef <Path >>( & mut self , path: P ) -> & mut Self {
415
+ self . cmd. current_dir( path) ;
416
+ self
417
+ }
404
418
405
419
/// Run the constructed command and assert that it is successfully run.
406
420
#[ track_caller]
@@ -413,15 +427,10 @@ macro_rules! impl_common_helpers {
413
427
pub fn run_fail( & mut self ) -> crate :: command:: CompletedProcess {
414
428
self . cmd. run_fail( )
415
429
}
416
-
417
- /// Set the path where the command will be run.
418
- pub fn current_dir<P : AsRef <Path >>( & mut self , path: P ) -> & mut Self {
419
- self . cmd. current_dir( path) ;
420
- self
421
- }
422
430
}
423
431
} ;
424
432
}
425
433
426
434
use crate :: command:: { Command , CompletedProcess } ;
427
435
pub ( crate ) use impl_common_helpers;
436
+ pub ( crate ) use impl_common_helpers_without_run;
0 commit comments