1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 11:37:44 +00:00

cksum: fix output of --algorithm

for the algorithms md5, sha[1,224,256,384,512], blake2b, and sm3 from

<digest> <filesize> <filename>

to

<algo name> (<filename>) = <digest>

to use the same format as GNU cksum
This commit is contained in:
Daniel Hofstetter 2023-05-11 08:03:12 +02:00
parent 452be5a220
commit 0781ad0a65
29 changed files with 79 additions and 73 deletions

View file

@ -1,7 +1,11 @@
// spell-checker:ignore (words) asdf
// spell-checker:ignore (words) asdf algo algos
use crate::common::util::TestScenario;
const ALGOS: [&str; 11] = [
"sysv", "bsd", "crc", "md5", "sha1", "sha224", "sha256", "sha384", "sha512", "blake2b", "sm3",
];
#[test]
fn test_invalid_arg() {
new_ucmd!().arg("--definitely-invalid").fails().code_is(1);
@ -12,7 +16,7 @@ fn test_single_file() {
new_ucmd!()
.arg("lorem_ipsum.txt")
.succeeds()
.stdout_is_fixture("single_file.expected");
.stdout_is_fixture("crc_single_file.expected");
}
#[test]
@ -21,7 +25,7 @@ fn test_multiple_files() {
.arg("lorem_ipsum.txt")
.arg("alice_in_wonderland.txt")
.succeeds()
.stdout_is_fixture("multiple_files.expected");
.stdout_is_fixture("crc_multiple_files.expected");
}
#[test]
@ -29,7 +33,7 @@ fn test_stdin() {
new_ucmd!()
.pipe_in_fixture("lorem_ipsum.txt")
.succeeds()
.stdout_is_fixture("stdin.expected");
.stdout_is_fixture("crc_stdin.expected");
}
#[test]
@ -117,77 +121,41 @@ fn test_stdin_larger_than_128_bytes() {
}
#[test]
fn test_sha1_single_file() {
new_ucmd!()
.arg("-a=sha1")
.arg("lorem_ipsum.txt")
.succeeds()
.stdout_is("ab1dd0bae1d8883a3d18a66de6afbd28252cfbef 772 lorem_ipsum.txt\n");
fn test_algorithm_single_file() {
for algo in ALGOS {
for option in ["-a", "--algorithm"] {
new_ucmd!()
.arg(format!("{option}={algo}"))
.arg("lorem_ipsum.txt")
.succeeds()
.stdout_is_fixture(format!("{algo}_single_file.expected"));
}
}
}
#[test]
fn test_sm3_single_file() {
new_ucmd!()
.arg("-a=sm3")
.arg("lorem_ipsum.txt")
.succeeds()
.stdout_is(
"6d296b805d060bfed22808df308dbb9b4317794dd4ed6740a10770a782699bc2 772 lorem_ipsum.txt\n",
);
fn test_algorithm_multiple_files() {
for algo in ALGOS {
for option in ["-a", "--algorithm"] {
new_ucmd!()
.arg(format!("{option}={algo}"))
.arg("lorem_ipsum.txt")
.arg("alice_in_wonderland.txt")
.succeeds()
.stdout_is_fixture(format!("{algo}_multiple_files.expected"));
}
}
}
#[test]
fn test_bsd_single_file() {
new_ucmd!()
.arg("-a=bsd")
.arg("lorem_ipsum.txt")
.succeeds()
.stdout_only_fixture("bsd_single_file.expected");
}
#[test]
fn test_bsd_multiple_files() {
new_ucmd!()
.arg("-a=bsd")
.arg("lorem_ipsum.txt")
.arg("alice_in_wonderland.txt")
.succeeds()
.stdout_only_fixture("bsd_multiple_files.expected");
}
#[test]
fn test_bsd_stdin() {
new_ucmd!()
.arg("-a=bsd")
.pipe_in_fixture("lorem_ipsum.txt")
.succeeds()
.stdout_only_fixture("bsd_stdin.expected");
}
#[test]
fn test_sysv_single_file() {
new_ucmd!()
.arg("-a=sysv")
.arg("lorem_ipsum.txt")
.succeeds()
.stdout_only_fixture("sysv_single_file.expected");
}
#[test]
fn test_sysv_multiple_files() {
new_ucmd!()
.arg("-a=sysv")
.arg("lorem_ipsum.txt")
.arg("alice_in_wonderland.txt")
.succeeds()
.stdout_only_fixture("sysv_multiple_files.expected");
}
#[test]
fn test_sysv_stdin() {
new_ucmd!()
.arg("-a=sysv")
.pipe_in_fixture("lorem_ipsum.txt")
.succeeds()
.stdout_only_fixture("sysv_stdin.expected");
fn test_algorithm_stdin() {
for algo in ALGOS {
for option in ["-a", "--algorithm"] {
new_ucmd!()
.arg(format!("{option}={algo}"))
.pipe_in_fixture("lorem_ipsum.txt")
.succeeds()
.stdout_is_fixture(format!("{algo}_stdin.expected"));
}
}
}