@@ -348,32 +348,7 @@ pub fn run_in_tmpdir<F: FnOnce()>(callback: F) {
348348 fs:: remove_dir_all ( tmpdir) . unwrap ( ) ;
349349}
350350
351- /// Implement common helpers for command wrappers. This assumes that the command wrapper is a struct
352- /// containing a `cmd: Command` field. The provided helpers are:
353- ///
354- /// 1. Generic argument acceptors: `arg` and `args` (delegated to [`Command`]). These are intended
355- /// to be *fallback* argument acceptors, when specific helpers don't make sense. Prefer to add
356- /// new specific helper methods over relying on these generic argument providers.
357- /// 2. Environment manipulation methods: `env`, `env_remove` and `env_clear`: these delegate to
358- /// methods of the same name on [`Command`].
359- /// 3. Output and execution: `run` and `run_fail` are provided. These are
360- /// higher-level convenience methods which wait for the command to finish running and assert
361- /// that the command successfully ran or failed as expected. They return
362- /// [`CompletedProcess`], which can be used to assert the stdout/stderr/exit code of the executed
363- /// process.
364- ///
365- /// Example usage:
366- ///
367- /// ```ignore (illustrative)
368- /// struct CommandWrapper { cmd: Command } // <- required `cmd` field
369- ///
370- /// crate::impl_common_helpers!(CommandWrapper);
371- ///
372- /// impl CommandWrapper {
373- /// // ... additional specific helper methods
374- /// }
375- /// ```
376- macro_rules! impl_common_helpers {
351+ macro_rules! impl_common_helpers_without_run {
377352 ( $wrapper: ident) => {
378353 impl $wrapper {
379354 /// Specify an environment variable.
@@ -426,6 +401,45 @@ macro_rules! impl_common_helpers {
426401 self . cmd. inspect( inspector) ;
427402 self
428403 }
404+ }
405+ } ;
406+ }
407+
408+ /// Implement common helpers for command wrappers. This assumes that the command wrapper is a struct
409+ /// containing a `cmd: Command` field. The provided helpers are:
410+ ///
411+ /// 1. Generic argument acceptors: `arg` and `args` (delegated to [`Command`]). These are intended
412+ /// to be *fallback* argument acceptors, when specific helpers don't make sense. Prefer to add
413+ /// new specific helper methods over relying on these generic argument providers.
414+ /// 2. Environment manipulation methods: `env`, `env_remove` and `env_clear`: these delegate to
415+ /// methods of the same name on [`Command`].
416+ /// 3. Output and execution: `run` and `run_fail` are provided. These are
417+ /// higher-level convenience methods which wait for the command to finish running and assert
418+ /// that the command successfully ran or failed as expected. They return
419+ /// [`CompletedProcess`], which can be used to assert the stdout/stderr/exit code of the executed
420+ /// process.
421+ ///
422+ /// Example usage:
423+ ///
424+ /// ```ignore (illustrative)
425+ /// struct CommandWrapper { cmd: Command } // <- required `cmd` field
426+ ///
427+ /// crate::impl_common_helpers!(CommandWrapper);
428+ ///
429+ /// impl CommandWrapper {
430+ /// // ... additional specific helper methods
431+ /// }
432+ /// ```
433+ macro_rules! impl_common_helpers {
434+ ( $wrapper: ident) => {
435+ crate :: impl_common_helpers_without_run!( $wrapper) ;
436+
437+ impl $wrapper {
438+ /// Set the path where the command will be run.
439+ pub fn current_dir<P : AsRef <Path >>( & mut self , path: P ) -> & mut Self {
440+ self . cmd. current_dir( path) ;
441+ self
442+ }
429443
430444 /// Run the constructed command and assert that it is successfully run.
431445 #[ track_caller]
@@ -450,3 +464,4 @@ macro_rules! impl_common_helpers {
450464
451465use crate :: command:: { Command , CompletedProcess } ;
452466pub ( crate ) use impl_common_helpers;
467+ pub ( crate ) use impl_common_helpers_without_run;
0 commit comments