mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-30 20:47:46 +00:00
Merge pull request #6252 from sylvestre/hash-error
hashsum: improve the error management to match GNU
This commit is contained in:
commit
64027e5a57
4 changed files with 249 additions and 64 deletions
|
@ -244,7 +244,7 @@ fn test_check_file_not_found_warning() {
|
|||
.arg(at.subdir.join("testf.sha1"))
|
||||
.fails()
|
||||
.stdout_is("sha1sum: testf: No such file or directory\ntestf: FAILED open or read\n")
|
||||
.stderr_is("sha1sum: warning: 1 listed file could not be read\n");
|
||||
.stderr_is("sha1sum: WARNING: 1 listed file could not be read\n");
|
||||
}
|
||||
|
||||
// Asterisk `*` is a reserved paths character on win32, nor the path can end with a whitespace.
|
||||
|
@ -457,6 +457,24 @@ fn test_with_escape_filename_zero_text() {
|
|||
assert!(stdout.contains("a\nb"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_check_empty_line() {
|
||||
let scene = TestScenario::new(util_name!());
|
||||
let at = &scene.fixtures;
|
||||
|
||||
at.touch("f");
|
||||
at.write(
|
||||
"in.md5",
|
||||
"d41d8cd98f00b204e9800998ecf8427e f\n\nd41d8cd98f00b204e9800998ecf8427e f\ninvalid\n\n",
|
||||
);
|
||||
scene
|
||||
.ccmd("md5sum")
|
||||
.arg("--check")
|
||||
.arg(at.subdir.join("in.md5"))
|
||||
.succeeds()
|
||||
.stderr_contains("WARNING: 1 line is improperly formatted");
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(not(windows))]
|
||||
fn test_check_with_escape_filename() {
|
||||
|
@ -480,3 +498,114 @@ fn test_check_with_escape_filename() {
|
|||
.succeeds();
|
||||
result.stdout_is("\\a\\nb: OK\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_check_strict_error() {
|
||||
let scene = TestScenario::new(util_name!());
|
||||
let at = &scene.fixtures;
|
||||
|
||||
at.write("f", "");
|
||||
at.write(
|
||||
"in.md5",
|
||||
"ERR\nERR\nd41d8cd98f00b204e9800998ecf8427e f\nERR\n",
|
||||
);
|
||||
scene
|
||||
.ccmd("md5sum")
|
||||
.arg("--check")
|
||||
.arg("--strict")
|
||||
.arg(at.subdir.join("in.md5"))
|
||||
.fails()
|
||||
.stderr_contains("WARNING: 3 lines are improperly formatted");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_check_warn() {
|
||||
let scene = TestScenario::new(util_name!());
|
||||
let at = &scene.fixtures;
|
||||
|
||||
at.write("f", "");
|
||||
at.write(
|
||||
"in.md5",
|
||||
"d41d8cd98f00b204e9800998ecf8427e f\nd41d8cd98f00b204e9800998ecf8427e f\ninvalid\n",
|
||||
);
|
||||
scene
|
||||
.ccmd("md5sum")
|
||||
.arg("--check")
|
||||
.arg("--warn")
|
||||
.arg(at.subdir.join("in.md5"))
|
||||
.succeeds()
|
||||
.stderr_contains("in.md5: 3: improperly formatted MD5 checksum line")
|
||||
.stderr_contains("WARNING: 1 line is improperly formatted");
|
||||
|
||||
// with strict, we should fail the execution
|
||||
scene
|
||||
.ccmd("md5sum")
|
||||
.arg("--check")
|
||||
.arg("--strict")
|
||||
.arg(at.subdir.join("in.md5"))
|
||||
.fails();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_check_status() {
|
||||
let scene = TestScenario::new(util_name!());
|
||||
let at = &scene.fixtures;
|
||||
|
||||
at.write("f", "");
|
||||
at.write("in.md5", "MD5(f)= d41d8cd98f00b204e9800998ecf8427f\n");
|
||||
scene
|
||||
.ccmd("md5sum")
|
||||
.arg("--check")
|
||||
.arg("--status")
|
||||
.arg(at.subdir.join("in.md5"))
|
||||
.fails()
|
||||
.no_output();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_check_status_code() {
|
||||
let scene = TestScenario::new(util_name!());
|
||||
let at = &scene.fixtures;
|
||||
|
||||
at.write("f", "");
|
||||
at.write("in.md5", "d41d8cd98f00b204e9800998ecf8427f f\n");
|
||||
scene
|
||||
.ccmd("md5sum")
|
||||
.arg("--check")
|
||||
.arg("--status")
|
||||
.arg(at.subdir.join("in.md5"))
|
||||
.fails()
|
||||
.stderr_is("")
|
||||
.stdout_is("");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_check_no_backslash_no_space() {
|
||||
let scene = TestScenario::new(util_name!());
|
||||
let at = &scene.fixtures;
|
||||
|
||||
at.write("f", "");
|
||||
at.write("in.md5", "MD5(f)= d41d8cd98f00b204e9800998ecf8427e\n");
|
||||
scene
|
||||
.ccmd("md5sum")
|
||||
.arg("--check")
|
||||
.arg(at.subdir.join("in.md5"))
|
||||
.succeeds()
|
||||
.stdout_is("f: OK\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_check_check_ignore_no_file() {
|
||||
let scene = TestScenario::new(util_name!());
|
||||
let at = &scene.fixtures;
|
||||
|
||||
at.write("f", "");
|
||||
at.write("in.md5", "d41d8cd98f00b204e9800998ecf8427f missing\n");
|
||||
scene
|
||||
.ccmd("md5sum")
|
||||
.arg("--check")
|
||||
.arg("--ignore-missing")
|
||||
.arg(at.subdir.join("in.md5"))
|
||||
.fails()
|
||||
.stderr_contains("in.md5: no file was verified");
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue