assert_cli
assert_cli copied to clipboard
How to test piping one command into another
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.
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?
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
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.