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

Merge branch 'main' into sort-mem-percent

This commit is contained in:
Sylvestre Ledru 2025-01-23 22:52:00 +01:00 committed by GitHub
commit 4f83924092
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
56 changed files with 890 additions and 411 deletions

View file

@ -2,7 +2,7 @@
//
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.
// spell-checker:ignore (words) asdf algo algos asha mgmt xffname hexa GFYEQ HYQK Yqxb
// spell-checker:ignore (words) asdf algo algos asha mgmt xffname hexa GFYEQ HYQK Yqxb dont
use crate::common::util::TestScenario;
@ -1284,6 +1284,18 @@ fn test_several_files_error_mgmt() {
.stderr_contains("incorrect: no properly ");
}
#[test]
fn test_check_unknown_checksum_file() {
let scene = TestScenario::new(util_name!());
scene
.ucmd()
.arg("--check")
.arg("missing")
.fails()
.stderr_only("cksum: missing: No such file or directory\n");
}
#[test]
fn test_check_comment_line() {
// A comment in a checksum file shall be discarded unnoticed.
@ -1811,6 +1823,373 @@ mod gnu_cksum_base64 {
}
}
/// This module reimplements the cksum-c.sh GNU test.
mod gnu_cksum_c {
use super::*;
const INVALID_SUM: &str = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaafdb57c725157cb40b5aee8d937b8351477e";
fn make_scene() -> TestScenario {
let scene = TestScenario::new(util_name!());
let at = &scene.fixtures;
at.write("input", "9\n7\n1\n4\n2\n6\n3\n5\n8\n10\n");
let algos: &[&[&str]] = &[
&["-a", "sha384"],
&["-a", "blake2b"],
&["-a", "blake2b", "-l", "384"],
&["-a", "sm3"],
];
for args in algos {
let result = scene.ucmd().args(args).succeeds();
let stdout = result.stdout();
at.append_bytes("CHECKSUMS", stdout);
}
scene
}
#[test]
#[ignore]
fn test_signed_checksums() {
todo!()
}
#[test]
fn test_check_individual_digests_in_mixed_file() {
let scene = make_scene();
scene
.ucmd()
.arg("--check")
.arg("-a")
.arg("sm3")
.arg("CHECKSUMS")
.succeeds();
}
#[test]
fn test_check_against_older_non_hex_formats() {
let scene = make_scene();
scene
.ucmd()
.arg("-c")
.arg("-a")
.arg("crc")
.arg("CHECKSUMS")
.fails();
let crc_cmd = scene.ucmd().arg("-a").arg("crc").arg("input").succeeds();
let crc_cmd_out = crc_cmd.stdout();
scene.fixtures.write_bytes("CHECKSUMS.crc", crc_cmd_out);
scene.ucmd().arg("-c").arg("CHECKSUMS.crc").fails();
}
#[test]
fn test_status() {
let scene = make_scene();
scene
.ucmd()
.arg("--status")
.arg("--check")
.arg("CHECKSUMS")
.succeeds()
.no_output();
}
fn make_scene_with_comment() -> TestScenario {
let scene = make_scene();
scene
.fixtures
.append("CHECKSUMS", "# Very important comment\n");
scene
}
#[test]
fn test_status_with_comment() {
let scene = make_scene_with_comment();
scene
.ucmd()
.arg("--status")
.arg("--check")
.arg("CHECKSUMS")
.succeeds()
.no_output();
}
fn make_scene_with_invalid_line() -> TestScenario {
let scene = make_scene_with_comment();
scene.fixtures.append("CHECKSUMS", "invalid_line\n");
scene
}
#[test]
fn test_check_strict() {
let scene = make_scene_with_invalid_line();
// without strict, succeeds
scene
.ucmd()
.arg("--check")
.arg("CHECKSUMS")
.succeeds()
.stderr_contains("1 line is improperly formatted");
// with strict, fails
scene
.ucmd()
.arg("--strict")
.arg("--check")
.arg("CHECKSUMS")
.fails()
.stderr_contains("1 line is improperly formatted");
}
fn make_scene_with_two_invalid_lines() -> TestScenario {
let scene = make_scene_with_comment();
scene
.fixtures
.append("CHECKSUMS", "invalid_line\ninvalid_line\n");
scene
}
#[test]
fn test_check_strict_plural_checks() {
let scene = make_scene_with_two_invalid_lines();
scene
.ucmd()
.arg("--strict")
.arg("--check")
.arg("CHECKSUMS")
.fails()
.stderr_contains("2 lines are improperly formatted");
}
fn make_scene_with_incorrect_checksum() -> TestScenario {
let scene = make_scene_with_two_invalid_lines();
scene
.fixtures
.append("CHECKSUMS", &format!("SM3 (input) = {INVALID_SUM}\n"));
scene
}
#[test]
fn test_check_with_incorrect_checksum() {
let scene = make_scene_with_incorrect_checksum();
scene
.ucmd()
.arg("--check")
.arg("CHECKSUMS")
.fails()
.stdout_contains("input: FAILED")
.stderr_contains("1 computed checksum did NOT match");
// also fails with strict
scene
.ucmd()
.arg("--strict")
.arg("--check")
.arg("CHECKSUMS")
.fails()
.stdout_contains("input: FAILED")
.stderr_contains("1 computed checksum did NOT match");
}
#[test]
fn test_status_with_errors() {
let scene = make_scene_with_incorrect_checksum();
scene
.ucmd()
.arg("--status")
.arg("--check")
.arg("CHECKSUMS")
.fails()
.no_output();
}
#[test]
fn test_check_with_non_existing_file() {
let scene = make_scene();
scene
.fixtures
.write("CHECKSUMS2", &format!("SM3 (input2) = {INVALID_SUM}\n"));
scene
.ucmd()
.arg("--check")
.arg("CHECKSUMS2")
.fails()
.stdout_contains("input2: FAILED open or read")
.stderr_contains("1 listed file could not be read");
// also fails with strict
scene
.ucmd()
.arg("--strict")
.arg("--check")
.arg("CHECKSUMS2")
.fails()
.stdout_contains("input2: FAILED open or read")
.stderr_contains("1 listed file could not be read");
}
fn make_scene_with_another_improperly_formatted() -> TestScenario {
let scene = make_scene_with_incorrect_checksum();
scene.fixtures.append(
"CHECKSUMS",
&format!("BLAKE2b (missing-file) = {INVALID_SUM}\n"),
);
scene
}
#[test]
fn test_warn() {
let scene = make_scene_with_another_improperly_formatted();
scene
.ucmd()
.arg("--warn")
.arg("--check")
.arg("CHECKSUMS")
.run()
.stderr_contains("CHECKSUMS: 6: improperly formatted SM3 checksum line")
.stderr_contains("CHECKSUMS: 9: improperly formatted BLAKE2b checksum line");
}
fn make_scene_with_checksum_missing() -> TestScenario {
let scene = make_scene_with_another_improperly_formatted();
scene.fixtures.write(
"CHECKSUMS-missing",
&format!("SM3 (nonexistent) = {INVALID_SUM}\n"),
);
scene
}
#[test]
fn test_ignore_missing() {
let scene = make_scene_with_checksum_missing();
scene
.ucmd()
.arg("--ignore-missing")
.arg("--check")
.arg("CHECKSUMS-missing")
.fails()
.stdout_does_not_contain("nonexistent: No such file or directory")
.stdout_does_not_contain("nonexistent: FAILED open or read")
.stderr_contains("CHECKSUMS-missing: no file was verified");
}
#[test]
fn test_status_and_warn() {
let scene = make_scene_with_checksum_missing();
// --status before --warn
scene
.ucmd()
.arg("--status")
.arg("--warn")
.arg("--check")
.arg("CHECKSUMS")
.fails()
.stderr_contains("CHECKSUMS: 9: improperly formatted BLAKE2b checksum line")
.stderr_contains("WARNING: 3 lines are improperly formatted")
.stderr_contains("WARNING: 1 computed checksum did NOT match");
// --warn before --status (status hides the results)
scene
.ucmd()
.arg("--warn")
.arg("--status")
.arg("--check")
.arg("CHECKSUMS")
.fails()
.stderr_does_not_contain("CHECKSUMS: 9: improperly formatted BLAKE2b checksum line")
.stderr_does_not_contain("WARNING: 3 lines are improperly formatted")
.stderr_does_not_contain("WARNING: 1 computed checksum did NOT match");
}
#[test]
fn test_status_and_ignore_missing() {
let scene = make_scene_with_checksum_missing();
scene
.ucmd()
.arg("--status")
.arg("--ignore-missing")
.arg("--check")
.arg("CHECKSUMS")
.fails()
.no_output();
}
#[test]
fn test_status_warn_and_ignore_missing() {
let scene = make_scene_with_checksum_missing();
scene
.ucmd()
.arg("--status")
.arg("--warn")
.arg("--ignore-missing")
.arg("--check")
.arg("CHECKSUMS-missing")
.fails()
.stderr_contains("CHECKSUMS-missing: no file was verified")
.stdout_does_not_contain("nonexistent: No such file or directory");
}
#[test]
fn test_check_several_files_dont_exist() {
let scene = make_scene();
scene
.ucmd()
.arg("--check")
.arg("non-existing-1")
.arg("non-existing-2")
.fails()
.stderr_contains("non-existing-1: No such file or directory")
.stderr_contains("non-existing-2: No such file or directory");
}
#[test]
fn test_check_several_files_empty() {
let scene = make_scene();
scene.fixtures.touch("empty-1");
scene.fixtures.touch("empty-2");
scene
.ucmd()
.arg("--check")
.arg("empty-1")
.arg("empty-2")
.fails()
.stderr_contains("empty-1: no properly formatted checksum lines found")
.stderr_contains("empty-2: no properly formatted checksum lines found");
}
}
/// The tests in this module check the behavior of cksum when given different
/// checksum formats and algorithms in the same file, while specifying an
/// algorithm on CLI or not.

