1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-29 03:57:44 +00:00

Merge pull request #6929 from RenjiSann/cksum-fixes

cksum: even more fixes
This commit is contained in:
Daniel Hofstetter 2024-12-12 10:16:48 +01:00 committed by GitHub
commit 209ec0b817
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 398 additions and 197 deletions

View file

@ -1443,7 +1443,7 @@ mod check_utf8 {
let scene = TestScenario::new(util_name!());
let at = &scene.fixtures;
let filename: OsString = OsStringExt::from_vec(b"funky\xffname".to_vec());
at.touch(&filename);
at.touch(filename);
// Checksum match
at.write_bytes("check",
@ -1480,7 +1480,6 @@ mod check_utf8 {
}
}
#[ignore = "not yet implemented"]
#[test]
fn test_check_blake_length_guess() {
let correct_lines = [
@ -1523,7 +1522,6 @@ fn test_check_blake_length_guess() {
.stderr_contains("foo.sums: no properly formatted checksum lines found");
}
#[ignore = "not yet implemented"]
#[test]
fn test_check_confusing_base64() {
let cksum = "BLAKE2b-48 (foo.dat) = fc1f97C4";
@ -1544,7 +1542,6 @@ fn test_check_confusing_base64() {
/// This test checks that when a file contains several checksum lines
/// with different encoding, the decoding still works.
#[ignore = "not yet implemented"]
#[test]
fn test_check_mix_hex_base64() {
let b64 = "BLAKE2b-128 (foo1.dat) = BBNuJPhdRwRlw9tm5Y7VbA==";
@ -1769,3 +1766,81 @@ mod gnu_cksum_base64 {
}
}
}
/// The tests in this module check the behavior of cksum when given different
/// checksum formats and algorithms in the same file, while specifying an
/// algorithm on CLI or not.
mod format_mix {
use super::*;
// First line is algo-based, second one is not
const INPUT_ALGO_NON_ALGO: &str = "\
BLAKE2b (bar) = 786a02f742015903c6c6fd852552d272912f4740e15847618a86e217f71f5419d25e1031afee585313896444934eb04b903a685b1448b755d56f701afe9be2ce\n\
786a02f742015903c6c6fd852552d272912f4740e15847618a86e217f71f5419d25e1031afee585313896444934eb04b903a685b1448b755d56f701afe9be2ce foo";
// First line is non algo-based, second one is
const INPUT_NON_ALGO_ALGO: &str = "\
786a02f742015903c6c6fd852552d272912f4740e15847618a86e217f71f5419d25e1031afee585313896444934eb04b903a685b1448b755d56f701afe9be2ce foo\n\
BLAKE2b (bar) = 786a02f742015903c6c6fd852552d272912f4740e15847618a86e217f71f5419d25e1031afee585313896444934eb04b903a685b1448b755d56f701afe9be2ce";
/// Make a simple scene with foo and bar empty files
fn make_scene() -> TestScenario {
let scene = TestScenario::new(util_name!());
let at = &scene.fixtures;
at.touch("foo");
at.touch("bar");
scene
}
#[test]
fn test_check_cli_algo_non_algo() {
let scene = make_scene();
scene
.ucmd()
.arg("--check")
.arg("--algo=blake2b")
.pipe_in(INPUT_ALGO_NON_ALGO)
.succeeds()
.stdout_contains("bar: OK\nfoo: OK")
.no_stderr();
}
#[test]
fn test_check_cli_non_algo_algo() {
let scene = make_scene();
scene
.ucmd()
.arg("--check")
.arg("--algo=blake2b")
.pipe_in(INPUT_NON_ALGO_ALGO)
.succeeds()
.stdout_contains("foo: OK\nbar: OK")
.no_stderr();
}
#[test]
fn test_check_algo_non_algo() {
let scene = make_scene();
scene
.ucmd()
.arg("--check")
.pipe_in(INPUT_ALGO_NON_ALGO)
.succeeds()
.stdout_contains("bar: OK")
.stderr_contains("cksum: WARNING: 1 line is improperly formatted");
}
#[test]
fn test_check_non_algo_algo() {
let scene = make_scene();
scene
.ucmd()
.arg("--check")
.pipe_in(INPUT_NON_ALGO_ALGO)
.succeeds()
.stdout_contains("bar: OK")
.stderr_contains("cksum: WARNING: 1 line is improperly formatted");
}
}