1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 19:47:45 +00:00

cp: fix cp-i GNU test

`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.
This commit is contained in:
Niyaz Nigmatullin 2022-09-17 19:15:52 +03:00
parent 2cddce26d3
commit 2ce999c959
2 changed files with 6 additions and 4 deletions

View file

@ -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)]
@ -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() {

View file

@ -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");
}