mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-09-16 03:36:18 +00:00
Merge branch 'main' into tail_notify
This commit is contained in:
commit
e8834597f3
13 changed files with 301 additions and 70 deletions
|
@ -28,6 +28,11 @@ fn test_df_compatible_si() {
|
|||
new_ucmd!().arg("-aH").succeeds();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_df_compatible_sync() {
|
||||
new_ucmd!().arg("--sync").succeeds();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_df_arguments_override_themselves() {
|
||||
new_ucmd!().args(&["--help", "--help"]).succeeds();
|
||||
|
|
|
@ -131,6 +131,25 @@ fn test_exclusive_option() {
|
|||
.stderr_contains("mutually exclusive");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_stdin() {
|
||||
new_ucmd!()
|
||||
.pipe_in("owt 40;33\n")
|
||||
.args(&["-b", "-"])
|
||||
.succeeds()
|
||||
.stdout_is("LS_COLORS='tw=40;33:';\nexport LS_COLORS\n")
|
||||
.no_stderr();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_extra_operand() {
|
||||
new_ucmd!()
|
||||
.args(&["-c", "file1", "file2"])
|
||||
.fails()
|
||||
.stderr_contains("dircolors: extra operand 'file2'\n")
|
||||
.no_stdout();
|
||||
}
|
||||
|
||||
fn test_helper(file_name: &str, term: &str) {
|
||||
new_ucmd!()
|
||||
.env("TERM", term)
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
use crate::common::util::*;
|
||||
use uucore::display::Quotable;
|
||||
// spell-checker:ignore (ToDO) taaaa tbbbb tcccc
|
||||
|
||||
#[test]
|
||||
|
@ -179,6 +180,14 @@ fn test_tabs_must_be_ascending() {
|
|||
.stderr_contains("tab sizes must be ascending");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_tabs_cannot_be_zero() {
|
||||
new_ucmd!()
|
||||
.arg("--tabs=0")
|
||||
.fails()
|
||||
.stderr_contains("tab size cannot be 0");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_tabs_keep_last_trailing_specifier() {
|
||||
// If there are multiple trailing specifiers, use only the last one
|
||||
|
@ -200,3 +209,39 @@ fn test_tabs_comma_separated_no_numbers() {
|
|||
.succeeds()
|
||||
.stdout_is(" a b c");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_tabs_with_specifier_not_at_start() {
|
||||
fn run_cmd(arg: &str, expected_prefix: &str, expected_suffix: &str) {
|
||||
let expected_msg = format!(
|
||||
"{} specifier not at start of number: {}",
|
||||
expected_prefix.quote(),
|
||||
expected_suffix.quote()
|
||||
);
|
||||
new_ucmd!().arg(arg).fails().stderr_contains(expected_msg);
|
||||
}
|
||||
run_cmd("--tabs=1/", "/", "/");
|
||||
run_cmd("--tabs=1/2", "/", "/2");
|
||||
run_cmd("--tabs=1+", "+", "+");
|
||||
run_cmd("--tabs=1+2", "+", "+2");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_tabs_with_invalid_chars() {
|
||||
new_ucmd!()
|
||||
.arg("--tabs=x")
|
||||
.fails()
|
||||
.stderr_contains("tab size contains invalid character(s): 'x'");
|
||||
new_ucmd!()
|
||||
.arg("--tabs=1x2")
|
||||
.fails()
|
||||
.stderr_contains("tab size contains invalid character(s): 'x2'");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_tabs_with_too_large_size() {
|
||||
let arg = format!("--tabs={}", u128::MAX);
|
||||
let expected_error = format!("tab stop is too large '{}'", u128::MAX);
|
||||
|
||||
new_ucmd!().arg(arg).fails().stderr_contains(expected_error);
|
||||
}
|
||||
|
|
|
@ -2324,6 +2324,20 @@ fn test_ls_quoting_style() {
|
|||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_ls_quoting_and_color() {
|
||||
let scene = TestScenario::new(util_name!());
|
||||
let at = &scene.fixtures;
|
||||
|
||||
at.touch("one two");
|
||||
scene
|
||||
.ucmd()
|
||||
.arg("--color")
|
||||
.arg("one two")
|
||||
.succeeds()
|
||||
.stdout_only("'one two'\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_ls_ignore_hide() {
|
||||
let scene = TestScenario::new(util_name!());
|
||||
|
|
|
@ -27,6 +27,18 @@ const TMPDIR: &str = "TMPDIR";
|
|||
#[cfg(windows)]
|
||||
const TMPDIR: &str = "TMP";
|
||||
|
||||
/// 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]
|
||||
fn test_mktemp_mktemp() {
|
||||
let scene = TestScenario::new(util_name!());
|
||||
|
@ -417,6 +429,21 @@ fn test_mktemp_directory_tmpdir() {
|
|||
assert!(PathBuf::from(result.stdout_str().trim()).is_dir());
|
||||
}
|
||||
|
||||
/// Test for combining `--tmpdir` and a template with a subdirectory.
|
||||
#[test]
|
||||
fn test_tmpdir_template_has_subdirectory() {
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
at.mkdir("a");
|
||||
#[cfg(not(windows))]
|
||||
let (template, joined) = ("a/bXXXX", "./a/bXXXX");
|
||||
#[cfg(windows)]
|
||||
let (template, joined) = (r"a\bXXXX", r".\a\bXXXX");
|
||||
let result = ucmd.args(&["--tmpdir=.", template]).succeeds();
|
||||
let filename = result.no_stderr().stdout_str().trim_end();
|
||||
assert_matches_template!(joined, filename);
|
||||
assert!(at.file_exists(filename));
|
||||
}
|
||||
|
||||
/// Test that an absolute path is disallowed when --tmpdir is provided.
|
||||
#[test]
|
||||
fn test_tmpdir_absolute_path() {
|
||||
|
@ -466,18 +493,6 @@ fn matches_template(template: &str, s: &str) -> bool {
|
|||
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() {
|
||||
|
@ -550,6 +565,16 @@ fn test_suffix_path_separator() {
|
|||
.arg(r"aXXX\b")
|
||||
.fails()
|
||||
.stderr_only("mktemp: invalid suffix '\\b', contains directory separator\n");
|
||||
#[cfg(not(windows))]
|
||||
new_ucmd!()
|
||||
.arg("XXX/..")
|
||||
.fails()
|
||||
.stderr_only("mktemp: invalid suffix '/..', contains directory separator\n");
|
||||
#[cfg(windows)]
|
||||
new_ucmd!()
|
||||
.arg(r"XXX\..")
|
||||
.fails()
|
||||
.stderr_only("mktemp: invalid suffix '\\..', contains directory separator\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -572,3 +597,25 @@ fn test_too_few_xs_suffix_directory() {
|
|||
fn test_too_many_arguments() {
|
||||
new_ucmd!().args(&["-q", "a", "b"]).fails().code_is(1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_two_contiguous_wildcard_blocks() {
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
let template = "XXX_XXX";
|
||||
let result = ucmd.arg(template).succeeds();
|
||||
let filename = result.no_stderr().stdout_str().trim_end();
|
||||
assert_eq!(&filename[..4], "XXX_");
|
||||
assert_matches_template!(template, filename);
|
||||
assert!(at.file_exists(filename));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_three_contiguous_wildcard_blocks() {
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
let template = "XXX_XXX_XXX";
|
||||
let result = ucmd.arg(template).succeeds();
|
||||
let filename = result.no_stderr().stdout_str().trim_end();
|
||||
assert_eq!(&filename[..8], "XXX_XXX_");
|
||||
assert_matches_template!(template, filename);
|
||||
assert!(at.file_exists(filename));
|
||||
}
|
||||
|
|
|
@ -1738,7 +1738,7 @@ fn test_follow_name_truncate4() {
|
|||
|
||||
let mut args = vec!["-s.1", "--max-unchanged-stats=1", "-F", "file"];
|
||||
|
||||
let delay = 100;
|
||||
let delay = 300;
|
||||
for _ in 0..2 {
|
||||
at.append("file", "foobar\n");
|
||||
|
||||
|
@ -1761,7 +1761,7 @@ fn test_follow_name_truncate4() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(unix)]
|
||||
#[cfg(all(unix, not(target_os = "android")))] // NOTE: Should work on Android but CI VM is too slow.
|
||||
fn test_follow_truncate_fast() {
|
||||
// inspired by: "gnu/tests/tail-2/truncate.sh"
|
||||
// Ensure all logs are output upon file truncation
|
||||
|
@ -1775,7 +1775,7 @@ fn test_follow_truncate_fast() {
|
|||
let mut args = vec!["-s.1", "--max-unchanged-stats=1", "f", "---disable-inotify"];
|
||||
let follow = vec!["-f", "-F"];
|
||||
|
||||
let delay = 100;
|
||||
let delay = 150;
|
||||
for _ in 0..2 {
|
||||
for mode in &follow {
|
||||
args.push(mode);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue