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

hashsum: also escape/unescape files with checks (#5868)

* hashsum: make tag conflicts with --text and --check

* hashsum: change the case in one of the gnu test

* build-gnu.sh: use symlink instead of copy

Plus: it won't cp new md5

* hashsum: also escape/unescape files with checks

Should fix tests/cksum/md5sum-bsd.sh

* improve the variable name

Co-authored-by: Daniel Hofstetter <daniel.hofstetter@42dh.com>

* Improve test

Co-authored-by: Daniel Hofstetter <daniel.hofstetter@42dh.com>

* Improve test

Co-authored-by: Daniel Hofstetter <daniel.hofstetter@42dh.com>

---------

Co-authored-by: Daniel Hofstetter <daniel.hofstetter@42dh.com>
This commit is contained in:
Sylvestre Ledru 2024-03-12 14:56:27 +01:00 committed by GitHub
parent cc1142cee6
commit 1725479c06
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 94 additions and 15 deletions

View file

@ -356,6 +356,22 @@ fn test_invalid_arg() {
new_ucmd!().arg("--definitely-invalid").fails().code_is(1);
}
#[test]
fn test_conflicting_arg() {
new_ucmd!()
.arg("--tag")
.arg("--check")
.arg("--md5")
.fails()
.code_is(1);
new_ucmd!()
.arg("--tag")
.arg("--text")
.arg("--md5")
.fails()
.code_is(1);
}
#[test]
fn test_tag() {
let scene = TestScenario::new(util_name!());
@ -386,3 +402,47 @@ fn test_with_escape_filename() {
assert!(stdout.starts_with('\\'));
assert!(stdout.trim().ends_with("a\\nb"));
}
#[test]
#[cfg(not(windows))]
fn test_with_escape_filename_zero_text() {
let scene = TestScenario::new(util_name!());
let at = &scene.fixtures;
let filename = "a\nb";
at.touch(filename);
let result = scene
.ccmd("md5sum")
.arg("--text")
.arg("--zero")
.arg(filename)
.succeeds();
let stdout = result.stdout_str();
println!("stdout {}", stdout);
assert!(!stdout.starts_with('\\'));
assert!(stdout.contains("a\nb"));
}
#[test]
#[cfg(not(windows))]
fn test_check_with_escape_filename() {
let scene = TestScenario::new(util_name!());
let at = &scene.fixtures;
let filename = "a\nb";
at.touch(filename);
let result = scene.ccmd("md5sum").arg("--tag").arg(filename).succeeds();
let stdout = result.stdout_str();
println!("stdout {}", stdout);
assert!(stdout.starts_with("\\MD5"));
assert!(stdout.contains("a\\nb"));
at.write("check.md5", stdout);
let result = scene
.ccmd("md5sum")
.arg("--strict")
.arg("-c")
.arg("check.md5")
.succeeds();
result.stdout_is("\\a\\nb: OK\n");
}