Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sha1sum: fix the -c usage (Closes: #3815) #3816

Merged
merged 1 commit into from
Aug 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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("");
}