mirror of
https://github.com/uutils/coreutils
synced 2024-12-13 14:52:41 +00:00
Merge pull request #4856 from cakebaker/cksum_fix_algorithm_output
cksum: fix output of --algorithm
This commit is contained in:
commit
22a7f98a47
29 changed files with 79 additions and 73 deletions
|
@ -159,8 +159,14 @@ where
|
|||
div_ceil(sz, options.output_bits),
|
||||
filename.display()
|
||||
),
|
||||
(_, true) => println!("{sum} {sz}"),
|
||||
(_, false) => println!("{sum} {sz} {}", filename.display()),
|
||||
(ALGORITHM_OPTIONS_CRC, true) => println!("{sum} {sz}"),
|
||||
(ALGORITHM_OPTIONS_CRC, false) => println!("{sum} {sz} {}", filename.display()),
|
||||
(ALGORITHM_OPTIONS_BLAKE2B, _) => println!("BLAKE2b ({}) = {sum}", filename.display()),
|
||||
_ => println!(
|
||||
"{} ({}) = {sum}",
|
||||
options.algo_name.to_ascii_uppercase(),
|
||||
filename.display()
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
2
tests/fixtures/cksum/blake2b_multiple_files.expected
vendored
Normal file
2
tests/fixtures/cksum/blake2b_multiple_files.expected
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
BLAKE2b (lorem_ipsum.txt) = 0e97a09189e560c3789c0bff1f020166861ef857d1fbfe4574de1842e3c06cabb9575e4af6309a166158c2b408d3c038c1b49d828b35158142cdc0396d1195c3
|
||||
BLAKE2b (alice_in_wonderland.txt) = 91b8b0f0868e905ad18b8ac35e4a1dacd289857b19258ab5d1e071761af758b0134ec152d4f011fe1825ca889c80c2e072ca70eb50548c25fc49a98937515af4
|
1
tests/fixtures/cksum/blake2b_single_file.expected
vendored
Normal file
1
tests/fixtures/cksum/blake2b_single_file.expected
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
BLAKE2b (lorem_ipsum.txt) = 0e97a09189e560c3789c0bff1f020166861ef857d1fbfe4574de1842e3c06cabb9575e4af6309a166158c2b408d3c038c1b49d828b35158142cdc0396d1195c3
|
1
tests/fixtures/cksum/blake2b_stdin.expected
vendored
Normal file
1
tests/fixtures/cksum/blake2b_stdin.expected
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
BLAKE2b (-) = 0e97a09189e560c3789c0bff1f020166861ef857d1fbfe4574de1842e3c06cabb9575e4af6309a166158c2b408d3c038c1b49d828b35158142cdc0396d1195c3
|
2
tests/fixtures/cksum/md5_multiple_files.expected
vendored
Normal file
2
tests/fixtures/cksum/md5_multiple_files.expected
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
MD5 (lorem_ipsum.txt) = cd724690f7dc61775dfac400a71f2caa
|
||||
MD5 (alice_in_wonderland.txt) = f6fa7033e16166a9589aa1c0388ffd58
|
1
tests/fixtures/cksum/md5_single_file.expected
vendored
Normal file
1
tests/fixtures/cksum/md5_single_file.expected
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
MD5 (lorem_ipsum.txt) = cd724690f7dc61775dfac400a71f2caa
|
1
tests/fixtures/cksum/md5_stdin.expected
vendored
Normal file
1
tests/fixtures/cksum/md5_stdin.expected
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
MD5 (-) = cd724690f7dc61775dfac400a71f2caa
|
2
tests/fixtures/cksum/sha1_multiple_files.expected
vendored
Normal file
2
tests/fixtures/cksum/sha1_multiple_files.expected
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
SHA1 (lorem_ipsum.txt) = ab1dd0bae1d8883a3d18a66de6afbd28252cfbef
|
||||
SHA1 (alice_in_wonderland.txt) = 22b54b2520e8b4fa59eb10719028a4e587c12d1e
|
1
tests/fixtures/cksum/sha1_single_file.expected
vendored
Normal file
1
tests/fixtures/cksum/sha1_single_file.expected
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
SHA1 (lorem_ipsum.txt) = ab1dd0bae1d8883a3d18a66de6afbd28252cfbef
|
1
tests/fixtures/cksum/sha1_stdin.expected
vendored
Normal file
1
tests/fixtures/cksum/sha1_stdin.expected
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
SHA1 (-) = ab1dd0bae1d8883a3d18a66de6afbd28252cfbef
|
2
tests/fixtures/cksum/sha224_multiple_files.expected
vendored
Normal file
2
tests/fixtures/cksum/sha224_multiple_files.expected
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
SHA224 (lorem_ipsum.txt) = 3de66fbcad106e1b40ab391be56c51d2007eb1f9c655d0f4e29bfc01
|
||||
SHA224 (alice_in_wonderland.txt) = 54c9c7d78458886418ce0845111fc49fe1c628ffd4bf3da14226ffd9
|
1
tests/fixtures/cksum/sha224_single_file.expected
vendored
Normal file
1
tests/fixtures/cksum/sha224_single_file.expected
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
SHA224 (lorem_ipsum.txt) = 3de66fbcad106e1b40ab391be56c51d2007eb1f9c655d0f4e29bfc01
|
1
tests/fixtures/cksum/sha224_stdin.expected
vendored
Normal file
1
tests/fixtures/cksum/sha224_stdin.expected
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
SHA224 (-) = 3de66fbcad106e1b40ab391be56c51d2007eb1f9c655d0f4e29bfc01
|
2
tests/fixtures/cksum/sha256_multiple_files.expected
vendored
Normal file
2
tests/fixtures/cksum/sha256_multiple_files.expected
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
SHA256 (lorem_ipsum.txt) = f7c420501c50e00b309250100d67ea5e910981536b4582fe9c435bd92b3f1f02
|
||||
SHA256 (alice_in_wonderland.txt) = 14ab7e5a0aa3a670222744714bc96961d51012cb216225d965db71824a46e5fe
|
1
tests/fixtures/cksum/sha256_single_file.expected
vendored
Normal file
1
tests/fixtures/cksum/sha256_single_file.expected
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
SHA256 (lorem_ipsum.txt) = f7c420501c50e00b309250100d67ea5e910981536b4582fe9c435bd92b3f1f02
|
1
tests/fixtures/cksum/sha256_stdin.expected
vendored
Normal file
1
tests/fixtures/cksum/sha256_stdin.expected
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
SHA256 (-) = f7c420501c50e00b309250100d67ea5e910981536b4582fe9c435bd92b3f1f02
|
2
tests/fixtures/cksum/sha384_multiple_files.expected
vendored
Normal file
2
tests/fixtures/cksum/sha384_multiple_files.expected
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
SHA384 (lorem_ipsum.txt) = 4be4b90a0d0d32966992921019f24abc824dcfb8b1c408102f1f6788fb80ba9a9a4c5a7b575a3353a90a8ee719481dcb
|
||||
SHA384 (alice_in_wonderland.txt) = b7966c97ef84ab5858db2e0cdd33fbaf4fa8346d84de65aba001e738c242598a43272854d0073ad1099404eaa1d93766
|
1
tests/fixtures/cksum/sha384_single_file.expected
vendored
Normal file
1
tests/fixtures/cksum/sha384_single_file.expected
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
SHA384 (lorem_ipsum.txt) = 4be4b90a0d0d32966992921019f24abc824dcfb8b1c408102f1f6788fb80ba9a9a4c5a7b575a3353a90a8ee719481dcb
|
1
tests/fixtures/cksum/sha384_stdin.expected
vendored
Normal file
1
tests/fixtures/cksum/sha384_stdin.expected
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
SHA384 (-) = 4be4b90a0d0d32966992921019f24abc824dcfb8b1c408102f1f6788fb80ba9a9a4c5a7b575a3353a90a8ee719481dcb
|
2
tests/fixtures/cksum/sha512_multiple_files.expected
vendored
Normal file
2
tests/fixtures/cksum/sha512_multiple_files.expected
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
SHA512 (lorem_ipsum.txt) = 965464ab2556aad58ebc73d89ad221e559797529ecafc0f466c11795cff6d6e2c60f96a07c542cfd1f426e5e4fe0a48aa15667ba44096b213d0813cd038dfa05
|
||||
SHA512 (alice_in_wonderland.txt) = 251646d5a7eb481e0f3aced7839d78dd5e97153f822dc55938e17059c485990d85d602e2881b528b565ab6262584a69c97b068b26bda81acc9356c53c7c1c96d
|
1
tests/fixtures/cksum/sha512_single_file.expected
vendored
Normal file
1
tests/fixtures/cksum/sha512_single_file.expected
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
SHA512 (lorem_ipsum.txt) = 965464ab2556aad58ebc73d89ad221e559797529ecafc0f466c11795cff6d6e2c60f96a07c542cfd1f426e5e4fe0a48aa15667ba44096b213d0813cd038dfa05
|
1
tests/fixtures/cksum/sha512_stdin.expected
vendored
Normal file
1
tests/fixtures/cksum/sha512_stdin.expected
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
SHA512 (-) = 965464ab2556aad58ebc73d89ad221e559797529ecafc0f466c11795cff6d6e2c60f96a07c542cfd1f426e5e4fe0a48aa15667ba44096b213d0813cd038dfa05
|
2
tests/fixtures/cksum/sm3_multiple_files.expected
vendored
Normal file
2
tests/fixtures/cksum/sm3_multiple_files.expected
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
SM3 (lorem_ipsum.txt) = 6d296b805d060bfed22808df308dbb9b4317794dd4ed6740a10770a782699bc2
|
||||
SM3 (alice_in_wonderland.txt) = d66617ae3c4e87828298dcd836f79efbab488c53b84e09c3e8e83a16c902418d
|
1
tests/fixtures/cksum/sm3_single_file.expected
vendored
Normal file
1
tests/fixtures/cksum/sm3_single_file.expected
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
SM3 (lorem_ipsum.txt) = 6d296b805d060bfed22808df308dbb9b4317794dd4ed6740a10770a782699bc2
|
1
tests/fixtures/cksum/sm3_stdin.expected
vendored
Normal file
1
tests/fixtures/cksum/sm3_stdin.expected
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
SM3 (-) = 6d296b805d060bfed22808df308dbb9b4317794dd4ed6740a10770a782699bc2
|
Loading…
Reference in a new issue