Skip to content

Commit

Permalink
put the file name in b3sum error output
Browse files Browse the repository at this point in the history
This was previously there, but got dropped in
c5c07bb.
  • Loading branch information
oconnor663-zoom committed Jun 24, 2020
1 parent 4c41a89 commit e0f193d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion b3sum/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ fn main() -> Result<()> {
let result = hash_one_input(path, &args);
if let Err(e) = result {
some_file_failed = true;
eprintln!("{}: {}", NAME, e);
eprintln!("{}: {}: {}", NAME, path.to_string_lossy(), e);
}
}
}
Expand Down
31 changes: 31 additions & 0 deletions b3sum/tests/cli_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,37 @@ fn test_hash_many() {
assert_eq!(expected_no_names, output_no_names);
}

#[test]
fn test_missing_files() {
let dir = tempfile::tempdir().unwrap();
let file1 = dir.path().join("file1");
fs::write(&file1, b"foo").unwrap();
let file2 = dir.path().join("file2");
fs::write(&file2, b"bar").unwrap();

let output = cmd!(b3sum_exe(), "file1", "missing_file", "file2")
.dir(dir.path())
.stdout_capture()
.stderr_capture()
.unchecked()
.run()
.unwrap();
assert!(!output.status.success());

let foo_hash = blake3::hash(b"foo");
let bar_hash = blake3::hash(b"bar");
let expected_stdout = format!(
"{} file1\n{} file2\n",
foo_hash.to_hex(),
bar_hash.to_hex(),
);
assert_eq!(expected_stdout.as_bytes(), &output.stdout[..]);

let bing_error = fs::File::open(dir.path().join("missing_file")).unwrap_err();
let expected_stderr = format!("b3sum: missing_file: {}\n", bing_error.to_string());
assert_eq!(expected_stderr.as_bytes(), &output.stderr[..]);
}

#[test]
fn test_hash_length() {
let mut buf = [0; 100];
Expand Down

0 comments on commit e0f193d

Please sign in to comment.