mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-09-15 19:36:16 +00:00
Merge branch 'main' into cp-backup-force
This commit is contained in:
commit
446df9da5a
71 changed files with 856 additions and 258 deletions
|
@ -423,6 +423,38 @@ fn test_chown_only_user_id() {
|
|||
.stderr_contains("failed to change");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_chown_fail_id() {
|
||||
// test chown 1111. file.txt
|
||||
|
||||
let scene = TestScenario::new(util_name!());
|
||||
let at = &scene.fixtures;
|
||||
|
||||
let result = scene.cmd_keepenv("id").arg("-u").run();
|
||||
if skipping_test_is_okay(&result, "id: cannot find name for group ID") {
|
||||
return;
|
||||
}
|
||||
let user_id = String::from(result.stdout_str().trim());
|
||||
assert!(!user_id.is_empty());
|
||||
|
||||
let file1 = "test_chown_file1";
|
||||
at.touch(file1);
|
||||
|
||||
scene
|
||||
.ucmd()
|
||||
.arg(format!("{}:", user_id))
|
||||
.arg(file1)
|
||||
.fails()
|
||||
.stderr_contains("invalid spec");
|
||||
|
||||
scene
|
||||
.ucmd()
|
||||
.arg(format!("{}.", user_id))
|
||||
.arg(file1)
|
||||
.fails()
|
||||
.stderr_contains("invalid spec");
|
||||
}
|
||||
|
||||
/// Test for setting the owner to a user ID for a user that does not exist.
|
||||
///
|
||||
/// For example:
|
||||
|
@ -708,7 +740,7 @@ fn test_chown_file_notexisting() {
|
|||
.fails();
|
||||
|
||||
// TODO: uncomment once "failed to change ownership of '{}' to {}" added to stdout
|
||||
// result.stderr_contains(&"retained as");
|
||||
// result.stderr_contains("retained as");
|
||||
// TODO: uncomment once message changed from "cannot dereference" to "cannot access"
|
||||
// result.stderr_contains(&"cannot access 'not_existing': No such file or directory");
|
||||
// result.stderr_contains("cannot access 'not_existing': No such file or directory");
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// spell-checker:ignore (flags) reflink (fs) tmpfs (linux) rlimit Rlim NOFILE clob btrfs ROOTDIR USERDIR procfs
|
||||
// spell-checker:ignore (flags) reflink (fs) tmpfs (linux) rlimit Rlim NOFILE clob btrfs ROOTDIR USERDIR procfs outfile
|
||||
|
||||
use crate::common::util::*;
|
||||
#[cfg(not(windows))]
|
||||
|
@ -215,6 +215,18 @@ fn test_cp_target_directory_is_file() {
|
|||
.stderr_contains(format!("'{}' is not a directory", TEST_HOW_ARE_YOU_SOURCE));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_cp_arg_update_interactive() {
|
||||
new_ucmd!()
|
||||
.arg(TEST_HELLO_WORLD_SOURCE)
|
||||
.arg(TEST_HOW_ARE_YOU_SOURCE)
|
||||
.arg("-i")
|
||||
.arg("--update")
|
||||
.succeeds()
|
||||
.no_stdout()
|
||||
.no_stderr();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_cp_arg_interactive() {
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
|
@ -1827,6 +1839,19 @@ fn test_copy_through_dangling_symlink_no_dereference_2() {
|
|||
.stderr_only("cp: not writing through dangling symlink 'target'");
|
||||
}
|
||||
|
||||
/// Test that copy through a dangling symbolic link fails, even with --force.
|
||||
#[test]
|
||||
#[cfg(not(windows))]
|
||||
fn test_copy_through_dangling_symlink_force() {
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
at.touch("src");
|
||||
at.symlink_file("no-such-file", "dest");
|
||||
ucmd.args(&["--force", "src", "dest"])
|
||||
.fails()
|
||||
.stderr_only("cp: not writing through dangling symlink 'dest'");
|
||||
assert!(!at.file_exists("dest"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(unix)]
|
||||
fn test_cp_archive_on_nonexistent_file() {
|
||||
|
@ -2269,3 +2294,32 @@ fn test_same_file_force_backup() {
|
|||
.no_stderr();
|
||||
assert!(at.file_exists("f~"));
|
||||
}
|
||||
|
||||
/// Test for copying the contents of a FIFO as opposed to the FIFO object itself.
|
||||
#[cfg(unix)]
|
||||
#[test]
|
||||
fn test_copy_contents_fifo() {
|
||||
let scenario = TestScenario::new(util_name!());
|
||||
let at = &scenario.fixtures;
|
||||
|
||||
// Start the `cp` process, reading the contents of `fifo` and
|
||||
// writing to regular file `outfile`.
|
||||
at.mkfifo("fifo");
|
||||
let mut ucmd = scenario.ucmd();
|
||||
let child = ucmd
|
||||
.args(&["--copy-contents", "fifo", "outfile"])
|
||||
.run_no_wait();
|
||||
|
||||
// Write some bytes to the `fifo`. We expect these bytes to get
|
||||
// copied through to `outfile`.
|
||||
std::fs::write(at.plus("fifo"), "foo").unwrap();
|
||||
|
||||
// At this point the child process should have terminated
|
||||
// successfully with no output. The `outfile` should have the
|
||||
// contents of `fifo` copied into it.
|
||||
let output = child.wait_with_output().unwrap();
|
||||
assert!(output.status.success());
|
||||
assert!(output.stdout.is_empty());
|
||||
assert!(output.stderr.is_empty());
|
||||
assert_eq!(at.read("outfile"), "foo");
|
||||
}
|
||||
|
|
|
@ -220,7 +220,7 @@ fn test_change_directory() {
|
|||
let out = scene
|
||||
.ucmd()
|
||||
.arg("--chdir")
|
||||
.arg(&temporary_path)
|
||||
.arg(temporary_path)
|
||||
.args(&pwd)
|
||||
.succeeds()
|
||||
.stdout_move_str();
|
||||
|
|
|
@ -1863,7 +1863,7 @@ fn test_ls_recursive() {
|
|||
#[cfg(not(windows))]
|
||||
result.stdout_contains("a/b:\nb");
|
||||
#[cfg(windows)]
|
||||
result.stdout_contains(&"a\\b:\nb");
|
||||
result.stdout_contains("a\\b:\nb");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -2093,13 +2093,13 @@ fn test_ls_indicator_style() {
|
|||
.ucmd()
|
||||
.arg(format!("--indicator-style={}", opt))
|
||||
.succeeds()
|
||||
.stdout_contains(&"/");
|
||||
.stdout_contains("/");
|
||||
}
|
||||
|
||||
// Same test as above, but with the alternate flags.
|
||||
let options = vec!["--classify", "--file-type", "-p"];
|
||||
for opt in options {
|
||||
scene.ucmd().arg(opt).succeeds().stdout_contains(&"/");
|
||||
scene.ucmd().arg(opt).succeeds().stdout_contains("/");
|
||||
}
|
||||
|
||||
// Classify and File-Type all contain indicators for pipes and links.
|
||||
|
@ -2110,7 +2110,7 @@ fn test_ls_indicator_style() {
|
|||
.ucmd()
|
||||
.arg(format!("--indicator-style={}", opt))
|
||||
.succeeds()
|
||||
.stdout_contains(&"@");
|
||||
.stdout_contains("@");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3195,7 +3195,7 @@ fn test_ls_context_format() {
|
|||
] {
|
||||
let format = format!("--format={}", word);
|
||||
ts.ucmd()
|
||||
.args(&[&"-Z", &format.as_str(), &"/"])
|
||||
.args(&["-Z", format.as_str(), "/"])
|
||||
.succeeds()
|
||||
.stdout_only(
|
||||
unwrap_or_return!(expected_result(&ts, &["-Z", format.as_str(), "/"])).stdout_str(),
|
||||
|
|
|
@ -825,3 +825,9 @@ fn test_nonexistent_dir_prefix() {
|
|||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_default_missing_value() {
|
||||
let scene = TestScenario::new(util_name!());
|
||||
scene.ucmd().arg("-d").arg("--tmpdir").succeeds();
|
||||
}
|
||||
|
|
|
@ -184,6 +184,25 @@ fn test_mv_interactive() {
|
|||
assert!(at.file_exists(file_b));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_mv_arg_update_interactive() {
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
|
||||
let file_a = "test_mv_replace_file_a";
|
||||
let file_b = "test_mv_replace_file_b";
|
||||
|
||||
at.touch(file_a);
|
||||
at.touch(file_b);
|
||||
|
||||
ucmd.arg(file_a)
|
||||
.arg(file_b)
|
||||
.arg("-i")
|
||||
.arg("--update")
|
||||
.succeeds()
|
||||
.no_stdout()
|
||||
.no_stderr();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_mv_no_clobber() {
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
|
|
|
@ -373,6 +373,19 @@ fn test_format_selected_fields() {
|
|||
.args(&["--from=auto", "--field", "1,4,3", "1K 2K 3K 4K 5K 6K"])
|
||||
.succeeds()
|
||||
.stdout_only("1000 2K 3000 4000 5K 6K\n");
|
||||
|
||||
new_ucmd!()
|
||||
.args(&["--from=auto", "--field", "1,4 3", "1K 2K 3K 4K 5K 6K"])
|
||||
.succeeds()
|
||||
.stdout_only("1000 2K 3000 4000 5K 6K\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_format_implied_range_and_field() {
|
||||
new_ucmd!()
|
||||
.args(&["--from=auto", "--field", "-2,4", "1K 2K 3K 4K 5K 6K"])
|
||||
.succeeds()
|
||||
.stdout_only("1000 2000 3K 4000 5K 6K\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -391,6 +404,18 @@ fn test_format_selected_field_range() {
|
|||
.stdout_only("1K 2000 3000 4000 5000 6K\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_format_all_fields() {
|
||||
let all_fields_patterns = vec!["-", "-,3", "3,-", "1,-,3", "- 3"];
|
||||
|
||||
for pattern in all_fields_patterns {
|
||||
new_ucmd!()
|
||||
.args(&["--from=auto", "--field", pattern, "1K 2K 3K 4K 5K 6K"])
|
||||
.succeeds()
|
||||
.stdout_only("1000 2000 3000 4000 5000 6000\n");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_should_succeed_if_range_out_of_bounds() {
|
||||
new_ucmd!()
|
||||
|
@ -530,7 +555,7 @@ fn test_round() {
|
|||
new_ucmd!()
|
||||
.args(&[
|
||||
"--to=si",
|
||||
&format!("--round={}", method),
|
||||
&format!("--round={method}"),
|
||||
"--",
|
||||
"9001",
|
||||
"-9001",
|
||||
|
@ -542,6 +567,32 @@ fn test_round() {
|
|||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_round_with_to_unit() {
|
||||
for (method, exp) in [
|
||||
("from-zero", ["6", "-6", "5.9", "-5.9", "5.86", "-5.86"]),
|
||||
("towards-zero", ["5", "-5", "5.8", "-5.8", "5.85", "-5.85"]),
|
||||
("up", ["6", "-5", "5.9", "-5.8", "5.86", "-5.85"]),
|
||||
("down", ["5", "-6", "5.8", "-5.9", "5.85", "-5.86"]),
|
||||
("nearest", ["6", "-6", "5.9", "-5.9", "5.86", "-5.86"]),
|
||||
] {
|
||||
new_ucmd!()
|
||||
.args(&[
|
||||
"--to-unit=1024",
|
||||
&format!("--round={method}"),
|
||||
"--",
|
||||
"6000",
|
||||
"-6000",
|
||||
"6000.0",
|
||||
"-6000.0",
|
||||
"6000.00",
|
||||
"-6000.00",
|
||||
])
|
||||
.succeeds()
|
||||
.stdout_only(exp.join("\n") + "\n");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_suffix_is_added_if_not_supplied() {
|
||||
new_ucmd!()
|
||||
|
|
|
@ -90,6 +90,35 @@ fn test_symlinked_default() {
|
|||
env.ucmd.succeeds().stdout_is(env.subdir + "\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_symlinked_default_posix() {
|
||||
let mut env = symlinked_env();
|
||||
env.ucmd
|
||||
.env("POSIXLY_CORRECT", "1")
|
||||
.succeeds()
|
||||
.stdout_is(env.symdir.clone() + "\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_symlinked_default_posix_l() {
|
||||
let mut env = symlinked_env();
|
||||
env.ucmd
|
||||
.env("POSIXLY_CORRECT", "1")
|
||||
.arg("-L")
|
||||
.succeeds()
|
||||
.stdout_is(env.symdir + "\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_symlinked_default_posix_p() {
|
||||
let mut env = symlinked_env();
|
||||
env.ucmd
|
||||
.env("POSIXLY_CORRECT", "1")
|
||||
.arg("-P")
|
||||
.succeeds()
|
||||
.stdout_is(env.symdir + "\n");
|
||||
}
|
||||
|
||||
#[cfg(not(windows))]
|
||||
pub mod untrustworthy_pwd_var {
|
||||
use std::path::Path;
|
||||
|
|
|
@ -400,6 +400,151 @@ fn test_rm_descend_directory() {
|
|||
assert!(!at.file_exists(file_2));
|
||||
}
|
||||
|
||||
#[cfg(feature = "chmod")]
|
||||
#[test]
|
||||
fn test_rm_prompts() {
|
||||
use std::io::Write;
|
||||
use std::process::Child;
|
||||
|
||||
// Needed for talking with stdin on platforms where CRLF or LF matters
|
||||
const END_OF_LINE: &str = if cfg!(windows) { "\r\n" } else { "\n" };
|
||||
|
||||
let mut answers = vec![
|
||||
"rm: descend into directory 'a'?",
|
||||
"rm: remove write-protected regular empty file 'a/empty-no-write'?",
|
||||
"rm: remove symbolic link 'a/slink'?",
|
||||
"rm: remove symbolic link 'a/slink-dot'?",
|
||||
"rm: remove write-protected regular file 'a/f-no-write'?",
|
||||
"rm: remove regular empty file 'a/empty'?",
|
||||
"rm: remove directory 'a/b'?",
|
||||
"rm: remove write-protected directory 'a/b-no-write'?",
|
||||
"rm: remove directory 'a'?",
|
||||
];
|
||||
|
||||
answers.sort();
|
||||
|
||||
let yes = format!("y{}", END_OF_LINE);
|
||||
|
||||
let scene = TestScenario::new(util_name!());
|
||||
let at = &scene.fixtures;
|
||||
|
||||
at.mkdir("a/");
|
||||
|
||||
let file_1 = "a/empty";
|
||||
let file_2 = "a/empty-no-write";
|
||||
let file_3 = "a/f-no-write";
|
||||
|
||||
at.touch(file_1);
|
||||
at.touch(file_2);
|
||||
at.make_file(file_3)
|
||||
.write_all(b"not-empty")
|
||||
.expect("Couldn't write to a/f-no-write");
|
||||
|
||||
at.symlink_dir("a/empty-f", "a/slink");
|
||||
at.symlink_dir(".", "a/slink-dot");
|
||||
|
||||
let dir_1 = "a/b/";
|
||||
let dir_2 = "a/b-no-write/";
|
||||
|
||||
at.mkdir(dir_1);
|
||||
at.mkdir(dir_2);
|
||||
|
||||
scene
|
||||
.ccmd("chmod")
|
||||
.arg("u-w")
|
||||
.arg(file_3)
|
||||
.arg(dir_2)
|
||||
.arg(file_2)
|
||||
.succeeds();
|
||||
|
||||
let mut child: Child = scene.ucmd().arg("-ri").arg("a").run_no_wait();
|
||||
|
||||
let mut child_stdin = child.stdin.take().unwrap();
|
||||
child_stdin.write_all(yes.as_bytes()).unwrap();
|
||||
child_stdin.flush().unwrap();
|
||||
child_stdin.write_all(yes.as_bytes()).unwrap();
|
||||
child_stdin.flush().unwrap();
|
||||
child_stdin.write_all(yes.as_bytes()).unwrap();
|
||||
child_stdin.flush().unwrap();
|
||||
child_stdin.write_all(yes.as_bytes()).unwrap();
|
||||
child_stdin.flush().unwrap();
|
||||
child_stdin.write_all(yes.as_bytes()).unwrap();
|
||||
child_stdin.flush().unwrap();
|
||||
child_stdin.write_all(yes.as_bytes()).unwrap();
|
||||
child_stdin.flush().unwrap();
|
||||
child_stdin.write_all(yes.as_bytes()).unwrap();
|
||||
child_stdin.flush().unwrap();
|
||||
child_stdin.write_all(yes.as_bytes()).unwrap();
|
||||
child_stdin.flush().unwrap();
|
||||
child_stdin.write_all(yes.as_bytes()).unwrap();
|
||||
child_stdin.flush().unwrap();
|
||||
|
||||
let output = child.wait_with_output().unwrap();
|
||||
|
||||
let mut trimmed_output = Vec::new();
|
||||
for string in String::from_utf8(output.stderr)
|
||||
.expect("Couldn't convert output.stderr to string")
|
||||
.split("rm: ")
|
||||
{
|
||||
if !string.is_empty() {
|
||||
let trimmed_string = format!("rm: {}", string).trim().to_string();
|
||||
trimmed_output.push(trimmed_string);
|
||||
}
|
||||
}
|
||||
|
||||
trimmed_output.sort();
|
||||
|
||||
assert!(trimmed_output.len() == answers.len());
|
||||
|
||||
for (i, checking_string) in trimmed_output.iter().enumerate() {
|
||||
assert!(checking_string == answers[i]);
|
||||
}
|
||||
|
||||
assert!(!at.dir_exists("a"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_rm_force_prompts_order() {
|
||||
use std::io::Write;
|
||||
use std::process::Child;
|
||||
|
||||
// Needed for talking with stdin on platforms where CRLF or LF matters
|
||||
const END_OF_LINE: &str = if cfg!(windows) { "\r\n" } else { "\n" };
|
||||
|
||||
let yes = format!("y{}", END_OF_LINE);
|
||||
|
||||
let scene = TestScenario::new(util_name!());
|
||||
let at = &scene.fixtures;
|
||||
|
||||
let empty_file = "empty";
|
||||
|
||||
at.touch(empty_file);
|
||||
|
||||
// This should cause rm to prompt to remove regular empty file
|
||||
let mut child: Child = scene.ucmd().arg("-fi").arg(empty_file).run_no_wait();
|
||||
|
||||
let mut child_stdin = child.stdin.take().unwrap();
|
||||
child_stdin.write_all(yes.as_bytes()).unwrap();
|
||||
child_stdin.flush().unwrap();
|
||||
|
||||
let output = child.wait_with_output().unwrap();
|
||||
let string_output =
|
||||
String::from_utf8(output.stderr).expect("Couldn't convert output.stderr to string");
|
||||
assert!(string_output.trim() == "rm: remove regular empty file 'empty'?");
|
||||
assert!(!at.file_exists(empty_file));
|
||||
|
||||
at.touch(empty_file);
|
||||
|
||||
// This should not cause rm to prompt to remove regular empty file
|
||||
scene
|
||||
.ucmd()
|
||||
.arg("-if")
|
||||
.arg(empty_file)
|
||||
.succeeds()
|
||||
.no_stderr();
|
||||
assert!(!at.file_exists(empty_file));
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore = "issue #3722"]
|
||||
fn test_rm_directory_rights_rm1() {
|
||||
|
|
|
@ -64,9 +64,9 @@ fn test_sync_no_permission_dir() {
|
|||
|
||||
ts.ccmd("chmod").arg("0").arg(dir).succeeds();
|
||||
let result = ts.ucmd().arg("--data").arg(dir).fails();
|
||||
result.stderr_contains("sync: error opening 'foo': Permission denied");
|
||||
result.stderr_contains("sync: cannot stat 'foo': Permission denied");
|
||||
let result = ts.ucmd().arg(dir).fails();
|
||||
result.stderr_contains("sync: error opening 'foo': Permission denied");
|
||||
result.stderr_contains("sync: cannot stat 'foo': Permission denied");
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
|
|
|
@ -58,11 +58,11 @@ impl Distribution<u8> for AlphanumericNewline {
|
|||
/// use rand::distributions::Alphanumeric;
|
||||
///
|
||||
/// // generates a 100 byte string with characters from AlphanumericNewline
|
||||
/// let random_string = RandomString::generate(&AlphanumericNewline, 100);
|
||||
/// let random_string = RandomString::generate(AlphanumericNewline, 100);
|
||||
/// assert_eq!(100, random_string.len());
|
||||
///
|
||||
/// // generates a 100 byte string with 10 newline characters not ending with a newline
|
||||
/// let string = RandomString::generate_with_delimiter(&Alphanumeric, b'\n', 10, false, 100);
|
||||
/// let string = RandomString::generate_with_delimiter(Alphanumeric, b'\n', 10, false, 100);
|
||||
/// assert_eq!(100, random_string.len());
|
||||
/// ```
|
||||
pub struct RandomString;
|
||||
|
@ -108,7 +108,7 @@ impl RandomString {
|
|||
/// use crate::common::random::{AlphanumericNewline, RandomString};
|
||||
///
|
||||
/// // generates a 100 byte string with 10 '\0' byte characters not ending with a '\0' byte
|
||||
/// let string = RandomString::generate_with_delimiter(&AlphanumericNewline, 0, 10, false, 100);
|
||||
/// let string = RandomString::generate_with_delimiter(AlphanumericNewline, 0, 10, false, 100);
|
||||
/// assert_eq!(100, random_string.len());
|
||||
/// assert_eq!(
|
||||
/// 10,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue