Skip to content

Commit

Permalink
Merge pull request #57 from conradkleinespel/fix-test
Browse files Browse the repository at this point in the history
Fixes pipe test
  • Loading branch information
conradkleinespel authored Jan 19, 2021
2 parents b4a96b6 + 953baba commit 019dc56
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 16 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ jobs:
name: Run cargo test
with:
command: test
args: --all-targets --all-features
- name: Run terminal tests
run: ./tests/tests-unix.sh
run: ./tests/tests-unix.sh
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]

name = "rpassword"
version = "5.0.0"
version = "5.0.1"
authors = ["Conrad Kleinespel <[email protected]>"]
description = "Read passwords in console applications."
license = "Apache-2.0"
Expand Down
18 changes: 6 additions & 12 deletions tests/piped.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,21 @@
//! 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"))
let mut out = Command::new("cargo")
.arg("run")
.arg("--quiet")
.arg("--example")
.arg("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();
Expand Down
4 changes: 2 additions & 2 deletions tests/tests-unix.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ DIR="$( dirname $( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) )"
# - diff tests/stderr <(printf "prompt_password_stderrprompt_reply_stderr")

# STDIN comes from a pipe
printf "1\n2\n3\n" | $DIR/target/debug/examples/tests > $DIR/tests/results_pipe_actual_stdout 2> $DIR/tests/results_pipe_actual_stderr
printf "1\n2\n3\n" | cargo run --quiet --example tests > $DIR/tests/results_pipe_actual_stdout 2> $DIR/tests/results_pipe_actual_stderr
diff $DIR/tests/results_pipe_expected_stdout $DIR/tests/results_pipe_actual_stdout
echo 'pipe stdout OK'
diff $DIR/tests/results_pipe_expected_stderr $DIR/tests/results_pipe_actual_stderr
echo 'pipe stderr OK'

# missing newline, only tested in pipe mode
printf "1\n2\n3" | $DIR/target/debug/examples/tests > $DIR/tests/results_pipe_missing_nl_actual_stdout 2> $DIR/tests/results_pipe_missing_nl_actual_stderr
printf "1\n2\n3" | cargo run --quiet --example tests > $DIR/tests/results_pipe_missing_nl_actual_stdout 2> $DIR/tests/results_pipe_missing_nl_actual_stderr
diff $DIR/tests/results_pipe_missing_nl_expected_stdout $DIR/tests/results_pipe_missing_nl_actual_stdout
echo 'pipe with missing nl stdout OK'
diff $DIR/tests/results_pipe_missing_nl_expected_stderr $DIR/tests/results_pipe_missing_nl_actual_stderr
Expand Down

0 comments on commit 019dc56

Please sign in to comment.