cksum: implement trivial --tag flag

This commit is contained in:
Ben Wiederhake 2024-03-02 03:14:13 +01:00
parent edb1eb0a76
commit 7b219aee63
2 changed files with 30 additions and 0 deletions

View file

@ -286,6 +286,7 @@ mod options {
pub const ALGORITHM: &str = "algorithm";
pub const FILE: &str = "file";
pub const UNTAGGED: &str = "untagged";
pub const TAG: &str = "tag";
pub const LENGTH: &str = "length";
pub const RAW: &str = "raw";
}
@ -396,6 +397,13 @@ pub fn uu_app() -> Command {
Arg::new(options::UNTAGGED)
.long(options::UNTAGGED)
.help("create a reversed style checksum, without digest type")
.action(ArgAction::SetTrue)
.overrides_with(options::TAG),
)
.arg(
Arg::new(options::TAG)
.long(options::TAG)
.help("create a BSD style checksum, undo --untagged (default)")
.action(ArgAction::SetTrue),
)
.arg(

View file

@ -140,6 +140,17 @@ fn test_repeated_flags() {
.stdout_is_fixture("md5_single_file.expected");
}
#[test]
fn test_tag_after_untagged() {
new_ucmd!()
.arg("--untagged")
.arg("--tag")
.arg("-a=md5")
.arg("lorem_ipsum.txt")
.succeeds()
.stdout_is_fixture("md5_single_file.expected");
}
#[test]
fn test_algorithm_single_file() {
for algo in ALGOS {
@ -220,6 +231,17 @@ fn test_untagged_algorithm_single_file() {
}
}
#[test]
fn test_untagged_algorithm_after_tag() {
new_ucmd!()
.arg("--tag")
.arg("--untagged")
.arg("--algorithm=md5")
.arg("lorem_ipsum.txt")
.succeeds()
.stdout_is_fixture("untagged/md5_single_file.expected");
}
#[test]
fn test_untagged_algorithm_multiple_files() {
for algo in ALGOS {