Skip to content

Converting from Predicate<str> into Predicate<[u8]> #32

@mssun

Description

@mssun

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:

  1. assert_cmd and predicate's documentation are separated, you should look it back and forth.
  2. The from_utf8() is in the PredicateStrExt trait, 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions