mirror of
https://github.com/uutils/coreutils.git
synced 2026-06-10 15:48:22 -07:00
sha1sum: introduce standalone binary
This commit is contained in:
Generated
+13
@@ -627,6 +627,7 @@ dependencies = [
|
||||
"uu_rmdir",
|
||||
"uu_runcon",
|
||||
"uu_seq",
|
||||
"uu_sha1sum",
|
||||
"uu_shred",
|
||||
"uu_shuf",
|
||||
"uu_sleep",
|
||||
@@ -3984,6 +3985,18 @@ dependencies = [
|
||||
"uucore",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "uu_sha1sum"
|
||||
version = "0.6.0"
|
||||
dependencies = [
|
||||
"clap",
|
||||
"codspeed-divan-compat",
|
||||
"fluent",
|
||||
"tempfile",
|
||||
"uu_checksum_common",
|
||||
"uucore",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "uu_shred"
|
||||
version = "0.6.0"
|
||||
|
||||
@@ -88,6 +88,7 @@ feat_common_core = [
|
||||
"cksum",
|
||||
"b2sum",
|
||||
"md5sum",
|
||||
"sha1sum",
|
||||
"comm",
|
||||
"cp",
|
||||
"csplit",
|
||||
@@ -441,6 +442,7 @@ chroot = { optional = true, version = "0.6.0", package = "uu_chroot", path = "sr
|
||||
cksum = { optional = true, version = "0.6.0", package = "uu_cksum", path = "src/uu/cksum" }
|
||||
b2sum = { optional = true, version = "0.6.0", package = "uu_b2sum", path = "src/uu/b2sum" }
|
||||
md5sum = { optional = true, version = "0.6.0", package = "uu_md5sum", path = "src/uu/md5sum" }
|
||||
sha1sum = { optional = true, version = "0.6.0", package = "uu_sha1sum", path = "src/uu/sha1sum" }
|
||||
comm = { optional = true, version = "0.6.0", package = "uu_comm", path = "src/uu/comm" }
|
||||
cp = { optional = true, version = "0.6.0", package = "uu_cp", path = "src/uu/cp" }
|
||||
csplit = { optional = true, version = "0.6.0", package = "uu_csplit", path = "src/uu/csplit" }
|
||||
|
||||
@@ -96,7 +96,6 @@ SELINUX_PROGS := \
|
||||
runcon
|
||||
|
||||
HASHSUM_PROGS := \
|
||||
sha1sum \
|
||||
sha224sum \
|
||||
sha256sum \
|
||||
sha384sum \
|
||||
|
||||
@@ -91,7 +91,6 @@ pub fn main() {
|
||||
phf_map.entry(krate, format!("({krate}::uumain, {krate}::uu_app_custom)"));
|
||||
|
||||
let map_value = format!("({krate}::uumain, {krate}::uu_app_common)");
|
||||
phf_map.entry("sha1sum", map_value.clone());
|
||||
phf_map.entry("sha224sum", map_value.clone());
|
||||
phf_map.entry("sha256sum", map_value.clone());
|
||||
phf_map.entry("sha384sum", map_value.clone());
|
||||
|
||||
@@ -51,7 +51,7 @@ fn get_canonical_util_name(util_name: &str) -> &str {
|
||||
"[" => "test",
|
||||
|
||||
// hashsum aliases - all these hash commands are aliases for hashsum
|
||||
"sha1sum" | "sha224sum" | "sha256sum" | "sha384sum" | "sha512sum" => "hashsum",
|
||||
"sha224sum" | "sha256sum" | "sha384sum" | "sha512sum" => "hashsum",
|
||||
|
||||
"dir" => "ls", // dir is an alias for ls
|
||||
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
[package]
|
||||
name = "uu_sha1sum"
|
||||
description = "sha1sum ~ (uutils) Print or check the SHA1 checksums"
|
||||
repository = "https://github.com/uutils/coreutils/tree/main/src/uu/sha1sum"
|
||||
version.workspace = true
|
||||
authors.workspace = true
|
||||
license.workspace = true
|
||||
homepage.workspace = true
|
||||
keywords.workspace = true
|
||||
categories.workspace = true
|
||||
edition.workspace = true
|
||||
readme.workspace = true
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
|
||||
[lib]
|
||||
path = "src/sha1sum.rs"
|
||||
|
||||
[dependencies]
|
||||
clap = { workspace = true }
|
||||
uu_checksum_common = { workspace = true }
|
||||
uucore = { workspace = true, features = [
|
||||
"checksum",
|
||||
"encoding",
|
||||
"sum",
|
||||
"hardware",
|
||||
] }
|
||||
fluent = { workspace = true }
|
||||
|
||||
[dev-dependencies]
|
||||
divan = { workspace = true }
|
||||
tempfile = { workspace = true }
|
||||
uucore = { workspace = true, features = ["benchmark"] }
|
||||
|
||||
[[bin]]
|
||||
name = "sha1sum"
|
||||
path = "src/main.rs"
|
||||
Symlink
+1
@@ -0,0 +1 @@
|
||||
../../../LICENSE
|
||||
@@ -0,0 +1,2 @@
|
||||
sha1sum-about = Print or check the SHA1 checksums
|
||||
sha1sum-usage = sha1sum [OPTIONS] [FILE]...
|
||||
@@ -0,0 +1,2 @@
|
||||
sha1sum-about = Afficher le SHA1 et la taille de chaque fichier
|
||||
sha1sum-usage = sha1sum [OPTION]... [FICHIER]...
|
||||
@@ -0,0 +1 @@
|
||||
uucore::bin!(uu_sha1sum);
|
||||
@@ -0,0 +1 @@
|
||||
uu_checksum_common::declare_standalone!("sha1sum", uucore::checksum::AlgoKind::Sha1);
|
||||
@@ -173,7 +173,7 @@ pub fn get_canonical_util_name(util_name: &str) -> &str {
|
||||
"[" => "test",
|
||||
|
||||
// hashsum aliases - all these hash commands are aliases for hashsum
|
||||
"sha1sum" | "sha224sum" | "sha256sum" | "sha384sum" | "sha512sum" => "hashsum",
|
||||
"sha224sum" | "sha256sum" | "sha384sum" | "sha512sum" => "hashsum",
|
||||
|
||||
"dir" => "ls", // dir is an alias for ls
|
||||
|
||||
|
||||
@@ -157,7 +157,7 @@ fn create_bundle(
|
||||
try_add_resource_from(get_locales_dir(util_name).ok());
|
||||
|
||||
// checksum binaries also require fluent files from the checksum_common crate
|
||||
if ["cksum", "b2sum", "md5sum"].contains(&util_name) {
|
||||
if ["cksum", "b2sum", "md5sum", "sha1sum"].contains(&util_name) {
|
||||
try_add_resource_from(get_locales_dir("checksum_common").ok());
|
||||
}
|
||||
|
||||
|
||||
@@ -201,7 +201,6 @@ macro_rules! test_digest_with_len {
|
||||
};
|
||||
}
|
||||
|
||||
test_digest! {sha1, sha1}
|
||||
test_digest! {b3sum, b3sum}
|
||||
test_digest! {shake128, shake128}
|
||||
test_digest! {shake256, shake256}
|
||||
@@ -215,6 +214,7 @@ test_digest_with_len! {sha3_256, sha3, 256}
|
||||
test_digest_with_len! {sha3_384, sha3, 384}
|
||||
test_digest_with_len! {sha3_512, sha3, 512}
|
||||
|
||||
#[ignore = "moved to standalone"]
|
||||
#[test]
|
||||
fn test_check_sha1() {
|
||||
// To make sure that #3815 doesn't happen again
|
||||
@@ -414,6 +414,7 @@ fn test_check_b2sum_verify() {
|
||||
.stdout_only("BLAKE2b-128 (a) = b93e0fc7bb21633c08bba07c5e71dc00\n");
|
||||
}
|
||||
|
||||
#[ignore = "moved to standalone"]
|
||||
#[test]
|
||||
fn test_check_file_not_found_warning() {
|
||||
let scene = TestScenario::new(util_name!());
|
||||
|
||||
@@ -0,0 +1,165 @@
|
||||
// This file is part of the uutils coreutils package.
|
||||
//
|
||||
// For the full copyright and license information, please view the LICENSE
|
||||
// file that was distributed with this source code.
|
||||
|
||||
use uutests::new_ucmd;
|
||||
use uutests::util::TestScenario;
|
||||
use uutests::util_name;
|
||||
// spell-checker:ignore checkfile, testf, ntestf
|
||||
macro_rules! get_hash(
|
||||
($str:expr) => (
|
||||
$str.split(' ').collect::<Vec<&str>>()[0]
|
||||
);
|
||||
);
|
||||
|
||||
macro_rules! test_digest {
|
||||
($id:ident) => {
|
||||
mod $id {
|
||||
use uutests::util::*;
|
||||
use uutests::util_name;
|
||||
static EXPECTED_FILE: &'static str = concat!(stringify!($id), ".expected");
|
||||
static CHECK_FILE: &'static str = concat!(stringify!($id), ".checkfile");
|
||||
static INPUT_FILE: &'static str = "input.txt";
|
||||
|
||||
#[test]
|
||||
fn test_single_file() {
|
||||
let ts = TestScenario::new(util_name!());
|
||||
assert_eq!(
|
||||
ts.fixtures.read(EXPECTED_FILE),
|
||||
get_hash!(
|
||||
ts.ucmd()
|
||||
.arg(INPUT_FILE)
|
||||
.succeeds()
|
||||
.no_stderr()
|
||||
.stdout_str()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_stdin() {
|
||||
let ts = TestScenario::new(util_name!());
|
||||
assert_eq!(
|
||||
ts.fixtures.read(EXPECTED_FILE),
|
||||
get_hash!(
|
||||
ts.ucmd()
|
||||
.pipe_in_fixture(INPUT_FILE)
|
||||
.succeeds()
|
||||
.no_stderr()
|
||||
.stdout_str()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_check() {
|
||||
let ts = TestScenario::new(util_name!());
|
||||
println!("File content='{}'", ts.fixtures.read(INPUT_FILE));
|
||||
println!("Check file='{}'", ts.fixtures.read(CHECK_FILE));
|
||||
|
||||
ts.ucmd()
|
||||
.args(&["--check", CHECK_FILE])
|
||||
.succeeds()
|
||||
.no_stderr()
|
||||
.stdout_is("input.txt: OK\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_zero() {
|
||||
let ts = TestScenario::new(util_name!());
|
||||
assert_eq!(
|
||||
ts.fixtures.read(EXPECTED_FILE),
|
||||
get_hash!(
|
||||
ts.ucmd()
|
||||
.arg("--zero")
|
||||
.arg(INPUT_FILE)
|
||||
.succeeds()
|
||||
.no_stderr()
|
||||
.stdout_str()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_missing_file() {
|
||||
let ts = TestScenario::new(util_name!());
|
||||
let at = &ts.fixtures;
|
||||
|
||||
at.write("a", "file1\n");
|
||||
at.write("c", "file3\n");
|
||||
|
||||
ts.ucmd()
|
||||
.args(&["a", "b", "c"])
|
||||
.fails()
|
||||
.stdout_contains("a\n")
|
||||
.stdout_contains("c\n")
|
||||
.stderr_contains("b: No such file or directory");
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
test_digest! {sha1}
|
||||
|
||||
#[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("");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_check_file_not_found_warning() {
|
||||
let scene = TestScenario::new(util_name!());
|
||||
let at = &scene.fixtures;
|
||||
|
||||
at.write("testf", "foobar\n");
|
||||
at.write(
|
||||
"testf.sha1",
|
||||
"988881adc9fc3655077dc2d4d757d480b5ea0e11 testf\n",
|
||||
);
|
||||
at.remove("testf");
|
||||
scene
|
||||
.ccmd("sha1sum")
|
||||
.arg("-c")
|
||||
.arg(at.subdir.join("testf.sha1"))
|
||||
.fails()
|
||||
.stdout_is("testf: FAILED open or read\n")
|
||||
.stderr_is("sha1sum: testf: No such file or directory\nsha1sum: WARNING: 1 listed file could not be read\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_invalid_arg() {
|
||||
new_ucmd!().arg("--definitely-invalid").fails_with_code(1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_conflicting_arg() {
|
||||
new_ucmd!().arg("--tag").arg("--check").fails_with_code(1);
|
||||
new_ucmd!().arg("--tag").arg("--text").fails_with_code(1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_help_shows_correct_utility_name() {
|
||||
// Test that help output shows the actual utility name instead of "hashsum"
|
||||
|
||||
new_ucmd!()
|
||||
.arg("--help")
|
||||
.succeeds()
|
||||
.stdout_contains("Usage: sha1sum")
|
||||
.stdout_does_not_contain("Usage: hashsum");
|
||||
}
|
||||
Vendored
+1
@@ -0,0 +1 @@
|
||||
hello, world
|
||||
@@ -76,6 +76,10 @@ mod test_b2sum;
|
||||
#[path = "by-util/test_md5sum.rs"]
|
||||
mod test_md5sum;
|
||||
|
||||
#[cfg(feature = "sha1sum")]
|
||||
#[path = "by-util/test_sha1sum.rs"]
|
||||
mod test_sha1sum;
|
||||
|
||||
#[cfg(feature = "cp")]
|
||||
#[path = "by-util/test_cp.rs"]
|
||||
mod test_cp;
|
||||
|
||||
Reference in New Issue
Block a user