View file

@ -950,7 +950,7 @@ mod tests_split_iterator {
| '*' | '?' | '[' | '#' | '˜' | '=' | '%' => {
special = true;
}
_ => continue,
_ => (),
}
}

View file

@ -63,7 +63,7 @@ fn test_kill_list_all_signals() {
.stdout_contains("KILL")
.stdout_contains("TERM")
.stdout_contains("HUP")
.stdout_does_not_contain("EXIT");
.stdout_contains("EXIT");
}
#[test]
@ -80,15 +80,16 @@ fn test_kill_list_all_signals_as_table() {
.succeeds()
.stdout_contains("KILL")
.stdout_contains("TERM")
.stdout_contains("HUP");
.stdout_contains("HUP")
.stdout_contains("EXIT");
}
#[test]
fn test_kill_table_starts_at_1() {
fn test_kill_table_starts_at_0() {
new_ucmd!()
.arg("-t")
.succeeds()
.stdout_matches(&Regex::new("^\\s?1\\sHUP").unwrap());
.stdout_matches(&Regex::new("^\\s?0\\sEXIT").unwrap());
}
#[test]
@ -104,6 +105,7 @@ fn test_kill_table_lists_all_vertically() {
assert!(signals.contains(&"KILL"));
assert!(signals.contains(&"TERM"));
assert!(signals.contains(&"HUP"));
assert!(signals.contains(&"EXIT"));
}
#[test]
@ -143,6 +145,7 @@ fn test_kill_list_all_vertically() {
assert!(signals.contains(&"KILL"));
assert!(signals.contains(&"TERM"));
assert!(signals.contains(&"HUP"));
assert!(signals.contains(&"EXIT"));
}
#[test]

View file

@ -1315,3 +1315,30 @@ fn test_same_sort_mode_twice() {
fn test_args_override() {
new_ucmd!().args(&["-f", "-f"]).pipe_in("foo").succeeds();
}
#[test]
fn test_k_overflow() {
let input = "2\n1\n";
let output = "1\n2\n";
new_ucmd!()
.args(&["-k", "18446744073709551616"])
.pipe_in(input)
.succeeds()
.stdout_is(output);
}
#[test]
fn test_human_blocks_r_and_q() {
let input = "1Q\n1R\n";
let output = "1R\n1Q\n";
new_ucmd!()
.args(&["-h"])
.pipe_in(input)
.succeeds()
.stdout_is(output);
}
#[test]
fn test_args_check_conflict() {
new_ucmd!().arg("-c").arg("-C").fails();
}

View file

@ -65,13 +65,11 @@ fn test_zero_timeout() {
new_ucmd!()
.args(&["-v", "0", "sleep", ".1"])
.succeeds()
.no_stderr()
.no_stdout();
.no_output();
new_ucmd!()
.args(&["-v", "0", "-s0", "-k0", "sleep", ".1"])
.succeeds()
.no_stderr()
.no_stdout();
.no_output();
}
#[test]
@ -82,15 +80,27 @@ fn test_command_empty_args() {
.stderr_contains("timeout: empty string");
}
#[test]
fn test_foreground() {
for arg in ["-f", "--foreground"] {
new_ucmd!()
.args(&[arg, ".1", "sleep", "10"])
.fails()
.code_is(124)
.no_output();
}
}
#[test]
fn test_preserve_status() {
new_ucmd!()
.args(&["--preserve-status", ".1", "sleep", "10"])
.fails()
// 128 + SIGTERM = 128 + 15
.code_is(128 + 15)
.no_stderr()
.no_stdout();
for arg in ["-p", "--preserve-status"] {
new_ucmd!()
.args(&[arg, ".1", "sleep", "10"])
.fails()
// 128 + SIGTERM = 128 + 15
.code_is(128 + 15)
.no_output();
}
}
#[test]
@ -102,8 +112,7 @@ fn test_preserve_status_even_when_send_signal() {
.args(&["-s", cont_spelling, "--preserve-status", ".1", "sleep", "2"])
.succeeds()
.code_is(0)
.no_stderr()
.no_stdout();
.no_output();
}
}
@ -113,14 +122,12 @@ fn test_dont_overflow() {
.args(&["9223372036854775808d", "sleep", "0"])
.succeeds()
.code_is(0)
.no_stderr()
.no_stdout();
.no_output();
new_ucmd!()
.args(&["-k", "9223372036854775808d", "10", "sleep", "0"])
.succeeds()
.code_is(0)
.no_stderr()
.no_stdout();
.no_output();
}
#[test]
@ -153,8 +160,7 @@ fn test_kill_after_long() {
new_ucmd!()
.args(&["--kill-after=1", "1", "sleep", "0"])
.succeeds()
.no_stdout()
.no_stderr();
.no_output();
}
#[test]