Skip to content

Commit

Permalink
feat: Short-hand Assert::code
Browse files Browse the repository at this point in the history
Part of #2
  • Loading branch information
epage committed May 30, 2018
1 parent 01a8f12 commit e234685
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/assert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,15 @@ impl Assert {
/// .assert()
/// .code(predicates::ord::eq(42));
/// ```
pub fn code(self, pred: &predicates::Predicate<i32>) -> Self {
pub fn code<I, P>(self, pred: I) -> Self
where
I: IntoCodePredicate<P>,
P: predicates::Predicate<i32>,
{
self.code_impl(&pred.into_code())
}

fn code_impl(self, pred: &predicates::Predicate<i32>) -> Self {
let actual_code = self.output
.status
.code()
Expand Down
22 changes: 22 additions & 0 deletions tests/assert.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
extern crate assert_cmd;
extern crate predicates;

use std::process::Command;

use assert_cmd::prelude::*;
use predicates::prelude::*;

#[test]
fn code_example() {
Command::main_binary()
.unwrap()
.env("exit", "42")
.assert()
.code(42);
// which is equivalent to
Command::main_binary()
.unwrap()
.env("exit", "42")
.assert()
.code(predicate::eq(42));
}

0 comments on commit e234685

Please sign in to comment.