mirror of
https://github.com/uutils/coreutils.git
synced 2025-12-23 08:47:37 +00:00
test(cksum): add tests for --length, refactor tests
This commit is contained in:
parent
a95633e520
commit
69ce42c3cb
2 changed files with 92 additions and 24 deletions
|
|
@ -295,15 +295,79 @@ fn test_untagged_algorithm_stdin() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn test_sha2_wrong_length() {
|
||||
for l in [0, 13, 819_111_123] {
|
||||
fn test_sha_length_invalid() {
|
||||
for algo in ["sha2", "sha3"] {
|
||||
for l in ["0", "00", "13", "56", "99999999999999999999999999"] {
|
||||
new_ucmd!()
|
||||
.arg("--algorithm")
|
||||
.arg(algo)
|
||||
.arg("--length")
|
||||
.arg(l)
|
||||
.arg("/dev/null")
|
||||
.fails_with_code(1)
|
||||
.no_stdout()
|
||||
.stderr_contains(format!("invalid length: '{l}'"))
|
||||
.stderr_contains(format!(
|
||||
"digest length for '{}' must be 224, 256, 384, or 512",
|
||||
algo.to_ascii_uppercase()
|
||||
));
|
||||
|
||||
// Also fails with --check
|
||||
new_ucmd!()
|
||||
.arg("--algorithm")
|
||||
.arg(algo)
|
||||
.arg("--length")
|
||||
.arg(l)
|
||||
.arg("/dev/null")
|
||||
.arg("--check")
|
||||
.fails_with_code(1)
|
||||
.no_stdout()
|
||||
.stderr_contains(format!("invalid length: '{l}'"))
|
||||
.stderr_contains(format!(
|
||||
"digest length for '{}' must be 224, 256, 384, or 512",
|
||||
algo.to_ascii_uppercase()
|
||||
));
|
||||
}
|
||||
|
||||
// Different error for NaNs
|
||||
for l in ["512x", "x512", "512x512"] {
|
||||
new_ucmd!()
|
||||
.arg("--algorithm")
|
||||
.arg(algo)
|
||||
.arg("--length")
|
||||
.arg(l)
|
||||
.arg("/dev/null")
|
||||
.fails_with_code(1)
|
||||
.no_stdout()
|
||||
.stderr_contains(format!("invalid length: '{l}'"));
|
||||
|
||||
// Also fails with --check
|
||||
new_ucmd!()
|
||||
.arg("--algorithm")
|
||||
.arg(algo)
|
||||
.arg("--length")
|
||||
.arg(l)
|
||||
.arg("/dev/null")
|
||||
.arg("--check")
|
||||
.fails_with_code(1)
|
||||
.no_stdout()
|
||||
.stderr_contains(format!("invalid length: '{l}'"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_sha_missing_length() {
|
||||
for algo in ["sha2", "sha3"] {
|
||||
new_ucmd!()
|
||||
.arg("--algorithm=sha2")
|
||||
.arg(format!("--length={l}"))
|
||||
.arg("--algorithm")
|
||||
.arg(algo)
|
||||
.arg("lorem_ipsum.txt")
|
||||
.fails_with_code(1)
|
||||
.no_stdout()
|
||||
.stderr_contains(format!("invalid length: '{l}'"));
|
||||
.stderr_contains(format!(
|
||||
"--algorithm={algo} requires specifying --length 224, 256, 384, or 512"
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -488,19 +552,6 @@ fn test_check_sha2_tagged_variant() {
|
|||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_sha3_wrong_length() {
|
||||
for l in [0, 13, 819_111_123] {
|
||||
new_ucmd!()
|
||||
.arg("--algorithm=sha3")
|
||||
.arg(format!("--length={l}"))
|
||||
.arg("lorem_ipsum.txt")
|
||||
.fails_with_code(1)
|
||||
.no_stdout()
|
||||
.stderr_contains(format!("invalid length: '{l}'"));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_sha3_single_file() {
|
||||
for l in SHA_LENGTHS {
|
||||
|
|
@ -708,7 +759,7 @@ fn test_length_not_supported() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn test_length() {
|
||||
fn test_blake2b_length() {
|
||||
new_ucmd!()
|
||||
.arg("--length=16")
|
||||
.arg("--algorithm=blake2b")
|
||||
|
|
@ -721,7 +772,7 @@ fn test_length() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn test_length_greater_than_512() {
|
||||
fn test_blake2b_length_greater_than_512() {
|
||||
new_ucmd!()
|
||||
.arg("--length=1024")
|
||||
.arg("--algorithm=blake2b")
|
||||
|
|
@ -733,7 +784,7 @@ fn test_length_greater_than_512() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn test_length_is_zero() {
|
||||
fn test_blake2b_length_is_zero() {
|
||||
new_ucmd!()
|
||||
.arg("--length=0")
|
||||
.arg("--algorithm=blake2b")
|
||||
|
|
@ -745,7 +796,7 @@ fn test_length_is_zero() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn test_length_repeated() {
|
||||
fn test_blake2b_length_repeated() {
|
||||
new_ucmd!()
|
||||
.arg("--length=10")
|
||||
.arg("--length=123456")
|
||||
|
|
@ -758,6 +809,23 @@ fn test_length_repeated() {
|
|||
.stdout_is_fixture("length_is_zero.expected");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_blake2b_length_invalid() {
|
||||
for len in [
|
||||
"1", "01", // Odd
|
||||
"",
|
||||
] {
|
||||
new_ucmd!()
|
||||
.arg("--length")
|
||||
.arg(len)
|
||||
.arg("--algorithm=blake2b")
|
||||
.arg("lorem_ipsum.txt")
|
||||
.arg("alice_in_wonderland.txt")
|
||||
.fails_with_code(1)
|
||||
.stderr_contains(format!("invalid length: '{len}'"));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_raw_single_file() {
|
||||
for algo in ALGOS {
|
||||
|
|
|
|||
|
|
@ -1,2 +1,2 @@
|
|||
cksum: invalid length: ‘1024’
|
||||
cksum: maximum digest length for ‘BLAKE2b’ is 512 bits
|
||||
cksum: invalid length: '1024'
|
||||
cksum: maximum digest length for 'BLAKE2b' is 512 bits
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue