1
Fork 0
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:
Jan Scheer 2022-05-23 01:10:32 +02:00
commit dc4b6f2cf9
No known key found for this signature in database
GPG key ID: C62AD4C29E2B9828
121 changed files with 657 additions and 520 deletions

View file

@ -1301,6 +1301,59 @@ fn test_ls_deref() {
assert!(!re.is_match(result.stdout_str().trim()));
}
#[test]
fn test_ls_group_directories_first() {
let scene = TestScenario::new(util_name!());
let at = &scene.fixtures;
let mut filenames = ["file1", "file2", "anotherFile", "abc", "xxx", "zzz"];
for filename in filenames {
at.touch(filename);
}
filenames.sort_unstable();
let dirnames = ["aaa", "bbb", "ccc", "yyy"];
for dirname in dirnames {
at.mkdir(dirname);
}
let dots = [".", ".."];
let result = scene
.ucmd()
.arg("-1a")
.arg("--group-directories-first")
.run();
assert_eq!(
result.stdout_str().split('\n').collect::<Vec<_>>(),
dots.into_iter()
.chain(dirnames.into_iter())
.chain(filenames.into_iter())
.chain([""].into_iter())
.collect::<Vec<_>>(),
);
let result = scene
.ucmd()
.arg("-1ar")
.arg("--group-directories-first")
.run();
assert_eq!(
result.stdout_str().split('\n').collect::<Vec<_>>(),
(dirnames.into_iter().rev())
.chain(dots.into_iter().rev())
.chain(filenames.into_iter().rev())
.chain([""].into_iter())
.collect::<Vec<_>>(),
);
let result = scene
.ucmd()
.arg("-1aU")
.arg("--group-directories-first")
.run();
let result2 = scene.ucmd().arg("-1aU").run();
assert_eq!(result.stdout_str(), result2.stdout_str());
}
#[test]
fn test_ls_sort_none() {
let scene = TestScenario::new(util_name!());
@ -2107,7 +2160,7 @@ fn test_ls_version_sort() {
);
let result = scene.ucmd().arg("-a1v").succeeds();
expected.insert(0, "..");
expected.insert(expected.len() - 1, "..");
expected.insert(0, ".");
assert_eq!(
result.stdout_str().split('\n').collect::<Vec<_>>(),

View file

@ -414,6 +414,22 @@ fn test_mktemp_directory_tmpdir() {
assert!(PathBuf::from(result.stdout_str().trim()).is_dir());
}
/// Test that an absolute path is disallowed when --tmpdir is provided.
#[test]
fn test_tmpdir_absolute_path() {
#[cfg(windows)]
let path = r"C:\XXX";
#[cfg(not(windows))]
let path = "/XXX";
new_ucmd!()
.args(&["--tmpdir=a", path])
.fails()
.stderr_only(format!(
"mktemp: invalid template, '{}'; with --tmpdir, it may not be absolute\n",
path
));
}
/// Decide whether a string matches a given template.
///
/// In the template, the character `'X'` is treated as a wildcard,
@ -496,3 +512,18 @@ fn test_template_path_separator() {
"a/bXXX".quote()
));
}
/// Test that a suffix with a path separator is invalid.
#[test]
fn test_suffix_path_separator() {
#[cfg(not(windows))]
new_ucmd!()
.arg("aXXX/b")
.fails()
.stderr_only("mktemp: invalid suffix '/b', contains directory separator\n");
#[cfg(windows)]
new_ucmd!()
.arg(r"aXXX\b")
.fails()
.stderr_only("mktemp: invalid suffix '\\b', contains directory separator\n");
}

View file

@ -641,6 +641,20 @@ fn test_mv_target_dir() {
assert!(at.file_exists(&format!("{}/{}", dir, file_b)));
}
#[test]
fn test_mv_target_dir_single_source() {
let (at, mut ucmd) = at_and_ucmd!();
let dir = "test_mv_target_dir_single_source_dir";
let file = "test_mv_target_dir_single_source_file";
at.touch(file);
at.mkdir(dir);
ucmd.arg("-t").arg(dir).arg(file).succeeds().no_stderr();
assert!(!at.file_exists(file));
assert!(at.file_exists(&format!("{}/{}", dir, file)));
}
#[test]
fn test_mv_overwrite_dir() {
let (at, mut ucmd) = at_and_ucmd!();