macro_rules! impl_common_helpers { ($wrapper: ident) => { ... }; }
Expand description
Implement common helpers for command wrappers. This assumes that the command wrapper is a struct
containing a cmd: Command field and a output function. The provided helpers are:
- Generic argument acceptors:
argandargs(delegated toCommand). These are intended to be fallback argument acceptors, when specific helpers don’t make sense. Prefer to add new specific helper methods over relying on these generic argument providers. - Environment manipulation methods:
env,env_removeandenv_clear: these delegate to methods of the same name onCommand. - Output and execution:
output,runandrun_failare provided.outputwaits for the command to finish running and returns the process’sOutput.runandrun_failare higher-level convenience methods which waits for the command to finish running and assert that the command successfully ran or failed as expected. Preferrunandrun_failwhen possible.
Example usage:
ⓘ
struct CommandWrapper { cmd: Command } // <- required `cmd` field
impl CommandWrapper {
/// Get the [`Output`][::std::process::Output] of the finished process.
pub fn command_output(&mut self) -> Output { /* ... */ } // <- required `command_output()` method
}
crate::impl_common_helpers!(CommandWrapper);
impl CommandWrapper {
// ... additional specific helper methods
}