mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 03:27:44 +00:00
hashsum: improve the error management to match GNU
Should make tests/cksum/md5sum.pl and tests/cksum/sha1sum.pl pass
This commit is contained in:
parent
128c0bc6b5
commit
6ef08d7f1c
4 changed files with 184 additions and 22 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.
|
||||
|
@ -471,7 +471,7 @@ fn test_check_empty_line() {
|
|||
.ccmd("md5sum")
|
||||
.arg("--check")
|
||||
.arg(at.subdir.join("in.md5"))
|
||||
.fails()
|
||||
.succeeds()
|
||||
.stderr_contains("WARNING: 1 line is improperly formatted");
|
||||
}
|
||||
|
||||
|
@ -498,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