Skip to content
This repository has been archived by the owner on Dec 29, 2021. It is now read-only.

Piping (stdin) to the process #26

Closed
killercup opened this issue Mar 23, 2017 · 5 comments
Closed

Piping (stdin) to the process #26

killercup opened this issue Mar 23, 2017 · 5 comments

Comments

@killercup
Copy link
Collaborator

Something like AssertCli::command("cat").given_input(reader).prints(reader_as_string)

cf. #21

@sevagh
Copy link
Contributor

sevagh commented Oct 4, 2017

This would be a big help to me. Another thing could be setting environment variables. Like many people I have my own hacky wrapper around std::process and I rely on stdin and environment variables to test my binary properly:

https://github.com/sevagh/pq/blob/master/tests/runner/mod.rs#L36

@epage
Copy link
Collaborator

epage commented Oct 4, 2017

This would be a big help to me.

https://github.com/sevagh/pq/blob/master/tests/runner/mod.rs#L36

Would you be willing to get your with_stdin into a PR against assert_cli? I personally do not (yet) have opinions on the name (with_stdin, stdin, given_input).

I rely on stdin and environment variables to test my binary properly:

Freyskeyd is looking at handling environment variables in #27. Feel free to jump on over there to see how well our current plan will handle your needs and provide feedback.

@sevagh
Copy link
Contributor

sevagh commented Oct 4, 2017

I'm running into some difficulty. It's as if cwd changed due to my changes:

output=``````', src/assert.rs:316
note: Run with `RUST_BACKTRACE=1` for a backtrace.
test readme_sect_example_line_30 ... FAILED
42
thread 'main' panicked at 'CLI assertion failed: `echo 42` StdOut mismatch: expected to contain "42"
output=``````', src/assert.rs:316
note: Run with `RUST_BACKTRACE=1` for a backtrace.
test readme_sect_example_line_20 ... FAILED
ls: cannot access 'foo-bar-foo': No such file or directory
thread 'main' panicked at 'assertion failed: test.is_ok()', /tmp/rust-skeptic.jyzyW7R9Webs/test.rs:10
note: Run with `RUST_BACKTRACE=1` for a backtrace.
test readme_sect_example_line_41 ... FAILED

My changes:
master...sevagh:master

I have yet to write stdin-specific tests, I just happened to break the regular tests.

@epage
Copy link
Collaborator

epage commented Oct 4, 2017

Oye, that is frustratingly unclear from the documentation.

spawn, output, and status all have different defaults when you don't explicitly set stdin/stdout/stderr

You have to pay close attention in the docs

spawn
By default, stdin, stdout and stderr are inherited from the parent.

output
By default, stdin, stdout and stderr are captured (and used to provide the resulting output).

status
By default, stdin, stdout and stderr are inherited from the parent.

I didn't notice until I went digging in the source code for std::process::Command and std::sys::process

So you need

       let command = command
             .stdin(Stdio::piped())
             .stdout(Stdio::piped())
             .stderr(Stdio::piped());

@sevagh
Copy link
Contributor

sevagh commented Oct 5, 2017

Thanks for the help. Here's the PR: #44

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants