Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Skip calling Windows console api with piped stdin (#51)
* skip calling windows console api with piped stdin * test with piped stdin * upgrade appveyor's rustc to 1.44.0
- Loading branch information
Showing
3 changed files
with
57 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
//! This test checks that piped input is handled correctly. | ||
|
||
use std::env; | ||
use std::io::Write; | ||
use std::process::{Command, Stdio}; | ||
|
||
#[test] | ||
fn piped_password() { | ||
// Find target directory | ||
let target_dir = env::current_exe() | ||
.unwrap() | ||
.parent() | ||
.unwrap() | ||
.parent() | ||
.unwrap() | ||
.to_path_buf(); | ||
|
||
// Run an example that reads a password and prints it | ||
let mut out = Command::new(target_dir.join("examples/read-password")) | ||
.stdout(Stdio::piped()) | ||
.stdin(Stdio::piped()) | ||
.spawn() | ||
.unwrap(); | ||
|
||
// Write "secret" as the password into stdin | ||
let stdin = out.stdin.as_mut().unwrap(); | ||
stdin.write_all("secret".as_bytes()).unwrap(); | ||
|
||
let out = out.wait_with_output().unwrap(); | ||
assert!(out.status.success()); | ||
|
||
let stdout = String::from_utf8(out.stdout).unwrap(); | ||
println!("stdout: {}", stdout); | ||
assert!(stdout.ends_with("Password: secret\n")); | ||
} |