diff --git a/src/assert.rs b/src/assert.rs index aa11a77..5ab3b6b 100644 --- a/src/assert.rs +++ b/src/assert.rs @@ -80,6 +80,27 @@ impl Assert { } } + /// Run a specific example of the current crate. + /// + /// Defaults to asserting _successful_ execution. + pub fn example>(name: S) -> Self { + Assert { + cmd: vec![ + OsStr::new("cargo"), + OsStr::new("run"), + #[cfg(not(debug_assertions))] + OsStr::new("--release"), + OsStr::new("--quiet"), + OsStr::new("--example"), + name.as_ref(), + OsStr::new("--"), + ].into_iter() + .map(OsString::from) + .collect(), + ..Self::default() + } + } + /// Run a custom command. /// /// Defaults to asserting _successful_ execution.