Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Easy "stdout contains" assertions #11

Closed
killercup opened this issue May 30, 2018 · 4 comments
Closed

Easy "stdout contains" assertions #11

killercup opened this issue May 30, 2018 · 4 comments

Comments

@killercup
Copy link
Contributor

killercup commented May 30, 2018

I'm trying to use this for a project instead of the published version of assert_cli. I'm super impressed by what you've accomplished here in the short time!

It seems that currently, there is no easy way to check that the output of a command contains some text. Or did I miss something?

Predicates only has a str::contains but stdout is a Vec<u8>. It seems that it could work with predicate::function, but it is quite cumbersome. I'm basically looking for good way of writing .stdout(&predicate::function(|x: &Vec<u8>| String::from_utf8_lossy(x).contains("Done!"))) -- but ideally without the need to use from_utf8_lossy. This last requirement is also why I opened this issue here, and not on the predicates, I expect we may need to talk about how to best deal with the Vec<u8> representation.

@epage
Copy link
Contributor

epage commented May 30, 2018

Any Predicate<str> has an extension method from_utf8 to turn it into one that should be usable for stdout... I hope. Can't remember if that has an explicit test. Check the tests folder for possible examples.

@killercup
Copy link
Contributor Author

Ah, very cool. Couldn't find it because it's not yet in a released version. Sadly, it also doesn't seem to like Vec<u8> because "the trait predicates::core::Predicate<std::vec::Vec<u8>> is not implemented for predicates::str::Utf8Predicate<predicates::str::ContainsPredicate>".

@epage
Copy link
Contributor

epage commented May 30, 2018

Didn't realize it wasn't published. I'll get it out and update the tests, fixing ergonomics along the way.

@epage
Copy link
Contributor

epage commented May 31, 2018

Need to come up with solutions for assert-rs/predicates-rs#20

Specifically for this case, the best I'm coming up with is adding a deref() via extension traits and having IntoOutputPredicate call it on Predicate<&str>

@epage epage closed this as completed in 8cdfb91 Jun 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants