From bbf0fd89c981a788c3d22bde548b342d749eba3f Mon Sep 17 00:00:00 2001 From: Christopher Field Date: Sun, 20 May 2018 20:37:43 -0500 Subject: [PATCH] Add `example` constructor for Assert --- src/assert.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) 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.