Skip to content

Commit

Permalink
add some tests for Clap's InferLongArgs setting
Browse files Browse the repository at this point in the history
  • Loading branch information
tertsdiepraam committed Jan 29, 2022
1 parent 5f1933a commit 2412e4c
Show file tree
Hide file tree
Showing 11 changed files with 166 additions and 110 deletions.
6 changes: 3 additions & 3 deletions tests/by-util/test_base32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ fn test_base32_encode_file() {

#[test]
fn test_decode() {
for decode_param in &["-d", "--decode"] {
for decode_param in &["-d", "--decode", "--dec"] {
let input = "JBSWY3DPFQQFO33SNRSCC===\n"; // spell-checker:disable-line
new_ucmd!()
.arg(decode_param)
Expand All @@ -56,7 +56,7 @@ fn test_garbage() {

#[test]
fn test_ignore_garbage() {
for ignore_garbage_param in &["-i", "--ignore-garbage"] {
for ignore_garbage_param in &["-i", "--ignore-garbage", "--ig"] {
let input = "JBSWY\x013DPFQ\x02QFO33SNRSCC===\n"; // spell-checker:disable-line
new_ucmd!()
.arg("-d")
Expand All @@ -69,7 +69,7 @@ fn test_ignore_garbage() {

#[test]
fn test_wrap() {
for wrap_param in &["-w", "--wrap"] {
for wrap_param in &["-w", "--wrap", "--wr"] {
let input = "The quick brown fox jumps over the lazy dog.";
new_ucmd!()
.arg(wrap_param)
Expand Down
6 changes: 3 additions & 3 deletions tests/by-util/test_base64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ fn test_base64_encode_file() {

#[test]
fn test_decode() {
for decode_param in &["-d", "--decode"] {
for decode_param in &["-d", "--decode", "--dec"] {
let input = "aGVsbG8sIHdvcmxkIQ=="; // spell-checker:disable-line
new_ucmd!()
.arg(decode_param)
Expand All @@ -48,7 +48,7 @@ fn test_garbage() {

#[test]
fn test_ignore_garbage() {
for ignore_garbage_param in &["-i", "--ignore-garbage"] {
for ignore_garbage_param in &["-i", "--ignore-garbage", "--ig"] {
let input = "aGVsbG8sIHdvcmxkIQ==\0"; // spell-checker:disable-line
new_ucmd!()
.arg("-d")
Expand All @@ -61,7 +61,7 @@ fn test_ignore_garbage() {

#[test]
fn test_wrap() {
for wrap_param in &["-w", "--wrap"] {
for wrap_param in &["-w", "--wrap", "--wr"] {
let input = "The quick brown fox jumps over the lazy dog.";
new_ucmd!()
.arg(wrap_param)
Expand Down
6 changes: 3 additions & 3 deletions tests/by-util/test_basename.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ fn test_do_not_remove_suffix() {

#[test]
fn test_multiple_param() {
for &multiple_param in &["-a", "--multiple"] {
for &multiple_param in &["-a", "--multiple", "--mul"] {
let path = "/foo/bar/baz";
new_ucmd!()
.args(&[multiple_param, path, path])
Expand All @@ -72,7 +72,7 @@ fn test_multiple_param() {

#[test]
fn test_suffix_param() {
for &suffix_param in &["-s", "--suffix"] {
for &suffix_param in &["-s", "--suffix", "--suf"] {
let path = "/foo/bar/baz.exe";
new_ucmd!()
.args(&[suffix_param, ".exe", path, path])
Expand All @@ -83,7 +83,7 @@ fn test_suffix_param() {

#[test]
fn test_zero_param() {
for &zero_param in &["-z", "--zero"] {
for &zero_param in &["-z", "--zero", "--ze"] {
let path = "/foo/bar/baz";
new_ucmd!()
.args(&[zero_param, "-a", path, path])
Expand Down
12 changes: 6 additions & 6 deletions tests/by-util/test_cat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ fn test_numbered_lines_no_trailing_newline() {

#[test]
fn test_stdin_show_nonprinting() {
for same_param in &["-v", "--show-nonprinting"] {
for same_param in &["-v", "--show-nonprinting", "--show-non"] {
new_ucmd!()
.args(&[same_param])
.pipe_in("\t\0\n")
Expand All @@ -275,7 +275,7 @@ fn test_stdin_show_nonprinting() {

#[test]
fn test_stdin_show_tabs() {
for same_param in &["-T", "--show-tabs"] {
for same_param in &["-T", "--show-tabs", "--show-ta"] {
new_ucmd!()
.args(&[same_param])
.pipe_in("\t\0\n")
Expand All @@ -286,7 +286,7 @@ fn test_stdin_show_tabs() {

#[test]
fn test_stdin_show_ends() {
for &same_param in &["-E", "--show-ends"] {
for &same_param in &["-E", "--show-ends", "--show-e"] {
new_ucmd!()
.args(&[same_param, "-"])
.pipe_in("\t\0\n\t")
Expand Down Expand Up @@ -317,7 +317,7 @@ fn test_show_ends_crlf() {

#[test]
fn test_stdin_show_all() {
for same_param in &["-A", "--show-all"] {
for same_param in &["-A", "--show-all", "--show-a"] {
new_ucmd!()
.args(&[same_param])
.pipe_in("\t\0\n")
Expand Down Expand Up @@ -346,7 +346,7 @@ fn test_stdin_nonprinting_and_tabs() {

#[test]
fn test_stdin_squeeze_blank() {
for same_param in &["-s", "--squeeze-blank"] {
for same_param in &["-s", "--squeeze-blank", "--squeeze"] {
new_ucmd!()
.arg(same_param)
.pipe_in("\n\na\n\n\n\n\nb\n\n\n")
Expand All @@ -358,7 +358,7 @@ fn test_stdin_squeeze_blank() {
#[test]
fn test_stdin_number_non_blank() {
// spell-checker:disable-next-line
for same_param in &["-b", "--number-nonblank"] {
for same_param in &["-b", "--number-nonblank", "--number-non"] {
new_ucmd!()
.arg(same_param)
.arg("-")
Expand Down
2 changes: 1 addition & 1 deletion tests/by-util/test_chgrp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ fn test_1() {
#[test]
fn test_fail_silently() {
if get_effective_gid() != 0 {
for opt in &["-f", "--silent", "--quiet"] {
for opt in &["-f", "--silent", "--quiet", "--sil", "--qui"] {
new_ucmd!()
.arg(opt)
.arg("bin")
Expand Down
13 changes: 12 additions & 1 deletion tests/by-util/test_cp.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// spell-checker:ignore (flags) reflink (fs) tmpfs (linux) rlimit Rlim NOFILE
// spell-checker:ignore (flags) reflink (fs) tmpfs (linux) rlimit Rlim NOFILE clob

use crate::common::util::*;
#[cfg(not(windows))]
Expand Down Expand Up @@ -227,6 +227,17 @@ fn test_cp_arg_no_clobber() {
assert_eq!(at.read(TEST_HOW_ARE_YOU_SOURCE), "How are you?\n");
}

#[test]
fn test_cp_arg_no_clobber_inferred_arg() {
let (at, mut ucmd) = at_and_ucmd!();
ucmd.arg(TEST_HELLO_WORLD_SOURCE)
.arg(TEST_HOW_ARE_YOU_SOURCE)
.arg("--no-clob")
.succeeds();

assert_eq!(at.read(TEST_HOW_ARE_YOU_SOURCE), "How are you?\n");
}

#[test]
fn test_cp_arg_no_clobber_twice() {
let scene = TestScenario::new(util_name!());
Expand Down
33 changes: 23 additions & 10 deletions tests/by-util/test_cut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ static COMPLEX_SEQUENCE: &TestedSequence = &TestedSequence {

#[test]
fn test_byte_sequence() {
for &param in &["-b", "--bytes"] {
for &param in &["-b", "--bytes", "--byt"] {
for example_seq in EXAMPLE_SEQUENCES {
new_ucmd!()
.args(&[param, example_seq.sequence, INPUT])
Expand All @@ -53,7 +53,7 @@ fn test_byte_sequence() {

#[test]
fn test_char_sequence() {
for &param in &["-c", "--characters"] {
for &param in &["-c", "--characters", "--char"] {
for example_seq in EXAMPLE_SEQUENCES {
//as of coreutils 8.25 a char range is effectively the same as a byte range; there is no distinct treatment of utf8 chars.
new_ucmd!()
Expand All @@ -66,7 +66,7 @@ fn test_char_sequence() {

#[test]
fn test_field_sequence() {
for &param in &["-f", "--fields"] {
for &param in &["-f", "--fields", "--fie"] {
for example_seq in EXAMPLE_SEQUENCES {
new_ucmd!()
.args(&[param, example_seq.sequence, INPUT])
Expand All @@ -78,7 +78,7 @@ fn test_field_sequence() {

#[test]
fn test_specify_delimiter() {
for &param in &["-d", "--delimiter"] {
for &param in &["-d", "--delimiter", "--del"] {
new_ucmd!()
.args(&[param, ":", "-f", COMPLEX_SEQUENCE.sequence, INPUT])
.succeeds()
Expand All @@ -100,15 +100,28 @@ fn test_output_delimiter() {
])
.succeeds()
.stdout_only_fixture("output_delimiter.expected");

new_ucmd!()
.args(&[
"-d:",
"--output-del=@",
"-f",
COMPLEX_SEQUENCE.sequence,
INPUT,
])
.succeeds()
.stdout_only_fixture("output_delimiter.expected");
}

#[test]
fn test_complement() {
new_ucmd!()
.args(&["-d_", "--complement", "-f", "2"])
.pipe_in("9_1\n8_2\n7_3")
.succeeds()
.stdout_only("9\n8\n7\n");
for param in &["--complement", "--com"] {
new_ucmd!()
.args(&["-d_", param, "-f", "2"])
.pipe_in("9_1\n8_2\n7_3")
.succeeds()
.stdout_only("9\n8\n7\n");
}
}

#[test]
Expand All @@ -122,7 +135,7 @@ fn test_zero_terminated() {

#[test]
fn test_only_delimited() {
for param in &["-s", "--only-delimited"] {
for param in &["-s", "--only-delimited", "--only-del"] {
new_ucmd!()
.args(&["-d_", param, "-f", "1"])
.pipe_in("91\n82\n7_3")
Expand Down
48 changes: 24 additions & 24 deletions tests/by-util/test_date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,9 @@ use rust_users::*;

#[test]
fn test_date_email() {
new_ucmd!().arg("--rfc-email").succeeds();
}

#[test]
fn test_date_email2() {
new_ucmd!().arg("-R").succeeds();
for param in &["--rfc-email", "--rfc-e", "-R"] {
new_ucmd!().arg(param).succeeds();
}
}

#[test]
Expand All @@ -26,37 +23,40 @@ fn test_date_rfc_3339() {
let re = Regex::new(rfc_regexp).unwrap();

// Check that the output matches the regexp
scene
.ucmd()
.arg("--rfc-3339=ns")
.succeeds()
.stdout_matches(&re);
for param in &["--rfc-3339", "--rfc-3"] {
scene
.ucmd()
.arg(format!("{}=ns", param))
.succeeds()
.stdout_matches(&re);

scene
.ucmd()
.arg("--rfc-3339=seconds")
.succeeds()
.stdout_matches(&re);
scene
.ucmd()
.arg(format!("{}=seconds", param))
.succeeds()
.stdout_matches(&re);
}
}

#[test]
fn test_date_rfc_8601() {
new_ucmd!().arg("--iso-8601=ns").succeeds();
for param in &["--iso-8601", "--i"] {
new_ucmd!().arg(format!("{}=ns", param)).succeeds();
}
}

#[test]
fn test_date_rfc_8601_second() {
new_ucmd!().arg("--iso-8601=second").succeeds();
for param in &["--iso-8601", "--i"] {
new_ucmd!().arg(format!("{}=second", param)).succeeds();
}
}

#[test]
fn test_date_utc() {
new_ucmd!().arg("--utc").succeeds();
}

#[test]
fn test_date_universal() {
new_ucmd!().arg("--universal").succeeds();
for param in &["--universal", "--utc", "--uni", "--u"] {
new_ucmd!().arg(param).succeeds();
}
}

#[test]
Expand Down
5 changes: 5 additions & 0 deletions tests/by-util/test_df.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ fn test_df_compatible_no_size_arg() {
new_ucmd!().arg("-a").succeeds();
}

#[test]
fn test_df_shortened_long_argument() {
new_ucmd!().arg("--a").succeeds();
}

#[test]
fn test_df_compatible() {
new_ucmd!().arg("-ah").succeeds();
Expand Down
Loading

0 comments on commit 2412e4c

Please sign in to comment.