Add details to stdin section of Machine Communication
Closes https://github.com/rust-cli/book/issues/55; based on convo there.
Let me know if I should redo the sample code to use clap and include tests for it. I wasn't sure if that's necessary or not.
Thanks for the feedback and working with me through all of this!
I pushed up the requested changes and verified the program works. I tried to add a separate test file in src/in-depth/tests but cargo test wasn't running. Is there anything in particular I need to get that to work or should I just let it be without the separate test?
It was this at src/in-depth/tests/machine-communication-stdin.rs:
use assert_cmd::Command;
#[test]
fn single_file() -> Result<(), Box<dyn std::error::Error>> {
let mut cmd = Command::cargo_bin("machine-communication-stdin")?;
cmd.arg("haiku.txt");
cmd.assert().success().stdout(String::from("7\n"));
Ok(())
}
#[test]
fn stdin() -> Result<(), Box<dyn std::error::Error>> {
let mut cmd = Command::cargo_bin("machine-communication-stdin")?;
cmd.arg("-")
.write_stdin("Hello, world! My first name is Standard, my last name is In.\n");
cmd.assert().success().stdout(String::from("12\n"));
Ok(())
}
#[test]
fn file_doesnt_exist() -> Result<(), Box<dyn std::error::Error>> {
let mut cmd = Command::cargo_bin("machine-communication-stdin")?;
cmd.arg("tests/file/doesnt/exist");
cmd.assert()
.failure()
.stderr(predicate::str::contains("No such file or directory"))
Ok(())
}
I've tried to address all of the feedback. 👍 I'd like to squash some (or all) of the commits whenever this is ready to merge, as I have some fixup commits for a few mistakes I corrected.
@epage would you be up for reviewing this again when you have a chance? Thank you!