Skip to content

Commit

Permalink
Merge pull request #3816 from sylvestre/fix-3815
Browse files Browse the repository at this point in the history
sha1sum: fix the -c usage (Closes: #3815)
  • Loading branch information
tertsdiepraam authored Aug 15, 2022
2 parents 2870fb0 + 00f5d91 commit 4434b7d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/uu/hashsum/src/hashsum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,11 @@ pub fn uumain(mut args: impl uucore::Args) -> UResult<()> {
};
let check = matches.contains_id("check");
let tag = matches.contains_id("tag");
let nonames = matches.contains_id("no-names");
let nonames = if binary_name == "b3sum" {
matches.contains_id("no-names")
} else {
false
};
let status = matches.contains_id("status");
let quiet = matches.contains_id("quiet") || status;
let strict = matches.contains_id("strict");
Expand Down
28 changes: 26 additions & 2 deletions tests/by-util/test_hashsum.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// spell-checker:ignore checkfile, nonames
use crate::common::util::*;
// spell-checker:ignore checkfile, nonames, testf
macro_rules! get_hash(
($str:expr) => (
$str.split(' ').collect::<Vec<&str>>()[0]
Expand Down Expand Up @@ -33,10 +34,13 @@ macro_rules! test_digest {
fn test_nonames() {
let ts = TestScenario::new("hashsum");
// EXPECTED_FILE has no newline character at the end
assert_eq!(format!("{0}\n{0}\n", ts.fixtures.read(EXPECTED_FILE)),
if DIGEST_ARG == "b3sum" {
// Option only available on b3sum
assert_eq!(format!("{0}\n{0}\n", ts.fixtures.read(EXPECTED_FILE)),
ts.ucmd().arg(DIGEST_ARG).arg(BITS_ARG).arg("--no-names").arg("input.txt").arg("-").pipe_in_fixture("input.txt")
.succeeds().no_stderr().stdout_str()
);
}
}

#[test]
Expand Down Expand Up @@ -92,3 +96,23 @@ test_digest! {
b2sum b2sum 512
b3sum b3sum 256
}

#[test]
fn test_check_sha1() {
// To make sure that #3815 doesn't happen again
let scene = TestScenario::new(util_name!());
let at = &scene.fixtures;

at.write("testf", "foobar\n");
at.write(
"testf.sha1",
"988881adc9fc3655077dc2d4d757d480b5ea0e11 testf\n",
);
scene
.ccmd("sha1sum")
.arg("-c")
.arg(at.subdir.join("testf.sha1"))
.succeeds()
.stdout_is("testf: OK\n")
.stderr_is("");
}

0 comments on commit 4434b7d

Please sign in to comment.