Skip to content

Commit

Permalink
cp: fix cp-i GNU test
Browse files Browse the repository at this point in the history
`cp` in interactive mode used to write to stdout asking for
overwrite. GNU version writes to stderr.

Changed: write to stderr to make compatible with GNU.
  • Loading branch information
niyaznigmatullin committed Sep 17, 2022
1 parent 2cddce2 commit 2ce999c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/uu/cp/src/cp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ use std::fs;
use std::fs::File;
use std::fs::OpenOptions;
use std::io;
use std::io::{stdin, stdout, Write};
use std::io::{stderr, stdin, Write};
#[cfg(unix)]
use std::os::unix::ffi::OsStrExt;
#[cfg(unix)]
Expand Down Expand Up @@ -118,9 +118,9 @@ macro_rules! or_continue(
/// answered yes.
macro_rules! prompt_yes(
($($args:tt)+) => ({
print!($($args)+);
print!(" [y/N]: ");
crash_if_err!(1, stdout().flush());
eprint!($($args)+);
eprint!(" [y/N]: ");
crash_if_err!(1, stderr().flush());
let mut s = String::new();
match stdin().read_line(&mut s) {
Ok(_) => match s.char_indices().next() {
Expand Down
2 changes: 2 additions & 0 deletions tests/by-util/test_cp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,8 @@ fn test_cp_arg_interactive() {
.arg("-i")
.pipe_in("N\n")
.succeeds()
.no_stdout()
.stderr_contains(format!("overwrite '{}'?", TEST_HOW_ARE_YOU_SOURCE))
.stderr_contains("Not overwriting");
}

Expand Down

0 comments on commit 2ce999c

Please sign in to comment.