Skip to content

Commit

Permalink
Merge pull request #15 from epage/api
Browse files Browse the repository at this point in the history
fix(assert): Don't put concrete predicates in the API
  • Loading branch information
epage authored Jun 18, 2018
2 parents a0105e3 + 933c3fe commit 2a17c34
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 24 deletions.
29 changes: 12 additions & 17 deletions src/assert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ impl Assert {
self
}

/// Ensure the command returned the expected code.
/// Ensure the command aborted before returning a code.
pub fn interrupted(self) -> Self {
if self.output.status.code().is_some() {
panic!("Unexpected completion\n{}", self);
Expand All @@ -166,7 +166,7 @@ impl Assert {
///
/// # Examples
///
/// ```rust,ignore
/// ```rust
/// use assert_cmd::prelude::*;
///
/// use std::process::Command;
Expand All @@ -176,12 +176,6 @@ impl Assert {
/// .env("exit", "42")
/// .assert()
/// .code(42);
/// // which is equivalent to
/// Command::main_binary()
/// .unwrap()
/// .env("exit", "42")
/// .assert()
/// .code(predicates::ord::eq(42));
/// ```
pub fn code<I, P>(self, pred: I) -> Self
where
Expand All @@ -206,7 +200,7 @@ impl Assert {
///
/// # Examples
///
/// ```rust,ignore
/// ```rust
/// use assert_cmd::prelude::*;
///
/// use std::process::Command;
Expand All @@ -216,7 +210,7 @@ impl Assert {
/// .env("stdout", "hello")
/// .env("stderr", "world")
/// .assert()
/// .stdout(predicates::ord::eq(b"hello"));
/// .stdout("hello\n");
/// ```
pub fn stdout<I, P>(self, pred: I) -> Self
where
Expand All @@ -240,7 +234,7 @@ impl Assert {
///
/// # Examples
///
/// ```rust,ignore
/// ```rust
/// use assert_cmd::prelude::*;
///
/// use std::process::Command;
Expand All @@ -250,7 +244,7 @@ impl Assert {
/// .env("stdout", "hello")
/// .env("stderr", "world")
/// .assert()
/// .stderr(predicates::ord::eq(b"world"));
/// .stderr("world\n");
/// ```
pub fn stderr<I, P>(self, pred: I) -> Self
where
Expand Down Expand Up @@ -349,11 +343,12 @@ where
}
}

impl<P> IntoOutputPredicate<predicates::str::Utf8Predicate<P>> for P
where
P: predicates::Predicate<str>,
impl IntoOutputPredicate<predicates::str::Utf8Predicate<predicates::ord::EqPredicate<&'static str>>>
for &'static str
{
fn into_output(self) -> predicates::str::Utf8Predicate<P> {
self.from_utf8()
fn into_output(
self,
) -> predicates::str::Utf8Predicate<predicates::ord::EqPredicate<&'static str>> {
predicates::ord::eq(self).from_utf8()
}
}
13 changes: 6 additions & 7 deletions tests/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,46 +4,45 @@ extern crate predicates;
use std::process;

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

#[test]
fn main_binary() {
let mut cmd = process::Command::main_binary().unwrap();
cmd.env("stdout", "42");
cmd.assert().success().stdout(predicate::eq("42").trim());
cmd.assert().success().stdout("42\n");
}

#[test]
fn main_binary_with_empty_env() {
let mut cmd = process::Command::main_binary().unwrap();
cmd.env_clear().env("stdout", "42");
cmd.assert().success().stdout(predicate::eq("42").trim());
cmd.assert().success().stdout("42\n");
}

#[test]
fn cargo_binary() {
let mut cmd = process::Command::cargo_bin("bin_fixture").unwrap();
cmd.env("stdout", "42");
cmd.assert().success().stdout(predicate::eq("42").trim());
cmd.assert().success().stdout("42\n");
}

#[test]
fn cargo_binary_with_empty_env() {
let mut cmd = process::Command::cargo_bin("bin_fixture").unwrap();
cmd.env_clear().env("stdout", "42");
cmd.assert().success().stdout(predicate::eq("42").trim());
cmd.assert().success().stdout("42\n");
}

#[test]
fn cargo_example() {
let mut cmd = process::Command::cargo_example("example_fixture").unwrap();
cmd.env("stdout", "42");
cmd.assert().success().stdout(predicate::eq("42").trim());
cmd.assert().success().stdout("42\n");
}

#[test]
fn cargo_example_with_empty_env() {
let mut cmd = process::Command::cargo_example("example_fixture").unwrap();
cmd.env_clear().env("stdout", "42");
cmd.assert().success().stdout(predicate::eq("42").trim());
cmd.assert().success().stdout("42\n");
}

0 comments on commit 2a17c34

Please sign in to comment.