mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
cksum: also show the error on stdout
This commit is contained in:
parent
07d579c40a
commit
115b203b22
2 changed files with 21 additions and 7 deletions
|
@ -510,10 +510,9 @@ where
|
||||||
match File::open(filename_to_check) {
|
match File::open(filename_to_check) {
|
||||||
Ok(f) => Box::new(f),
|
Ok(f) => Box::new(f),
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
show!(err.map_err_context(|| format!(
|
// yes, we have both stderr and stdout here
|
||||||
"Failed to open file: {}",
|
show!(err.map_err_context(|| filename_to_check.to_string()));
|
||||||
filename_to_check
|
println!("{}: FAILED open or read", filename_to_check);
|
||||||
)));
|
|
||||||
failed_open_file += 1;
|
failed_open_file += 1;
|
||||||
// we could not open the file but we want to continue
|
// we could not open the file but we want to continue
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -80,6 +80,21 @@ fn test_nonexisting_file() {
|
||||||
.stderr_contains(format!("cksum: {file_name}: No such file or directory"));
|
.stderr_contains(format!("cksum: {file_name}: No such file or directory"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_nonexisting_file_out() {
|
||||||
|
let (at, mut ucmd) = at_and_ucmd!();
|
||||||
|
at.write(
|
||||||
|
"f",
|
||||||
|
"MD5 (nonexistent) = e5773576fc75ff0f8eba14f61587ae28\n",
|
||||||
|
);
|
||||||
|
|
||||||
|
ucmd.arg("-c")
|
||||||
|
.arg("f")
|
||||||
|
.fails()
|
||||||
|
.stdout_contains("nonexistent: FAILED open or read")
|
||||||
|
.stderr_contains("cksum: nonexistent: No such file or directory");
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_one_nonexisting_file() {
|
fn test_one_nonexisting_file() {
|
||||||
let (at, mut ucmd) = at_and_ucmd!();
|
let (at, mut ucmd) = at_and_ucmd!();
|
||||||
|
@ -905,7 +920,7 @@ fn test_cksum_check_failed() {
|
||||||
.arg("CHECKSUM")
|
.arg("CHECKSUM")
|
||||||
.fails();
|
.fails();
|
||||||
|
|
||||||
assert!(result.stderr_str().contains("Failed to open file: input"));
|
assert!(result.stderr_str().contains("input: No such file or directory"));
|
||||||
assert!(result
|
assert!(result
|
||||||
.stderr_str()
|
.stderr_str()
|
||||||
.contains("2 lines are improperly formatted\n"));
|
.contains("2 lines are improperly formatted\n"));
|
||||||
|
@ -917,7 +932,7 @@ fn test_cksum_check_failed() {
|
||||||
// without strict
|
// without strict
|
||||||
let result = scene.ucmd().arg("--check").arg("CHECKSUM").fails();
|
let result = scene.ucmd().arg("--check").arg("CHECKSUM").fails();
|
||||||
|
|
||||||
assert!(result.stderr_str().contains("Failed to open file: input"));
|
assert!(result.stderr_str().contains("input: No such file or directory"));
|
||||||
assert!(result
|
assert!(result
|
||||||
.stderr_str()
|
.stderr_str()
|
||||||
.contains("2 lines are improperly formatted\n"));
|
.contains("2 lines are improperly formatted\n"));
|
||||||
|
@ -945,7 +960,7 @@ fn test_cksum_check_failed() {
|
||||||
.fails();
|
.fails();
|
||||||
println!("result.stderr_str() {}", result.stderr_str());
|
println!("result.stderr_str() {}", result.stderr_str());
|
||||||
println!("result.stdout_str() {}", result.stdout_str());
|
println!("result.stdout_str() {}", result.stdout_str());
|
||||||
assert!(result.stderr_str().contains("Failed to open file: input2"));
|
assert!(result.stderr_str().contains("input2: No such file or directory"));
|
||||||
assert!(result
|
assert!(result
|
||||||
.stderr_str()
|
.stderr_str()
|
||||||
.contains("4 lines are improperly formatted\n"));
|
.contains("4 lines are improperly formatted\n"));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue