Skip to content

Commit 700d045

Browse files
committed
test(cksum): Add sha3 tests
1 parent 594a60e commit 700d045

25 files changed

+172
-0
lines changed

tests/by-util/test_cksum.rs

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,146 @@ fn test_check_untagged_sha2_multiple_files() {
433433
}
434434
}
435435

436+
#[test]
437+
fn test_sha3_wrong_length() {
438+
for l in [0, 13, 819_111_123] {
439+
new_ucmd!()
440+
.arg("--algorithm=sha3")
441+
.arg(format!("--length={l}"))
442+
.arg("lorem_ipsum.txt")
443+
.fails_with_code(1)
444+
.no_stdout()
445+
.stderr_contains(format!("invalid length: '{l}'"));
446+
}
447+
}
448+
449+
#[test]
450+
fn test_sha3_single_file() {
451+
for l in SHA_LENGTHS {
452+
new_ucmd!()
453+
.arg("--algorithm=sha3")
454+
.arg(format!("--length={l}"))
455+
.arg("lorem_ipsum.txt")
456+
.succeeds()
457+
.stdout_is_fixture(format!("sha3_{l}_single_file.expected"));
458+
}
459+
}
460+
461+
#[test]
462+
fn test_sha3_multiple_files() {
463+
for l in SHA_LENGTHS {
464+
new_ucmd!()
465+
.arg("--algorithm=sha3")
466+
.arg(format!("--length={l}"))
467+
.arg("lorem_ipsum.txt")
468+
.arg("alice_in_wonderland.txt")
469+
.succeeds()
470+
.stdout_is_fixture(format!("sha3_{l}_multiple_files.expected"));
471+
}
472+
}
473+
474+
#[test]
475+
fn test_sha3_stdin() {
476+
for l in SHA_LENGTHS {
477+
new_ucmd!()
478+
.arg("--algorithm=sha3")
479+
.arg(format!("--length={l}"))
480+
.pipe_in_fixture("lorem_ipsum.txt")
481+
.succeeds()
482+
.stdout_is_fixture(format!("sha3_{l}_stdin.expected"));
483+
}
484+
}
485+
486+
#[test]
487+
fn test_untagged_sha3_single_file() {
488+
for l in SHA_LENGTHS {
489+
new_ucmd!()
490+
.arg("--untagged")
491+
.arg("--algorithm=sha3")
492+
.arg(format!("--length={l}"))
493+
.arg("lorem_ipsum.txt")
494+
.succeeds()
495+
.stdout_is_fixture(format!("untagged/sha3_{l}_single_file.expected"));
496+
}
497+
}
498+
499+
#[test]
500+
fn test_untagged_sha3_multiple_files() {
501+
for l in SHA_LENGTHS {
502+
new_ucmd!()
503+
.arg("--untagged")
504+
.arg("--algorithm=sha3")
505+
.arg(format!("--length={l}"))
506+
.arg("lorem_ipsum.txt")
507+
.arg("alice_in_wonderland.txt")
508+
.succeeds()
509+
.stdout_is_fixture(format!("untagged/sha3_{l}_multiple_files.expected"));
510+
}
511+
}
512+
513+
#[test]
514+
fn test_untagged_sha3_stdin() {
515+
for l in SHA_LENGTHS {
516+
new_ucmd!()
517+
.arg("--untagged")
518+
.arg("--algorithm=sha3")
519+
.arg(format!("--length={l}"))
520+
.pipe_in_fixture("lorem_ipsum.txt")
521+
.succeeds()
522+
.stdout_is_fixture(format!("untagged/sha3_{l}_stdin.expected"));
523+
}
524+
}
525+
526+
#[test]
527+
fn test_check_tagged_sha3_single_file() {
528+
for l in SHA_LENGTHS {
529+
new_ucmd!()
530+
.arg("--check")
531+
.arg(format!("sha3_{l}_single_file.expected"))
532+
.succeeds()
533+
.stdout_is("lorem_ipsum.txt: OK\n");
534+
}
535+
}
536+
537+
#[test]
538+
fn test_check_tagged_sha3_multiple_files() {
539+
for l in SHA_LENGTHS {
540+
new_ucmd!()
541+
.arg("--check")
542+
.arg(format!("sha3_{l}_multiple_files.expected"))
543+
.succeeds()
544+
.stdout_contains("lorem_ipsum.txt: OK\n")
545+
.stdout_contains("alice_in_wonderland.txt: OK\n");
546+
}
547+
}
548+
549+
// When checking sha3 in untagged mode, the length is automatically deduced
550+
// from the length of the digest.
551+
#[test]
552+
fn test_check_untagged_sha3_single_file() {
553+
for l in SHA_LENGTHS {
554+
new_ucmd!()
555+
.arg("--check")
556+
.arg("--algorithm=sha3")
557+
.arg(format!("untagged/sha3_{l}_single_file.expected"))
558+
.succeeds()
559+
.stdout_is("lorem_ipsum.txt: OK\n");
560+
}
561+
}
562+
563+
#[test]
564+
fn test_check_untagged_sha3_multiple_files() {
565+
for l in SHA_LENGTHS {
566+
new_ucmd!()
567+
.arg("--check")
568+
.arg("--algorithm=sha3")
569+
.arg(format!("untagged/sha3_{l}_multiple_files.expected"))
570+
.succeeds()
571+
.stdout_contains("lorem_ipsum.txt: OK\n")
572+
.stdout_contains("alice_in_wonderland.txt: OK\n");
573+
}
574+
}
575+
436576
#[test]
437577
fn test_check_algo() {
438578
for algo in ["bsd", "sysv", "crc", "crc32b"] {
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
SHA3-224 (lorem_ipsum.txt) = 00cf719da146d5f51f8969cb518aa2cb89dae71e0aad979b30398f13
2+
SHA3-224 (alice_in_wonderland.txt) = 33882bd6f47b47648950b4d6c606240c257eeae73e67b96610fd092c
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
SHA3-224 (lorem_ipsum.txt) = 00cf719da146d5f51f8969cb518aa2cb89dae71e0aad979b30398f13
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
SHA3-224 (-) = 00cf719da146d5f51f8969cb518aa2cb89dae71e0aad979b30398f13
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
SHA3-256 (lorem_ipsum.txt) = c9b081db1c20bdb4d8f376f45b3fb412b48c75932451d13dd79bea61e7bddbe4
2+
SHA3-256 (alice_in_wonderland.txt) = 507e920028b617afd342fdd0da3096237d34e33e2490c38a743bf628124803ce
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
SHA3-256 (lorem_ipsum.txt) = c9b081db1c20bdb4d8f376f45b3fb412b48c75932451d13dd79bea61e7bddbe4
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
SHA3-256 (-) = c9b081db1c20bdb4d8f376f45b3fb412b48c75932451d13dd79bea61e7bddbe4
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
SHA3-384 (lorem_ipsum.txt) = 12e0dc8c08c0f84c5facbe95ece4e0b568b3b9fbe7dbd1a6751a118c2997aa70a78123cb3d6858dc31d353fc6b874bbe
2+
SHA3-384 (alice_in_wonderland.txt) = d999e51e60b98da41060c287f71592517554addc14b9d27cac3935b8b312fb1e3ffad2730a9cfe855cf0fdcbce6990c6
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
SHA3-384 (lorem_ipsum.txt) = 12e0dc8c08c0f84c5facbe95ece4e0b568b3b9fbe7dbd1a6751a118c2997aa70a78123cb3d6858dc31d353fc6b874bbe
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
SHA3-384 (-) = 12e0dc8c08c0f84c5facbe95ece4e0b568b3b9fbe7dbd1a6751a118c2997aa70a78123cb3d6858dc31d353fc6b874bbe

0 commit comments

Comments
 (0)