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

How to compare stdout with a Vec<u8>? #50

Closed
mssun opened this issue Sep 3, 2018 · 3 comments
Closed

How to compare stdout with a Vec<u8>? #50

mssun opened this issue Sep 3, 2018 · 3 comments

Comments

@mssun
Copy link
Contributor

mssun commented Sep 3, 2018

I want compare command stdout with my tested app's stdout like this:

    let output = Command::new("uname").output().unwrap();
    let stdout = output.stdout;
    new_cmd!()
        .assert()
        .success()
        .stdout(stdout)    // this will give an error
        .stderr("");

I can't find a simple API from predicates. Can you suggest a proper way to handle this?

@epage
Copy link
Contributor

epage commented Sep 3, 2018

So if we go to the docs, .stdout() takes a IntoOutputPredicate. There is an implementation that takes a &'static [u8].

A Vec<u8> can be derefed as a &[u8] but the lifetime is a problem (possibly a bug?).

But you can use it for inspiration.

So in theory, you could do something like

use predicates::prelude::*;

    let output = Command::new("uname").output().unwrap();
    let stdout = output.stdout;
    new_cmd!()
        .assert()
        .success()
        .stdout(predicate::eq(&stdout as &[u8]))
        .stderr("");

@epage
Copy link
Contributor

epage commented Sep 3, 2018

And I created #51

@mssun
Copy link
Contributor Author

mssun commented Sep 3, 2018

Thank you @epage, I get it now.

@epage epage closed this as completed Sep 3, 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