1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 11:37:44 +00:00

test(cksum): add test for trailing spaces making an error

This commit is contained in:
Dorian Péron 2024-10-18 23:58:41 +02:00
parent 97b81a6685
commit 1c41a12fb5
2 changed files with 36 additions and 0 deletions

View file

@ -991,6 +991,19 @@ mod tests {
// Test invalid checksum line
let lines_invalid = vec!["invalid checksum line".to_string()];
assert!(determine_regex(&lines_invalid).is_none());
// Test leading space before checksum line
let lines_algo_based_leading_space =
vec![" MD5 (example.txt) = d41d8cd98f00b204e9800998ecf8427e".to_string()];
let res = determine_regex(&lines_algo_based_leading_space);
assert!(res.is_some());
assert_eq!(res.unwrap().0.as_str(), ALGO_BASED_REGEX);
// Test trailing space after checksum line (should fail)
let lines_algo_based_leading_space =
vec!["MD5 (example.txt) = d41d8cd98f00b204e9800998ecf8427e ".to_string()];
let res = determine_regex(&lines_algo_based_leading_space);
assert!(res.is_none());
}
#[test]

View file

@ -1402,3 +1402,26 @@ fn test_zero_single_file() {
.succeeds()
.stdout_is_fixture("zero_single_file.expected");
}
#[test]
fn test_check_trailing_space_fails() {
// If a checksum line has trailing spaces after the digest,
// it shall be considered improperly formatted.
let scene = TestScenario::new(util_name!());
let at = &scene.fixtures;
at.write("foo", "foo-content\n");
at.write(
"CHECKSUM",
"SHA1 (foo) = 058ab38dd3603703b3a7063cf95dc51a4286b6fe \n",
);
scene
.ucmd()
.arg("--check")
.arg("CHECKSUM")
.fails()
.no_stdout()
.stderr_contains("CHECKSUM: no properly formatted checksum lines found");
}