-
Notifications
You must be signed in to change notification settings - Fork 46
Description
As discussed in this PR mesalock-linux/mesabox#24. We should use predicate::str::contains(str).from_utf8() to convert Predicate<str> to Predicate<[u8]> for stdout() and stderr() comparison.
It's difficult to find answer in the documentation. There are several reasons:
assert_cmdandpredicate's documentation are separated, you should look it back and forth.- The
from_utf8()is in thePredicateStrExttrait, and it's difficult to find.
For example, my intuition is that stdout() accept a str like this: stdout("Hello, World!"). But what if I want to check if it contains this str? Then I found that stdout() accept a IntoOutputPredicate<P> actually. Then I switch to read the doc of IntoOutputPredicate and understand str implement this trait. But still, how to check contains? I read the doc of predicate and find out str::contains. The doc doesn't tell me how to use it in assert_cmd, then I'm confused. contains() gives me a ContainsPredicate. However, ContainsPredicate only implements Predicate<str>. At this point, I begin to be impatient and spent a lot of time reading the doc. Finally I find the PredicateStrExt.
This is my first experience of using assert_cmd and predicate. I don't know how to improve the APIs. I think it worth to improve the docs, like giving more examples combining assert_cmd and predicate.