mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-09-15 11:36:16 +00:00
Merge branch 'main' into ls_LZ
This commit is contained in:
commit
873c6c36f7
42 changed files with 509 additions and 303 deletions
|
@ -2724,7 +2724,7 @@ fn test_copy_dir_preserve_permissions_inaccessible_file() {
|
|||
ucmd.args(&["-p", "-R", "d1", "d2"])
|
||||
.fails()
|
||||
.code_is(1)
|
||||
.stderr_only("cp: cannot open 'd1/f' for reading: Permission denied\n");
|
||||
.stderr_only("cp: cannot open 'd1/f' for reading: permission denied\n");
|
||||
assert!(at.dir_exists("d2"));
|
||||
assert!(!at.file_exists("d2/f"));
|
||||
|
||||
|
|
|
@ -580,97 +580,58 @@ fn test_du_invalid_threshold() {
|
|||
|
||||
#[test]
|
||||
fn test_du_apparent_size() {
|
||||
let ts = TestScenario::new(util_name!());
|
||||
let result = ts.ucmd().arg("--apparent-size").succeeds();
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
at.mkdir_all("a/b");
|
||||
|
||||
at.write("a/b/file1", "foo");
|
||||
at.write("a/b/file2", "foobar");
|
||||
|
||||
let result = ucmd.args(&["--apparent-size", "--all", "a"]).succeeds();
|
||||
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
{
|
||||
let result_reference = unwrap_or_return!(expected_result(&ts, &["--apparent-size"]));
|
||||
assert_eq!(result.stdout_str(), result_reference.stdout_str());
|
||||
result.stdout_contains_line("1\ta/b/file2");
|
||||
result.stdout_contains_line("1\ta/b/file1");
|
||||
result.stdout_contains_line("1\ta/b");
|
||||
result.stdout_contains_line("1\ta");
|
||||
}
|
||||
|
||||
#[cfg(not(any(target_os = "linux", target_os = "android")))]
|
||||
_du_apparent_size(result.stdout_str());
|
||||
}
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
fn _du_apparent_size(s: &str) {
|
||||
assert_eq!(
|
||||
s,
|
||||
"1\t.\\subdir\\deeper\\deeper_dir
|
||||
1\t.\\subdir\\deeper
|
||||
6\t.\\subdir\\links
|
||||
6\t.\\subdir
|
||||
6\t.
|
||||
"
|
||||
);
|
||||
}
|
||||
#[cfg(target_vendor = "apple")]
|
||||
fn _du_apparent_size(s: &str) {
|
||||
assert_eq!(
|
||||
s,
|
||||
"1\t./subdir/deeper/deeper_dir
|
||||
1\t./subdir/deeper
|
||||
6\t./subdir/links
|
||||
6\t./subdir
|
||||
6\t.
|
||||
"
|
||||
);
|
||||
}
|
||||
#[cfg(target_os = "freebsd")]
|
||||
fn _du_apparent_size(s: &str) {
|
||||
assert_eq!(
|
||||
s,
|
||||
"1\t./subdir/deeper/deeper_dir
|
||||
2\t./subdir/deeper
|
||||
6\t./subdir/links
|
||||
8\t./subdir
|
||||
8\t.
|
||||
"
|
||||
);
|
||||
}
|
||||
#[cfg(all(
|
||||
not(target_vendor = "apple"),
|
||||
not(target_os = "windows"),
|
||||
not(target_os = "freebsd")
|
||||
))]
|
||||
fn _du_apparent_size(s: &str) {
|
||||
assert_eq!(
|
||||
s,
|
||||
"5\t./subdir/deeper/deeper_dir
|
||||
9\t./subdir/deeper
|
||||
10\t./subdir/links
|
||||
22\t./subdir
|
||||
26\t.
|
||||
"
|
||||
);
|
||||
#[cfg(target_os = "windows")]
|
||||
{
|
||||
result.stdout_contains_line("1\ta\\b\\file2");
|
||||
result.stdout_contains_line("1\ta\\b\\file1");
|
||||
result.stdout_contains_line("1\ta\\b");
|
||||
result.stdout_contains_line("1\ta");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_du_bytes() {
|
||||
let ts = TestScenario::new(util_name!());
|
||||
let result = ts.ucmd().arg("--bytes").succeeds();
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
at.mkdir_all("a/b");
|
||||
|
||||
at.write("a/b/file1", "foo");
|
||||
at.write("a/b/file2", "foobar");
|
||||
|
||||
let result = ucmd.args(&["--bytes", "--all", "a"]).succeeds();
|
||||
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
{
|
||||
let result_reference = unwrap_or_return!(expected_result(&ts, &["--bytes"]));
|
||||
assert_eq!(result.stdout_str(), result_reference.stdout_str());
|
||||
result.stdout_contains_line("6\ta/b/file2");
|
||||
result.stdout_contains_line("3\ta/b/file1");
|
||||
result.stdout_contains_line("9\ta/b");
|
||||
result.stdout_contains_line("9\ta");
|
||||
}
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
result.stdout_contains("5145\t.\\subdir\n");
|
||||
#[cfg(target_vendor = "apple")]
|
||||
result.stdout_contains("5625\t./subdir\n");
|
||||
#[cfg(target_os = "freebsd")]
|
||||
result.stdout_contains("7193\t./subdir\n");
|
||||
#[cfg(all(
|
||||
not(target_vendor = "apple"),
|
||||
not(target_os = "windows"),
|
||||
not(target_os = "freebsd"),
|
||||
not(target_os = "linux"),
|
||||
not(target_os = "android"),
|
||||
))]
|
||||
result.stdout_contains("21529\t./subdir\n");
|
||||
{
|
||||
result.stdout_contains_line("6\ta\\b\\file2");
|
||||
result.stdout_contains_line("3\ta\\b\\file1");
|
||||
result.stdout_contains_line("9\ta\\b");
|
||||
result.stdout_contains_line("9\ta");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -417,6 +417,83 @@ fn test_mv_same_hardlink() {
|
|||
.stderr_is(format!("mv: '{file_a}' and '{file_b}' are the same file\n",));
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(all(unix, not(target_os = "android")))]
|
||||
fn test_mv_same_symlink() {
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
let file_a = "test_mv_same_file_a";
|
||||
let file_b = "test_mv_same_file_b";
|
||||
let file_c = "test_mv_same_file_c";
|
||||
|
||||
at.touch(file_a);
|
||||
|
||||
at.symlink_file(file_a, file_b);
|
||||
|
||||
ucmd.arg(file_b)
|
||||
.arg(file_a)
|
||||
.fails()
|
||||
.stderr_is(format!("mv: '{file_b}' and '{file_a}' are the same file\n",));
|
||||
|
||||
let (at2, mut ucmd2) = at_and_ucmd!();
|
||||
at2.touch(file_a);
|
||||
|
||||
at2.symlink_file(file_a, file_b);
|
||||
ucmd2.arg(file_a).arg(file_b).succeeds();
|
||||
assert!(at2.file_exists(file_b));
|
||||
assert!(!at2.file_exists(file_a));
|
||||
|
||||
let (at3, mut ucmd3) = at_and_ucmd!();
|
||||
at3.touch(file_a);
|
||||
|
||||
at3.symlink_file(file_a, file_b);
|
||||
at3.symlink_file(file_b, file_c);
|
||||
|
||||
ucmd3.arg(file_c).arg(file_b).succeeds();
|
||||
assert!(!at3.symlink_exists(file_c));
|
||||
assert!(at3.symlink_exists(file_b));
|
||||
|
||||
let (at4, mut ucmd4) = at_and_ucmd!();
|
||||
at4.touch(file_a);
|
||||
|
||||
at4.symlink_file(file_a, file_b);
|
||||
at4.symlink_file(file_b, file_c);
|
||||
|
||||
ucmd4
|
||||
.arg(file_c)
|
||||
.arg(file_a)
|
||||
.fails()
|
||||
.stderr_is(format!("mv: '{file_c}' and '{file_a}' are the same file\n",));
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(all(unix, not(target_os = "android")))]
|
||||
fn test_mv_hardlink_to_symlink() {
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
let file = "file";
|
||||
let symlink_file = "symlink";
|
||||
let hardlink_to_symlink_file = "hardlink_to_symlink";
|
||||
|
||||
at.touch(file);
|
||||
at.symlink_file(file, symlink_file);
|
||||
at.hard_link(symlink_file, hardlink_to_symlink_file);
|
||||
|
||||
ucmd.arg(symlink_file).arg(hardlink_to_symlink_file).fails();
|
||||
|
||||
let (at2, mut ucmd2) = at_and_ucmd!();
|
||||
|
||||
at2.touch(file);
|
||||
at2.symlink_file(file, symlink_file);
|
||||
at2.hard_link(symlink_file, hardlink_to_symlink_file);
|
||||
|
||||
ucmd2
|
||||
.arg("--backup")
|
||||
.arg(symlink_file)
|
||||
.arg(hardlink_to_symlink_file)
|
||||
.succeeds();
|
||||
assert!(!at2.symlink_exists(symlink_file));
|
||||
assert!(at2.symlink_exists(&format!("{hardlink_to_symlink_file}~")));
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(all(unix, not(target_os = "android")))]
|
||||
fn test_mv_same_hardlink_backup_simple() {
|
||||
|
|
|
@ -627,6 +627,35 @@ fn test_skip_bytes() {
|
|||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_skip_bytes_hex() {
|
||||
let input = "abcdefghijklmnopq"; // spell-checker:disable-line
|
||||
new_ucmd!()
|
||||
.arg("-c")
|
||||
.arg("--skip-bytes=0xB")
|
||||
.run_piped_stdin(input.as_bytes())
|
||||
.no_stderr()
|
||||
.success()
|
||||
.stdout_is(unindent(
|
||||
"
|
||||
0000013 l m n o p q
|
||||
0000021
|
||||
",
|
||||
));
|
||||
new_ucmd!()
|
||||
.arg("-c")
|
||||
.arg("--skip-bytes=0xE")
|
||||
.run_piped_stdin(input.as_bytes())
|
||||
.no_stderr()
|
||||
.success()
|
||||
.stdout_is(unindent(
|
||||
"
|
||||
0000016 o p q
|
||||
0000021
|
||||
",
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_skip_bytes_error() {
|
||||
let input = "12345";
|
||||
|
|
|
@ -18,7 +18,7 @@ fn test_shred_remove() {
|
|||
at.touch(file_b);
|
||||
|
||||
// Shred file_a.
|
||||
scene.ucmd().arg("-u").arg(file_a).run();
|
||||
scene.ucmd().arg("-u").arg(file_a).succeeds();
|
||||
|
||||
// file_a was deleted, file_b exists.
|
||||
assert!(!at.file_exists(file_a));
|
||||
|
|
|
@ -41,7 +41,7 @@ fn test_sync_no_existing_files() {
|
|||
.arg("--data")
|
||||
.arg("do-no-exist")
|
||||
.fails()
|
||||
.stderr_contains("cannot stat");
|
||||
.stderr_contains("error opening");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -63,9 +63,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: cannot stat 'foo': Permission denied");
|
||||
result.stderr_contains("sync: error opening 'foo': Permission denied");
|
||||
let result = ts.ucmd().arg(dir).fails();
|
||||
result.stderr_contains("sync: cannot stat 'foo': Permission denied");
|
||||
result.stderr_contains("sync: error opening 'foo': Permission denied");
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
|
|
|
@ -35,6 +35,11 @@ fn test_invalid_arg() {
|
|||
new_ucmd!().arg("--definitely-invalid").fails().code_is(1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_version() {
|
||||
new_ucmd!().arg("--version").succeeds();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_simple() {
|
||||
run(NO_ARGS, b"y\ny\ny\ny\n");
|
||||
|
|
|
@ -659,6 +659,17 @@ impl CmdResult {
|
|||
self
|
||||
}
|
||||
|
||||
#[track_caller]
|
||||
pub fn stdout_contains_line<T: AsRef<str>>(&self, cmp: T) -> &Self {
|
||||
assert!(
|
||||
self.stdout_str().lines().any(|line| line == cmp.as_ref()),
|
||||
"'{}' does not contain line '{}'",
|
||||
self.stdout_str(),
|
||||
cmp.as_ref()
|
||||
);
|
||||
self
|
||||
}
|
||||
|
||||
#[track_caller]
|
||||
pub fn stderr_contains<T: AsRef<str>>(&self, cmp: T) -> &Self {
|
||||
assert!(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue