mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-09-16 03:36:18 +00:00
Merge branch 'main' into 2884-time-0.3
This commit is contained in:
commit
9b69e6fd47
35 changed files with 340 additions and 53 deletions
|
@ -31,7 +31,7 @@ fn test_default_output() {
|
|||
scene
|
||||
.ucmd()
|
||||
.succeeds()
|
||||
.stdout_does_not_match(&Regex::new("[rwx][^some-file1]").unwrap());
|
||||
.stdout_does_not_match(&Regex::new("[rwx-]{10}.*some-file1$").unwrap());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -51,5 +51,5 @@ fn test_long_output() {
|
|||
.ucmd()
|
||||
.arg("-l")
|
||||
.succeeds()
|
||||
.stdout_matches(&Regex::new("[rwx][^some-file1]").unwrap());
|
||||
.stdout_matches(&Regex::new("[rwx-]{10}.*some-file1$").unwrap());
|
||||
}
|
||||
|
|
|
@ -411,3 +411,74 @@ fn test_mktemp_directory_tmpdir() {
|
|||
result.no_stderr().stdout_contains("apt-key-gpghome.");
|
||||
assert!(PathBuf::from(result.stdout_str().trim()).is_dir());
|
||||
}
|
||||
|
||||
/// Decide whether a string matches a given template.
|
||||
///
|
||||
/// In the template, the character `'X'` is treated as a wildcard,
|
||||
/// that is, it matches anything. All other characters in `template`
|
||||
/// and `s` must match exactly.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```rust,ignore
|
||||
/// # These all match.
|
||||
/// assert!(matches_template("abc", "abc"));
|
||||
/// assert!(matches_template("aXc", "abc"));
|
||||
/// assert!(matches_template("XXX", "abc"));
|
||||
///
|
||||
/// # None of these match
|
||||
/// assert!(matches_template("abc", "abcd"));
|
||||
/// assert!(matches_template("abc", "ab"));
|
||||
/// assert!(matches_template("aXc", "abd"));
|
||||
/// assert!(matches_template("XXX", "abcd"));
|
||||
/// ```
|
||||
///
|
||||
fn matches_template(template: &str, s: &str) -> bool {
|
||||
if template.len() != s.len() {
|
||||
return false;
|
||||
}
|
||||
for (a, b) in template.chars().zip(s.chars()) {
|
||||
if !(a == 'X' || a == b) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
/// An assertion that uses [`matches_template`] and adds a helpful error message.
|
||||
macro_rules! assert_matches_template {
|
||||
($template:expr, $s:expr) => {{
|
||||
assert!(
|
||||
matches_template($template, $s),
|
||||
"\"{}\" != \"{}\"",
|
||||
$template,
|
||||
$s
|
||||
);
|
||||
}};
|
||||
}
|
||||
|
||||
/// Test that the file is created in the directory given by the template.
|
||||
#[test]
|
||||
fn test_respect_template() {
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
let template = "XXX";
|
||||
let result = ucmd.arg(template).succeeds();
|
||||
let filename = result.no_stderr().stdout_str().trim_end();
|
||||
assert_matches_template!(template, filename);
|
||||
assert!(at.file_exists(filename));
|
||||
}
|
||||
|
||||
/// Test that the file is created in the directory given by the template.
|
||||
#[test]
|
||||
fn test_respect_template_directory() {
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
at.mkdir("d");
|
||||
#[cfg(not(windows))]
|
||||
let template = "d/XXX";
|
||||
#[cfg(windows)]
|
||||
let template = r"d\XXX";
|
||||
let result = ucmd.arg(template).succeeds();
|
||||
let filename = result.no_stderr().stdout_str().trim_end();
|
||||
assert_matches_template!(template, filename);
|
||||
assert!(at.file_exists(filename));
|
||||
}
|
||||
|
|
|
@ -446,6 +446,14 @@ fn sub_any_specifiers_after_period() {
|
|||
.stdout_only("3");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unspecified_left_justify_is_1_width() {
|
||||
new_ucmd!()
|
||||
.args(&["%-o"]) //spell-checker:disable-line
|
||||
.succeeds()
|
||||
.stdout_only("0");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sub_any_specifiers_after_second_param() {
|
||||
new_ucmd!()
|
||||
|
|
|
@ -71,3 +71,35 @@ fn gnu_ext_disabled_ignore_and_only_file() {
|
|||
.succeeds()
|
||||
.stdout_only_fixture("gnu_ext_disabled_ignore_and_only_file.expected");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn gnu_ext_disabled_output_width_50() {
|
||||
new_ucmd!()
|
||||
.args(&["-G", "-w", "50", "input"])
|
||||
.succeeds()
|
||||
.stdout_only_fixture("gnu_ext_disabled_output_width_50.expected");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn gnu_ext_disabled_output_width_70() {
|
||||
new_ucmd!()
|
||||
.args(&["-G", "-w", "70", "input"])
|
||||
.succeeds()
|
||||
.stdout_only_fixture("gnu_ext_disabled_output_width_70.expected");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn gnu_ext_disabled_break_file() {
|
||||
new_ucmd!()
|
||||
.args(&["-G", "-b", "break_file", "input"])
|
||||
.succeeds()
|
||||
.stdout_only_fixture("gnu_ext_disabled_break_file.expected");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn gnu_ext_disabled_empty_word_regexp_ignores_break_file() {
|
||||
new_ucmd!()
|
||||
.args(&["-G", "-b", "break_file", "-R", "-W", "", "input"])
|
||||
.succeeds()
|
||||
.stdout_only_fixture("gnu_ext_disabled_rightward_no_ref.expected");
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ fn test_default_output() {
|
|||
scene
|
||||
.ucmd()
|
||||
.succeeds()
|
||||
.stdout_matches(&Regex::new("[rwx][^some-file1]").unwrap());
|
||||
.stdout_matches(&Regex::new("[rwx-]{10}.*some-file1$").unwrap());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -51,5 +51,5 @@ fn test_column_output() {
|
|||
.ucmd()
|
||||
.arg("-C")
|
||||
.succeeds()
|
||||
.stdout_does_not_match(&Regex::new("[rwx][^some-file1]").unwrap());
|
||||
.stdout_does_not_match(&Regex::new("[rwx-]{10}.*some-file1$").unwrap());
|
||||
}
|
||||
|
|
1
tests/fixtures/ptx/break_file
vendored
Normal file
1
tests/fixtures/ptx/break_file
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
abc_e^-]\
|
42
tests/fixtures/ptx/gnu_ext_disabled_break_file.expected
vendored
Normal file
42
tests/fixtures/ptx/gnu_ext_disabled_break_file.expected
vendored
Normal file
|
@ -0,0 +1,42 @@
|
|||
.xx "" "" """quotes"", for roff" ""
|
||||
.xx "" "and some other like %a, b" "#, c$c" ""
|
||||
.xx "" "and some other like %a, b#, c" "$c" ""
|
||||
.xx "" "and some other like" "%a, b#, c$c" ""
|
||||
.xx "" "and some other like %a" ", b#, c$c" ""
|
||||
.xx "" """quotes""," "for roff" ""
|
||||
.xx "" "{brackets}" "for tex" ""
|
||||
.xx "" "" "hello world!" ""
|
||||
.xx "" "let's c" "heck special characters:" ""
|
||||
.xx "" "let's check special c" "haracters:" ""
|
||||
.xx "" "let's check spec" "ial characters:" ""
|
||||
.xx "" "let's chec" "k special characters:" ""
|
||||
.xx "" "{brac" "kets} for tex" ""
|
||||
.xx "" "oh, and bac" "k\slash" ""
|
||||
.xx "" "" "let's check special characters:" ""
|
||||
.xx "" "let's check specia" "l characters:" ""
|
||||
.xx "" "and some other" "like %a, b#, c$c" ""
|
||||
.xx "" "he" "llo world!" ""
|
||||
.xx "" "maybe a" "lso~or^" ""
|
||||
.xx "" "" "maybe also~or^" ""
|
||||
.xx "" "a" "nd some other like %a, b#, c$c" ""
|
||||
.xx "" "oh, a" "nd back\slash" ""
|
||||
.xx "" "" "oh, and back\slash" ""
|
||||
.xx "" "and some" "other like %a, b#, c$c" ""
|
||||
.xx "" "let's check special cha" "racters:" ""
|
||||
.xx "" "{b" "rackets} for tex" ""
|
||||
.xx "" "and some othe" "r like %a, b#, c$c" ""
|
||||
.xx "" """quotes"", for" "roff" ""
|
||||
.xx "" "let's check special characte" "rs:" ""
|
||||
.xx "" """quote" "s"", for roff" ""
|
||||
.xx "" "oh, and back\sla" "sh" ""
|
||||
.xx "" "oh, and back\" "slash" ""
|
||||
.xx "" "and" "some other like %a, b#, c$c" ""
|
||||
.xx "" "let's check" "special characters:" ""
|
||||
.xx "" "let's check special charac" "ters:" ""
|
||||
.xx "" "{brackets} for" "tex" ""
|
||||
.xx "" "le" "t's check special characters:" ""
|
||||
.xx "" "{bracke" "ts} for tex" ""
|
||||
.xx "" "hello" "world!" ""
|
||||
.xx "" "{brackets} for te" "x" ""
|
||||
.xx "" "ma" "ybe also~or^" ""
|
||||
.xx "" "" "{brackets} for tex" ""
|
24
tests/fixtures/ptx/gnu_ext_disabled_output_width_50.expected
vendored
Normal file
24
tests/fixtures/ptx/gnu_ext_disabled_output_width_50.expected
vendored
Normal file
|
@ -0,0 +1,24 @@
|
|||
.xx "" "" """quotes"", for roff" ""
|
||||
.xx "" "and some other like" "%a, b#, c$c" ""
|
||||
.xx "" "maybe" "also~or^" ""
|
||||
.xx "%a, b#, c$c" "" "and some other like" ""
|
||||
.xx "" "oh," "and back\slash" ""
|
||||
.xx "" "some other like %a," "b#, c$c" "and"
|
||||
.xx "" "oh, and" "back\slash" ""
|
||||
.xx "" "other like %a, b#," "c$c" "and some"
|
||||
.xx "" "let's check special" "characters:" ""
|
||||
.xx "characters:" "let's" "check special" ""
|
||||
.xx "" """quotes""," "for roff" ""
|
||||
.xx "" "{brackets}" "for tex" ""
|
||||
.xx "" "" "hello world!" ""
|
||||
.xx "characters:" "" "let's check special" ""
|
||||
.xx "" "and some other" "like %a, b#, c$c" ""
|
||||
.xx "" "" "maybe also~or^" ""
|
||||
.xx "" "" "oh, and back\slash" ""
|
||||
.xx "" "and some" "other like %a, b#, c$c" ""
|
||||
.xx "" """quotes"", for" "roff" ""
|
||||
.xx "b#, c$c" "and" "some other like %a," ""
|
||||
.xx "" "let's check" "special characters:" ""
|
||||
.xx "" "{brackets} for" "tex" ""
|
||||
.xx "" "hello" "world!" ""
|
||||
.xx "" "" "{brackets} for tex" ""
|
24
tests/fixtures/ptx/gnu_ext_disabled_output_width_70.expected
vendored
Normal file
24
tests/fixtures/ptx/gnu_ext_disabled_output_width_70.expected
vendored
Normal file
|
@ -0,0 +1,24 @@
|
|||
.xx "" "" """quotes"", for roff" ""
|
||||
.xx "" "and some other like" "%a, b#, c$c" ""
|
||||
.xx "" "maybe" "also~or^" ""
|
||||
.xx "" "" "and some other like %a, b#, c$c" ""
|
||||
.xx "" "oh," "and back\slash" ""
|
||||
.xx "" "and some other like %a," "b#, c$c" ""
|
||||
.xx "" "oh, and" "back\slash" ""
|
||||
.xx "" "and some other like %a, b#," "c$c" ""
|
||||
.xx "" "let's check special" "characters:" ""
|
||||
.xx "" "let's" "check special characters:" ""
|
||||
.xx "" """quotes""," "for roff" ""
|
||||
.xx "" "{brackets}" "for tex" ""
|
||||
.xx "" "" "hello world!" ""
|
||||
.xx "" "" "let's check special characters:" ""
|
||||
.xx "" "and some other" "like %a, b#, c$c" ""
|
||||
.xx "" "" "maybe also~or^" ""
|
||||
.xx "" "" "oh, and back\slash" ""
|
||||
.xx "" "and some" "other like %a, b#, c$c" ""
|
||||
.xx "" """quotes"", for" "roff" ""
|
||||
.xx "" "and" "some other like %a, b#, c$c" ""
|
||||
.xx "" "let's check" "special characters:" ""
|
||||
.xx "" "{brackets} for" "tex" ""
|
||||
.xx "" "hello" "world!" ""
|
||||
.xx "" "" "{brackets} for tex" ""
|
Loading…
Add table
Add a link
Reference in a new issue