assert_cli icon indicating copy to clipboard operation
assert_cli copied to clipboard

How to test piping one command into another

Open samuela opened this issue 5 years ago • 3 comments

I have a situation in which I'd like to test the output of things like myprog | head and echo "foobar" | myprog. Is there a way to accomplish this with assert_cli? A concise assert_cmd! option would be ideal.

samuela avatar Jan 25 '20 01:01 samuela

Are you just wanting to test your programs handling of stdin/stdout or is there something more specific you want to test related to pipes, like broken pipes?

epage avatar Jan 25 '20 02:01 epage

Both ultimately would be nice but piping stdin/stdout is the most pressing. I ended up finding https://github.com/oconnor663/duct.rs and I'm giving that a shot atm

samuela avatar Jan 25 '20 03:01 samuela

If you just need to pipe, then it's easy to run ["/bin/sh", "-c", "your | piped | commands"], I do that in a few places (although for more complicated shell scripts that are out of scope for assert_cmd).

Proper pipe support in assert_cmd would be great, though it implies support for running and scheduling multiple commands, which is a can of worms we've opened elsewhere.

vincentdephily avatar Jan 31 '20 10:01 vincentdephily