macro_rules! impl_common_helpers {
($wrapper: ident) => { ... };
($wrapper: ident, $before_exec: expr) => { ... };
}Expand description
Implement common helpers for command wrappers. This assumes that the command wrapper is a struct
containing a cmd: Command field. 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:
runandrun_failare provided. These are higher-level convenience methods which wait for the command to finish running and assert that the command successfully ran or failed as expected. They returnCompletedProcess, which can be used to assert the stdout/stderr/exit code of the executed process.
Example usage:
ⓘ
struct CommandWrapper { cmd: Command } // <- required `cmd` field
crate::macros::impl_common_helpers!(CommandWrapper);
impl CommandWrapper {
// ... additional specific helper methods
}You can pass an optional second parameter which should be a function that is passed
&mut self just before the command is executed.