diff --git a/tests/by-util/test_cksum.rs b/tests/by-util/test_cksum.rs index 86de7ea95b6..1798261c3e3 100644 --- a/tests/by-util/test_cksum.rs +++ b/tests/by-util/test_cksum.rs @@ -1569,35 +1569,68 @@ fn test_check_mix_hex_base64() { .stdout_only("foo1.dat: OK\nfoo2.dat: OK\n"); } -#[ignore = "not yet implemented"] +/// This test ensures that an improperly formatted base64 checksum in a file +/// does not interrupt the processing of next lines. #[test] -fn test_check_incorrectly_formatted_checksum_does_not_stop_processing() { - // The first line contains an incorrectly formatted checksum that can't be - // correctly decoded. This must not prevent the program from looking at the - // rest of the file. - let lines = [ - "BLAKE2b-56 (foo1) = GFYEQ7HhAw=", // Should be 2 '=' at the end - "BLAKE2b-56 (foo2) = 18560443b1e103", // OK - ]; +fn test_check_incorrectly_formatted_checksum_keeps_processing_b64() { + let scene = TestScenario::new(util_name!()); + let at = &scene.fixtures; + at.touch("f"); + + let good_ck = "MD5 (f) = 1B2M2Y8AsgTpgAmY7PhCfg=="; // OK + let bad_ck = "MD5 (f) = 1B2M2Y8AsgTpgAmY7PhCfg="; // Missing last '=' + + // Good then Bad + scene + .ucmd() + .arg("--check") + .pipe_in([good_ck, bad_ck].join("\n").as_bytes().to_vec()) + .succeeds() + .stdout_contains("f: OK") + .stderr_contains("cksum: WARNING: 1 line is improperly formatted"); + + // Bad then Good + scene + .ucmd() + .arg("--check") + .pipe_in([bad_ck, good_ck].join("\n").as_bytes().to_vec()) + .succeeds() + .stdout_contains("f: OK") + .stderr_contains("cksum: WARNING: 1 line is improperly formatted"); +} +/// This test ensures that an improperly formatted hexadecimal checksum in a +/// file does not interrupt the processing of next lines. +#[test] +fn test_check_incorrectly_formatted_checksum_keeps_processing_hex() { let scene = TestScenario::new(util_name!()); let at = &scene.fixtures; + at.touch("f"); + + let good_ck = "MD5 (f) = d41d8cd98f00b204e9800998ecf8427e"; // OK + let bad_ck = "MD5 (f) = d41d8cd98f00b204e9800998ecf8427"; // Missing last - at.write("foo1", "foo"); - at.write("foo2", "foo"); - at.write("sum", &lines.join("\n")); + // Good then Bad + scene + .ucmd() + .arg("--check") + .pipe_in([good_ck, bad_ck].join("\n").as_bytes().to_vec()) + .succeeds() + .stdout_contains("f: OK") + .stderr_contains("cksum: WARNING: 1 line is improperly formatted"); + // Bad then Good scene .ucmd() .arg("--check") - .arg(at.subdir.join("sum")) + .pipe_in([bad_ck, good_ck].join("\n").as_bytes().to_vec()) .succeeds() - .stderr_contains("1 line is improperly formatted") - .stdout_contains("foo2: OK"); + .stdout_contains("f: OK") + .stderr_contains("cksum: WARNING: 1 line is improperly formatted"); } /// This module reimplements the cksum-base64.pl GNU test. -mod cksum_base64 { +mod gnu_cksum_base64 { use super::*; use crate::common::util::log_info;