mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-09-15 03:26:18 +00:00
Merge branch 'main' into fix-printf-hex-alternate-zero
This commit is contained in:
commit
4557821adf
34 changed files with 401 additions and 103 deletions
|
@ -81,15 +81,19 @@ fn test_nonexisting_file() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn test_folder() {
|
||||
fn test_one_nonexisting_file() {
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
|
||||
let folder_name = "a_folder";
|
||||
at.mkdir(folder_name);
|
||||
at.touch("abc.txt");
|
||||
at.touch("xyz.txt");
|
||||
|
||||
ucmd.arg(folder_name)
|
||||
.succeeds()
|
||||
.stdout_only(format!("4294967295 0 {folder_name}\n"));
|
||||
ucmd.arg("abc.txt")
|
||||
.arg("asdf.txt")
|
||||
.arg("xyz.txt")
|
||||
.fails()
|
||||
.stdout_contains_line("4294967295 0 xyz.txt")
|
||||
.stderr_contains("asdf.txt: No such file or directory")
|
||||
.stdout_contains_line("4294967295 0 abc.txt");
|
||||
}
|
||||
|
||||
// Make sure crc is correct for files larger than 32 bytes
|
||||
|
@ -288,15 +292,76 @@ fn test_length_is_zero() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn test_blake2b_fail_on_directory() {
|
||||
fn test_raw_single_file() {
|
||||
for algo in ALGOS {
|
||||
new_ucmd!()
|
||||
.arg("--raw")
|
||||
.arg("lorem_ipsum.txt")
|
||||
.arg(format!("--algorithm={algo}"))
|
||||
.succeeds()
|
||||
.no_stderr()
|
||||
.stdout_is_fixture_bytes(format!("raw/{algo}_single_file.expected"));
|
||||
}
|
||||
}
|
||||
#[test]
|
||||
fn test_raw_multiple_files() {
|
||||
new_ucmd!()
|
||||
.arg("--raw")
|
||||
.arg("lorem_ipsum.txt")
|
||||
.arg("alice_in_wonderland.txt")
|
||||
.fails()
|
||||
.no_stdout()
|
||||
.stderr_contains("cksum: the --raw option is not supported with multiple files")
|
||||
.code_is(1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_fail_on_folder() {
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
|
||||
let folder_name = "a_folder";
|
||||
at.mkdir(folder_name);
|
||||
|
||||
ucmd.arg("--algorithm=blake2b")
|
||||
.arg(folder_name)
|
||||
ucmd.arg(folder_name)
|
||||
.fails()
|
||||
.no_stdout()
|
||||
.stderr_contains(format!("cksum: {folder_name}: Is a directory"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_all_algorithms_fail_on_folder() {
|
||||
let scene = TestScenario::new(util_name!());
|
||||
|
||||
let at = &scene.fixtures;
|
||||
|
||||
let folder_name = "a_folder";
|
||||
at.mkdir(folder_name);
|
||||
|
||||
for algo in ALGOS {
|
||||
scene
|
||||
.ucmd()
|
||||
.arg(format!("--algorithm={algo}"))
|
||||
.arg(folder_name)
|
||||
.fails()
|
||||
.no_stdout()
|
||||
.stderr_contains(format!("cksum: {folder_name}: Is a directory"));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_folder_and_file() {
|
||||
let scene = TestScenario::new(util_name!());
|
||||
|
||||
let at = &scene.fixtures;
|
||||
|
||||
let folder_name = "a_folder";
|
||||
at.mkdir(folder_name);
|
||||
|
||||
scene
|
||||
.ucmd()
|
||||
.arg(folder_name)
|
||||
.arg("lorem_ipsum.txt")
|
||||
.fails()
|
||||
.stderr_contains(format!("cksum: {folder_name}: Is a directory"))
|
||||
.stdout_is_fixture("crc_single_file.expected");
|
||||
}
|
||||
|
|
|
@ -566,6 +566,22 @@ fn test_cp_arg_link_with_dest_hardlink_to_source() {
|
|||
assert!(at.file_exists(hardlink));
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(target_os = "linux")]
|
||||
fn test_cp_arg_link_with_same_file() {
|
||||
use std::os::linux::fs::MetadataExt;
|
||||
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
let file = "file";
|
||||
|
||||
at.touch(file);
|
||||
|
||||
ucmd.args(&["--link", file, file]).succeeds();
|
||||
|
||||
assert_eq!(at.metadata(file).st_nlink(), 1);
|
||||
assert!(at.file_exists(file));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_cp_arg_symlink() {
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
|
@ -715,6 +731,25 @@ fn test_cp_arg_backup_with_dest_a_symlink() {
|
|||
assert_eq!(original, at.resolve_link(backup));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_cp_arg_backup_with_dest_a_symlink_to_source() {
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
let source = "source";
|
||||
let source_content = "content";
|
||||
let symlink = "symlink";
|
||||
let backup = "symlink~";
|
||||
|
||||
at.write(source, source_content);
|
||||
at.symlink_file(source, symlink);
|
||||
|
||||
ucmd.arg("-b").arg(source).arg(symlink).succeeds();
|
||||
|
||||
assert!(!at.symlink_exists(symlink));
|
||||
assert_eq!(source_content, at.read(symlink));
|
||||
assert!(at.symlink_exists(backup));
|
||||
assert_eq!(source, at.resolve_link(backup));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_cp_arg_backup_with_other_args() {
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
|
|
|
@ -255,3 +255,13 @@ fn test_equal_as_delimiter3() {
|
|||
.succeeds()
|
||||
.stdout_only_bytes("abZcd\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_multiple() {
|
||||
let result = new_ucmd!()
|
||||
.args(&["-f2", "-d:", "-d="])
|
||||
.pipe_in("a=b\n")
|
||||
.succeeds();
|
||||
assert_eq!(result.stdout_str(), "b\n");
|
||||
assert_eq!(result.stderr_str(), "");
|
||||
}
|
||||
|
|
|
@ -391,7 +391,7 @@ fn test_read_backwards_bytes_proc_fs_version() {
|
|||
|
||||
let args = ["-c", "-1", "/proc/version"];
|
||||
let result = ts.ucmd().args(&args).succeeds();
|
||||
assert!(result.stdout().len() > 0);
|
||||
assert!(!result.stdout().is_empty());
|
||||
}
|
||||
|
||||
#[cfg(all(
|
||||
|
@ -406,7 +406,7 @@ fn test_read_backwards_bytes_proc_fs_modules() {
|
|||
|
||||
let args = ["-c", "-1", "/proc/modules"];
|
||||
let result = ts.ucmd().args(&args).succeeds();
|
||||
assert!(result.stdout().len() > 0);
|
||||
assert!(!result.stdout().is_empty());
|
||||
}
|
||||
|
||||
#[cfg(all(
|
||||
|
@ -421,7 +421,7 @@ fn test_read_backwards_lines_proc_fs_modules() {
|
|||
|
||||
let args = ["--lines", "-1", "/proc/modules"];
|
||||
let result = ts.ucmd().args(&args).succeeds();
|
||||
assert!(result.stdout().len() > 0);
|
||||
assert!(!result.stdout().is_empty());
|
||||
}
|
||||
|
||||
#[cfg(all(
|
||||
|
|
|
@ -4293,3 +4293,39 @@ fn test_term_colorterm() {
|
|||
"exe"
|
||||
);
|
||||
}
|
||||
|
||||
#[cfg(all(unix, not(target_os = "macos")))]
|
||||
#[test]
|
||||
fn test_acl_display() {
|
||||
use std::process::Command;
|
||||
|
||||
let scene = TestScenario::new(util_name!());
|
||||
let at = &scene.fixtures;
|
||||
let path = "a42";
|
||||
at.mkdir(path);
|
||||
|
||||
let path = at.plus_as_string(path);
|
||||
// calling the command directly. xattr requires some dev packages to be installed
|
||||
// and it adds a complex dependency just for a test
|
||||
match Command::new("setfacl")
|
||||
.args(["-d", "-m", "group::rwx", &path])
|
||||
.status()
|
||||
.map(|status| status.code())
|
||||
{
|
||||
Ok(Some(0)) => {}
|
||||
Ok(_) => {
|
||||
println!("test skipped: setfacl failed");
|
||||
return;
|
||||
}
|
||||
Err(e) => {
|
||||
println!("test skipped: setfacl failed with {}", e);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
scene
|
||||
.ucmd()
|
||||
.args(&["-lda", &path])
|
||||
.succeeds()
|
||||
.stdout_contains("+");
|
||||
}
|
||||
|
|
|
@ -634,3 +634,20 @@ fn test_empty_section_delimiter() {
|
|||
.stdout_is(" 1\ta\n \n 2\tb\n");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_directory_as_input() {
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
let dir = "dir";
|
||||
let file = "file";
|
||||
let content = "aaa";
|
||||
|
||||
at.mkdir(dir);
|
||||
at.write(file, content);
|
||||
|
||||
ucmd.arg(dir)
|
||||
.arg(file)
|
||||
.fails()
|
||||
.stderr_is(format!("nl: {dir}: Is a directory\n"))
|
||||
.stdout_contains(content);
|
||||
}
|
||||
|
|
|
@ -4,6 +4,14 @@
|
|||
// file that was distributed with this source code.
|
||||
use crate::common::util::TestScenario;
|
||||
|
||||
#[test]
|
||||
fn test_no_args() {
|
||||
new_ucmd!()
|
||||
.fails()
|
||||
.no_stdout()
|
||||
.stderr_contains("pathchk: missing operand");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_invalid_arg() {
|
||||
new_ucmd!().arg("--definitely-invalid").fails().code_is(1);
|
||||
|
@ -11,8 +19,6 @@ fn test_invalid_arg() {
|
|||
|
||||
#[test]
|
||||
fn test_default_mode() {
|
||||
// test the default mode
|
||||
|
||||
// accept some reasonable default
|
||||
new_ucmd!().args(&["dir/file"]).succeeds().no_stdout();
|
||||
|
||||
|
@ -48,8 +54,6 @@ fn test_default_mode() {
|
|||
|
||||
#[test]
|
||||
fn test_posix_mode() {
|
||||
// test the posix mode
|
||||
|
||||
// accept some reasonable default
|
||||
new_ucmd!().args(&["-p", "dir/file"]).succeeds().no_stdout();
|
||||
|
||||
|
@ -74,8 +78,6 @@ fn test_posix_mode() {
|
|||
|
||||
#[test]
|
||||
fn test_posix_special() {
|
||||
// test the posix special mode
|
||||
|
||||
// accept some reasonable default
|
||||
new_ucmd!().args(&["-P", "dir/file"]).succeeds().no_stdout();
|
||||
|
||||
|
@ -115,8 +117,6 @@ fn test_posix_special() {
|
|||
|
||||
#[test]
|
||||
fn test_posix_all() {
|
||||
// test the posix special mode
|
||||
|
||||
// accept some reasonable default
|
||||
new_ucmd!()
|
||||
.args(&["-p", "-P", "dir/file"])
|
||||
|
@ -164,10 +164,3 @@ fn test_posix_all() {
|
|||
// fail on empty path
|
||||
new_ucmd!().args(&["-p", "-P", ""]).fails().no_stdout();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_args_parsing() {
|
||||
// fail on no args
|
||||
let empty_args: [String; 0] = [];
|
||||
new_ucmd!().args(&empty_args).fails().no_stdout();
|
||||
}
|
||||
|
|
|
@ -36,6 +36,11 @@ fn escaped_slash() {
|
|||
.stdout_only("hello\\ world");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unescaped_double_quote() {
|
||||
new_ucmd!().args(&["\\\""]).succeeds().stdout_only("\"");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn escaped_hex() {
|
||||
new_ucmd!().args(&["\\x41"]).succeeds().stdout_only("A");
|
||||
|
@ -665,3 +670,13 @@ fn sub_alternative_upper_hex() {
|
|||
.succeeds()
|
||||
.stdout_only("0x2A");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn char_as_byte() {
|
||||
new_ucmd!().args(&["%c", "🙃"]).succeeds().stdout_only("ð");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn no_infinite_loop() {
|
||||
new_ucmd!().args(&["a", "b"]).succeeds().stdout_only("a");
|
||||
}
|
||||
|
|
1
tests/fixtures/cksum/raw/blake2b_single_file.expected
vendored
Normal file
1
tests/fixtures/cksum/raw/blake2b_single_file.expected
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
— ‘‰å`Ãxœÿf†øWÑûþEtÞBãÀl«¹W^Jö0šaX´ÓÀ8Á´<C381>‚‹5<15>BÍÀ9m•Ã
|
1
tests/fixtures/cksum/raw/bsd_single_file.expected
vendored
Normal file
1
tests/fixtures/cksum/raw/bsd_single_file.expected
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
<1F>
|
1
tests/fixtures/cksum/raw/crc_single_file.expected
vendored
Normal file
1
tests/fixtures/cksum/raw/crc_single_file.expected
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
訓h
|
BIN
tests/fixtures/cksum/raw/md5_single_file.expected
vendored
Normal file
BIN
tests/fixtures/cksum/raw/md5_single_file.expected
vendored
Normal file
Binary file not shown.
1
tests/fixtures/cksum/raw/sha1_single_file.expected
vendored
Normal file
1
tests/fixtures/cksum/raw/sha1_single_file.expected
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
<EFBFBD>к<>؈:=<18>m毽(%,<2C><>
|
BIN
tests/fixtures/cksum/raw/sha224_single_file.expected
vendored
Normal file
BIN
tests/fixtures/cksum/raw/sha224_single_file.expected
vendored
Normal file
Binary file not shown.
1
tests/fixtures/cksum/raw/sha256_single_file.expected
vendored
Normal file
1
tests/fixtures/cksum/raw/sha256_single_file.expected
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
÷Ä PPà0’P
gê^‘ <09>SkE‚þœC[Ù+?
|
3
tests/fixtures/cksum/raw/sha384_single_file.expected
vendored
Normal file
3
tests/fixtures/cksum/raw/sha384_single_file.expected
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
K荵
|
||||
2吠鋳<19>シ<EFBFBD>マクアト/g胤コ囹LZ{WZ3Sゥ
|
||||
守Hヒ
|
1
tests/fixtures/cksum/raw/sha512_single_file.expected
vendored
Normal file
1
tests/fixtures/cksum/raw/sha512_single_file.expected
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
–Td«%VªÕ޼sØšÒ!åYyu)ì¯ÀôfÁ•ÏöÖâÆ– |T,ýBn^Oऊ¡VgºD k!=Í<03>ú
|
1
tests/fixtures/cksum/raw/sm3_single_file.expected
vendored
Normal file
1
tests/fixtures/cksum/raw/sm3_single_file.expected
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
m)k€]þÒ(ß0<C39F>»›CyMÔíg@¡p§‚i›Â
|
1
tests/fixtures/cksum/raw/sysv_single_file.expected
vendored
Normal file
1
tests/fixtures/cksum/raw/sysv_single_file.expected
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
I
|
Loading…
Add table
Add a link
Reference in a new issue