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

WIP: Free fns for Output constructors and add prelude #75

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

killercup
Copy link
Collaborator

@killercup killercup commented Oct 29, 2017

Based on #74, cf. #74 (review)

  • No, I did not try to fix all the tests this is just a WIP to discuss if we want this

epage and others added 2 commits October 28, 2017 12:29
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.
@killercup killercup requested a review from epage October 29, 2017 11:32
@killercup
Copy link
Collaborator Author

@epage what do you think of this? (You just need to look at the second commit)

@killercup killercup changed the title Feature/output assert fns+prelude WIP: Free fns for Output constructors and add prelude Oct 29, 2017
@epage
Copy link
Collaborator

epage commented Oct 30, 2017

I'm hoping this isn't pride but I think I prefer the original solution.

  • Maybe I'm letting my python background through but I dislike wildcard use. I think preludes make sense for traits but thats it.
  • Serves better for progressive disclosure.
    • Docs and auto-completion only show you whats generally relevant. Once you decide to mess with Output, it starts to show you more options.

Thoughts? If you agree, I'll go ahead and fix up your suggestions on #74.

@killercup
Copy link
Collaborator Author

@epage I usually agree with wildcard imports being bad, but preludes are a special use case as they only re-export the things that you'd usually import anyway. But that's not the main point of the PR, you can expand the glob import—that's actually the one fancy refactoring feature the RLS has currently! Or do something like use assert_cli::ouput::predicates as output;. :)

What do you think about using free functions instead of constructors on Output? My main concern here is making test code be concise and expressive (both when reading and writing it), and I think .stderr(Output::is("foo")) is just that one tad too verbose. stderr is an output, so writing output a second time doesn't help much.

@epage epage mentioned this pull request Nov 3, 2017
@epage
Copy link
Collaborator

epage commented Nov 4, 2017

High level: I understand the desire to make the API less verbose. I think this is a case of us having slightly different priorities in API design. So I'd call it a tie with you breaking the tie in the direction you see fit.

If you go forward with this PR, we should have at least once one example not using a prelude to help people if there is a symbol conflict

Details (continued):

  • If we encourage use assert_cli::ouput::predicates as output;, what happens if we add a trait in the future?
  • Regarding free factory functions: I put a slightly higher priority on consistent API design over being less verbose. People expect factories to be on the type they create.
  • The factory being on the type provides symmetry with Environment

@epage
Copy link
Collaborator

epage commented Jan 11, 2018

Before working on #80, we should probably decide between

to avoid major conflicts between the output work for #80 and this.

@killercup
Copy link
Collaborator Author

Sorry, I'd love to make progress here. I really feel like I should spend some time thinking about this and maybe experimenting with more real-world code; but I don't have much time right now :( So I'd be open to gather arguments from more people and figuring out a general consensus.

@epage
Copy link
Collaborator

epage commented Jan 12, 2018

Seems reasonable.

@epage epage mentioned this pull request Jan 25, 2018
4 tasks
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants