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

Commit

Permalink
fix(output): Re-work API to work with rustfmt
Browse files Browse the repository at this point in the history
rustfmt will split long builers across lines, even when that breaks
logical grouping.

For example
```rust
assert_cli::Assert::command(&["ls", "foo-bar-foo"])
    .fails()
    .and()
    .stderr().contains("foo-bar-foo")
    .unwrap();
```
will be turned into
```rust
assert_cli::Assert::command(&["ls", "foo-bar-foo"])
    .fails()
    .and()
    .stderr()
    .contains("foo-bar-foo")
    .unwrap();
```
which obscures intent.

Normally, I don't like working around tools but this one seems
sufficient to do so.
```rust
assert_cli::Assert::command(&["ls", "foo-bar-foo"])
    .fails()
    .and()
    .stderr(assert_cli::Output::contains("foo-bar-foo"))
    .unwrap();
```

Pros
- More consistent with `with_env`
- Can add support for accepting arrays
- Still auto-complete / docs friendly
- Still expandable to additional assertions without much duplication or
  losing out on good error reporting

Cons
- More verbose if you don't `use assert_cli::{Assert, Environment, Output}`

Alternatives
- Accept distinct predicates
  - e.g. `.stderr(assert_cli::Is::text("foo-bar-foo"))`
  - e.g. `.stderr(assert_cli::Is::not("foo-bar-foo"))`
  - Strange `text` function
  - More structs to `use`
  - Less auto-complete / docs friendly (lacks contextual discovery or
    whatever the UX term is)

Fixes #70

BREAKING CHANGE: `.stdout().contains(text)` is now
`.stdout(assert_cli::Output::contains(text)`, etc.
  • Loading branch information
epage committed Oct 28, 2017
1 parent 3bc9787 commit 3afd1e6
Show file tree
Hide file tree
Showing 7 changed files with 262 additions and 241 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,20 @@ fn main() {
assert_cli::Assert::command(&["ls", "foo-bar-foo"])
.fails()
.and()
.stderr().contains("foo-bar-foo")
.stderr(assert_cli::Output::contains("foo-bar-foo"))
.unwrap();
}
```

If you want to match the program's output _exactly_, you can use
`stdout().is` (and shows the macro form of `command`):
`Output::is` (and shows the macro form of `command`):

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

0 comments on commit 3afd1e6

Please sign in to comment.