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

Commit

Permalink
Merge #38
Browse files Browse the repository at this point in the history
38: Reuse output assertions between stdout/stderr r=killercup a=epage

Reusing output assertions makes it easier to add new ones in the future.

I feel the new naming scheme this provides makes intent of the API clearer as well (`stdout().contains` vs `prints`).

This is done by creating an `OutputAssertionBuilder` that `Assertion` delegates to for creating output assertions, passing in an enum of which stream to read from.   This unfortunately meant dropping the cool type tricks that were introduced in #24.  This also required merging the storage of stdout/stderr assertions.  To accommodate this, output assertions are now appended which might be useful on its own.
  • Loading branch information
bors[bot] committed Sep 23, 2017
2 parents 0618fd2 + 64c766b commit 4cc32a5
Show file tree
Hide file tree
Showing 5 changed files with 162 additions and 212 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Here's a trivial example:
extern crate assert_cli;

fn main() {
assert_cli::Assert::command(&["echo", "42"]).prints("42").unwrap();
assert_cli::Assert::command(&["echo", "42"]).stdout().contains("42").unwrap();
}
```

Expand All @@ -31,7 +31,7 @@ Or if you'd rather use the macro, to save you some writing:
#[macro_use] extern crate assert_cli;

fn main() {
assert_cmd!(echo "42").prints("42").unwrap();
assert_cmd!(echo "42").stdout().contains("42").unwrap();
}
```

Expand All @@ -45,21 +45,21 @@ fn main() {
let test = assert_cmd!(ls "foo-bar-foo")
.fails()
.and()
.prints_error("foo-bar-foo")
.stderr().contains("foo-bar-foo")
.execute();
assert!(test.is_ok());
}
```

If you want to match the program's output _exactly_, you can use
`prints_exactly`:
`stdout().is`:

```rust,should_panic
#[macro_use] extern crate assert_cli;
fn main() {
assert_cmd!(wc "README.md")
.prints_exactly("1337 README.md")
.stdout().is("1337 README.md")
.unwrap();
}
```
Expand Down
Loading

0 comments on commit 4cc32a5

Please sign in to comment.