Skip to content

Commit 966fdc0

Browse files
committed
test(cksum): Test for cksum -a blake3
1 parent 7a67af5 commit 966fdc0

3 files changed

Lines changed: 124 additions & 0 deletions

File tree

Cargo.lock

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,7 @@ rayon = "1.10"
432432
regex = "1.10.4"
433433
rlimit = "0.11.0"
434434
rstest = "0.26.0"
435+
rstest_reuse = "0.7.0"
435436
rustc-hash = "2.1.1"
436437
rust-ini = "0.21.0"
437438
same-file = "1.0.6"
@@ -640,6 +641,7 @@ uucore = { workspace = true, features = [
640641
walkdir.workspace = true
641642
hex-literal = "1.0.0"
642643
rstest.workspace = true
644+
rstest_reuse.workspace = true
643645

644646
[target.'cfg(unix)'.dev-dependencies]
645647
nix = { workspace = true, features = [

tests/by-util/test_cksum.rs

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
// spell-checker:ignore (words) asdf algo algos asha mgmt xffname hexa GFYEQ HYQK Yqxb dont checkfile
66

77
use rstest::rstest;
8+
use rstest_reuse::{apply, template};
89

910
use uutests::at_and_ucmd;
1011
use uutests::new_ucmd;
@@ -3287,3 +3288,112 @@ fn test_check_shake256_no_length() {
32873288
.fails()
32883289
.stderr_only("cksum: 'standard input': no properly formatted checksum lines found\n");
32893290
}
3291+
3292+
#[template]
3293+
#[rstest]
3294+
#[case::no_length(
3295+
b"foo",
3296+
"04e0bb39f30b1a3feb89f536c93be15055482df748674b00d26e5a75777702e9",
3297+
None
3298+
)]
3299+
#[case(
3300+
b"foo",
3301+
"04e0bb39f30b1a3feb89f536c93be15055482df748674b00d26e5a75777702e9",
3302+
Some(0)
3303+
)]
3304+
#[case(
3305+
b"foo",
3306+
"04e0bb39f30b1a3feb89f536c93be15055482df748674b00d26e5a75777702e9",
3307+
Some(256)
3308+
)]
3309+
#[case(
3310+
b"foo",
3311+
"04e0bb39f30b1a3feb89f536c93be15055482df748674b00d26e5a75777702e9791074b7511b59d31c71c62f5a745689fa6c",
3312+
Some(400)
3313+
)]
3314+
#[case(b"foo", "04e0bb39f3", Some(40))]
3315+
#[case(b"foo", "04e0", Some(16))]
3316+
#[case(b"foo", "04", Some(8))]
3317+
fn test_blake3(#[case] input: &[u8], #[case] expected: &str, #[case] length: Option<usize>) {}
3318+
3319+
#[apply(test_blake3)]
3320+
fn test_compute_blake3(
3321+
#[case] input: &[u8],
3322+
#[case] expected: &str,
3323+
#[case] length: Option<usize>,
3324+
) {
3325+
let length_args: &[String] = if let Some(len) = length {
3326+
&["-l".into(), len.to_string()]
3327+
} else {
3328+
&[]
3329+
};
3330+
3331+
new_ucmd!()
3332+
.arg("-a")
3333+
.arg("blake3")
3334+
.args(length_args)
3335+
.pipe_in(input)
3336+
.succeeds()
3337+
.stdout_only(format!(
3338+
"BLAKE3{} (-) = {expected}\n",
3339+
match length {
3340+
Some(0) | None => "-256".into(),
3341+
Some(i) => format!("-{i}"),
3342+
}
3343+
));
3344+
3345+
// with --untagged
3346+
new_ucmd!()
3347+
.arg("-a")
3348+
.arg("blake3")
3349+
.arg("--untagged")
3350+
.args(length_args)
3351+
.pipe_in(input)
3352+
.succeeds()
3353+
.stdout_only(format!("{expected} -\n"));
3354+
}
3355+
3356+
#[apply(test_blake3)]
3357+
fn test_check_blake3_tagged(
3358+
#[case] input: &[u8],
3359+
#[case] digest: &str,
3360+
#[case] opt_len: Option<usize>,
3361+
) {
3362+
let (at, mut ucmd) = at_and_ucmd!();
3363+
at.write_bytes("FILE", input);
3364+
3365+
let len = match opt_len {
3366+
Some(0) => "-256".into(),
3367+
Some(i) => format!("-{i}"),
3368+
None => String::new(),
3369+
};
3370+
3371+
let tagged = format!("BLAKE3{len} (FILE) = {digest}",);
3372+
3373+
ucmd.arg("-c")
3374+
.arg("-a")
3375+
.arg("blake3")
3376+
.pipe_in(tagged)
3377+
.succeeds()
3378+
.stdout_only("FILE: OK\n");
3379+
}
3380+
3381+
#[apply(test_blake3)]
3382+
#[allow(clippy::used_underscore_binding)]
3383+
fn test_check_blake3_untagged(
3384+
#[case] input: &[u8],
3385+
#[case] digest: &str,
3386+
#[case] _opt_len: Option<usize>,
3387+
) {
3388+
let (at, mut ucmd) = at_and_ucmd!();
3389+
at.write_bytes("FILE", input);
3390+
3391+
let untagged = format!("{digest} FILE");
3392+
3393+
ucmd.arg("-c")
3394+
.arg("-a")
3395+
.arg("blake3")
3396+
.pipe_in(untagged)
3397+
.succeeds()
3398+
.stdout_only("FILE: OK\n");
3399+
}

0 commit comments

Comments
 (0)