Skip to content
This repository was archived by the owner on Dec 29, 2021. It is now read-only.

Commit 880a4bd

Browse files
authored
Merge pull request #108 from volks73/feature-example-constructor
Add `example` constructor for Assert
2 parents a352d02 + bbf0fd8 commit 880a4bd

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/assert.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,27 @@ impl Assert {
8080
}
8181
}
8282

83+
/// Run a specific example of the current crate.
84+
///
85+
/// Defaults to asserting _successful_ execution.
86+
pub fn example<S: AsRef<OsStr>>(name: S) -> Self {
87+
Assert {
88+
cmd: vec![
89+
OsStr::new("cargo"),
90+
OsStr::new("run"),
91+
#[cfg(not(debug_assertions))]
92+
OsStr::new("--release"),
93+
OsStr::new("--quiet"),
94+
OsStr::new("--example"),
95+
name.as_ref(),
96+
OsStr::new("--"),
97+
].into_iter()
98+
.map(OsString::from)
99+
.collect(),
100+
..Self::default()
101+
}
102+
}
103+
83104
/// Run a custom command.
84105
///
85106
/// Defaults to asserting _successful_ execution.

0 commit comments

Comments
 (0)