1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-09-15 11:36:16 +00:00

mv: resolve merge conflict

This commit is contained in:
John Shin 2023-04-30 20:09:32 -07:00
commit 85ded232bc
35 changed files with 550 additions and 209 deletions

View file

@ -334,6 +334,29 @@ fn test_invalid_format_string() {
assert!(result.stderr_str().starts_with("date: invalid format "));
}
#[test]
fn test_date_string_human() {
let date_formats = vec![
"1 year ago",
"1 year",
"2 months ago",
"15 days ago",
"1 week ago",
"5 hours ago",
"30 minutes ago",
"10 seconds",
];
let re = Regex::new(r"^\d{4}-\d{2}-\d{2} \d{2}:\d{2}\n$").unwrap();
for date_format in date_formats {
new_ucmd!()
.arg("-d")
.arg(date_format)
.arg("+%Y-%m-%d %S:%M")
.succeeds()
.stdout_matches(&re);
}
}
#[test]
fn test_invalid_date_string() {
new_ucmd!()

View file

@ -1,6 +1,6 @@
// spell-checker:ignore (words) READMECAREFULLY birthtime doesntexist oneline somebackup lrwx somefile somegroup somehiddenbackup somehiddenfile tabsize aaaaaaaa bbbb cccc dddddddd ncccc
#[cfg(feature = "feat_selinux")]
#[cfg(any(unix, feature = "feat_selinux"))]
use crate::common::util::expected_result;
use crate::common::util::TestScenario;
#[cfg(all(unix, feature = "chmod"))]
@ -1276,7 +1276,7 @@ fn test_ls_long_formats() {
// Zero or one "." for indicating a file with security context
// Regex for three names, so all of author, group and owner
let re_three = Regex::new(r"[xrw-]{9}\.? \d ([-0-9_a-z_A-Z]+ ){3}0").unwrap();
let re_three = Regex::new(r"[xrw-]{9}\.? \d ([-0-9_a-z.A-Z]+ ){3}0").unwrap();
#[cfg(unix)]
let re_three_num = Regex::new(r"[xrw-]{9}\.? \d (\d+ ){3}0").unwrap();
@ -1285,13 +1285,13 @@ fn test_ls_long_formats() {
// - group and owner
// - author and owner
// - author and group
let re_two = Regex::new(r"[xrw-]{9}\.? \d ([-0-9_a-z_A-Z]+ ){2}0").unwrap();
let re_two = Regex::new(r"[xrw-]{9}\.? \d ([-0-9_a-z.A-Z]+ ){2}0").unwrap();
#[cfg(unix)]
let re_two_num = Regex::new(r"[xrw-]{9}\.? \d (\d+ ){2}0").unwrap();
// Regex for one name: author, group or owner
let re_one = Regex::new(r"[xrw-]{9}\.? \d [-0-9_a-z_A-Z]+ 0").unwrap();
let re_one = Regex::new(r"[xrw-]{9}\.? \d [-0-9_a-z.A-Z]+ 0").unwrap();
#[cfg(unix)]
let re_one_num = Regex::new(r"[xrw-]{9}\.? \d \d+ 0").unwrap();
@ -1640,88 +1640,103 @@ fn test_ls_styles() {
at.touch("test");
let re_full = Regex::new(
r"[a-z-]* \d* \w* \w* \d* \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d* (\+|\-)\d{4} test\n",
r"[a-z-]* \d* [\w.]* [\w.]* \d* \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d* (\+|\-)\d{4} test\n",
)
.unwrap();
let re_long =
Regex::new(r"[a-z-]* \d* \w* \w* \d* \d{4}-\d{2}-\d{2} \d{2}:\d{2} test\n").unwrap();
let re_iso = Regex::new(r"[a-z-]* \d* \w* \w* \d* \d{2}-\d{2} \d{2}:\d{2} test\n").unwrap();
Regex::new(r"[a-z-]* \d* [\w.]* [\w.]* \d* \d{4}-\d{2}-\d{2} \d{2}:\d{2} test\n").unwrap();
let re_iso =
Regex::new(r"[a-z-]* \d* [\w.]* [\w.]* \d* \d{2}-\d{2} \d{2}:\d{2} test\n").unwrap();
let re_locale =
Regex::new(r"[a-z-]* \d* \w* \w* \d* [A-Z][a-z]{2} ( |\d)\d \d{2}:\d{2} test\n").unwrap();
let re_custom_format = Regex::new(r"[a-z-]* \d* \w* \w* \d* \d{4}__\d{2} test\n").unwrap();
Regex::new(r"[a-z-]* \d* [\w.]* [\w.]* \d* [A-Z][a-z]{2} ( |\d)\d \d{2}:\d{2} test\n")
.unwrap();
let re_custom_format =
Regex::new(r"[a-z-]* \d* [\w.]* [\w.]* \d* \d{4}__\d{2} test\n").unwrap();
//full-iso
let result = scene
scene
.ucmd()
.arg("-l")
.arg("--time-style=full-iso")
.succeeds();
assert!(re_full.is_match(result.stdout_str()));
.succeeds()
.stdout_matches(&re_full);
//long-iso
let result = scene
scene
.ucmd()
.arg("-l")
.arg("--time-style=long-iso")
.succeeds();
assert!(re_long.is_match(result.stdout_str()));
.succeeds()
.stdout_matches(&re_long);
//iso
let result = scene.ucmd().arg("-l").arg("--time-style=iso").succeeds();
assert!(re_iso.is_match(result.stdout_str()));
scene
.ucmd()
.arg("-l")
.arg("--time-style=iso")
.succeeds()
.stdout_matches(&re_iso);
//locale
let result = scene.ucmd().arg("-l").arg("--time-style=locale").succeeds();
assert!(re_locale.is_match(result.stdout_str()));
scene
.ucmd()
.arg("-l")
.arg("--time-style=locale")
.succeeds()
.stdout_matches(&re_locale);
//+FORMAT
let result = scene
scene
.ucmd()
.arg("-l")
.arg("--time-style=+%Y__%M")
.succeeds();
assert!(re_custom_format.is_match(result.stdout_str()));
.succeeds()
.stdout_matches(&re_custom_format);
// Also fails due to not having full clap support for time_styles
scene.ucmd().arg("-l").arg("-time-style=invalid").fails();
//Overwrite options tests
let result = scene
scene
.ucmd()
.arg("-l")
.arg("--time-style=long-iso")
.arg("--time-style=iso")
.succeeds();
assert!(re_iso.is_match(result.stdout_str()));
let result = scene
.succeeds()
.stdout_matches(&re_iso);
scene
.ucmd()
.arg("--time-style=iso")
.arg("--full-time")
.succeeds();
assert!(re_full.is_match(result.stdout_str()));
let result = scene
.succeeds()
.stdout_matches(&re_full);
scene
.ucmd()
.arg("--full-time")
.arg("--time-style=iso")
.succeeds();
assert!(re_iso.is_match(result.stdout_str()));
.succeeds()
.stdout_matches(&re_iso);
let result = scene
scene
.ucmd()
.arg("--full-time")
.arg("--time-style=iso")
.arg("--full-time")
.succeeds();
assert!(re_full.is_match(result.stdout_str()));
.succeeds()
.stdout_matches(&re_full);
let result = scene
scene
.ucmd()
.arg("--full-time")
.arg("-x")
.arg("-l")
.succeeds();
assert!(re_full.is_match(result.stdout_str()));
.succeeds()
.stdout_matches(&re_full);
at.touch("test2");
let result = scene.ucmd().arg("--full-time").arg("-x").succeeds();
assert_eq!(result.stdout_str(), "test test2\n");
scene
.ucmd()
.arg("--full-time")
.arg("-x")
.succeeds()
.stdout_is("test test2\n");
}
#[test]
@ -1776,9 +1791,15 @@ fn test_ls_order_time() {
at.open("test-4").metadata().unwrap().accessed().unwrap();
// It seems to be dependent on the platform whether the access time is actually set
#[cfg(all(unix, not(target_os = "android")))]
result.stdout_only("test-3\ntest-4\ntest-2\ntest-1\n");
#[cfg(any(windows, target_os = "android"))]
#[cfg(unix)]
{
let expected = unwrap_or_return!(expected_result(&scene, &["-t", arg]));
at.open("test-3").metadata().unwrap().accessed().unwrap();
at.open("test-4").metadata().unwrap().accessed().unwrap();
result.stdout_only(expected.stdout_str());
}
#[cfg(windows)]
result.stdout_only("test-4\ntest-3\ntest-2\ntest-1\n");
}

View file

@ -23,6 +23,7 @@ static TEST_TEMPLATE7: &str = "XXXtemplate"; // spell-checker:disable-line
static TEST_TEMPLATE8: &str = "tempXXXl/ate";
#[cfg(windows)]
static TEST_TEMPLATE8: &str = "tempXXXl\\ate";
static TEST_TEMPLATE9: &str = "a.XXXX";
#[cfg(not(windows))]
const TMPDIR: &str = "TMPDIR";
@ -569,6 +570,34 @@ fn test_template_path_separator() {
));
}
/// Test that a prefix with a point is valid.
#[test]
fn test_prefix_template_separator() {
new_ucmd!()
.args(&["-p", ".", "-t", TEST_TEMPLATE9])
.succeeds();
}
#[test]
fn test_prefix_template_with_path_separator() {
#[cfg(not(windows))]
new_ucmd!()
.args(&["-t", "a/XXX"])
.fails()
.stderr_only(format!(
"mktemp: invalid template, {}, contains directory separator\n",
"a/XXX".quote()
));
#[cfg(windows)]
new_ucmd!()
.args(&["-t", r"a\XXX"])
.fails()
.stderr_only(format!(
"mktemp: invalid template, {}, contains directory separator\n",
r"a\XXX".quote()
));
}
/// Test that a suffix with a path separator is invalid.
#[test]
fn test_suffix_path_separator() {

View file

@ -57,6 +57,63 @@ fn test_mv_move_file_into_dir() {
assert!(at.file_exists(format!("{dir}/{file}")));
}
#[test]
fn test_mv_move_file_into_dir_with_target_arg() {
let (at, mut ucmd) = at_and_ucmd!();
let dir = "test_mv_move_file_into_dir_with_target_arg_dir";
let file = "test_mv_move_file_into_dir_with_target_arg_file";
at.mkdir(dir);
at.touch(file);
ucmd.arg("--target")
.arg(dir)
.arg(file)
.succeeds()
.no_stderr();
assert!(at.file_exists(format!("{dir}/{file}")))
}
#[test]
fn test_mv_move_file_into_file_with_target_arg() {
let (at, mut ucmd) = at_and_ucmd!();
let file1 = "test_mv_move_file_into_file_with_target_arg_file1";
let file2 = "test_mv_move_file_into_file_with_target_arg_file2";
at.touch(file1);
at.touch(file2);
ucmd.arg("--target")
.arg(file1)
.arg(file2)
.fails()
.stderr_is(format!("mv: target directory '{file1}': Not a directory\n"));
assert!(at.file_exists(file1))
}
#[test]
fn test_mv_move_multiple_files_into_file() {
let (at, mut ucmd) = at_and_ucmd!();
let file1 = "test_mv_move_multiple_files_into_file1";
let file2 = "test_mv_move_multiple_files_into_file2";
let file3 = "test_mv_move_multiple_files_into_file3";
at.touch(file1);
at.touch(file2);
at.touch(file3);
ucmd.arg(file1)
.arg(file2)
.arg(file3)
.fails()
.stderr_is(format!("mv: target '{file3}': Not a directory\n"));
assert!(at.file_exists(file1));
assert!(at.file_exists(file2));
}
#[test]
fn test_mv_move_file_between_dirs() {
let (at, mut ucmd) = at_and_ucmd!();
@ -234,8 +291,9 @@ fn test_mv_no_clobber() {
ucmd.arg("-n")
.arg(file_a)
.arg(file_b)
.succeeds()
.no_stderr();
.fails()
.code_is(1)
.stderr_only(format!("mv: not replacing '{file_b}'\n"));
assert!(at.file_exists(file_a));
assert!(at.file_exists(file_b));
@ -909,7 +967,9 @@ fn test_mv_backup_dir() {
.arg(dir_a)
.arg(dir_b)
.succeeds()
.stdout_only(format!("'{dir_a}' -> '{dir_b}' (backup: '{dir_b}~')\n"));
.stdout_only(format!(
"renamed '{dir_a}' -> '{dir_b}' (backup: '{dir_b}~')\n"
));
assert!(!at.dir_exists(dir_a));
assert!(at.dir_exists(dir_b));
@ -981,7 +1041,7 @@ fn test_mv_verbose() {
.arg(file_a)
.arg(file_b)
.succeeds()
.stdout_only(format!("'{file_a}' -> '{file_b}'\n"));
.stdout_only(format!("renamed '{file_a}' -> '{file_b}'\n"));
at.touch(file_a);
scene
@ -990,7 +1050,9 @@ fn test_mv_verbose() {
.arg(file_a)
.arg(file_b)
.succeeds()
.stdout_only(format!("'{file_a}' -> '{file_b}' (backup: '{file_b}~')\n"));
.stdout_only(format!(
"renamed '{file_a}' -> '{file_b}' (backup: '{file_b}~')\n"
));
}
#[test]

View file

@ -1,11 +1,14 @@
// spell-checker:ignore libc's
use crate::common::util::TestScenario;
#[test]
#[cfg(not(target_os = "android"))]
fn test_get_current_niceness() {
// NOTE: this assumes the test suite is being run with a default niceness
// of 0, which may not necessarily be true
new_ucmd!().run().stdout_is("0\n");
// Test that the nice command with no arguments returns the default nice
// value, which we determine by querying libc's `nice` in our own process.
new_ucmd!()
.run()
.stdout_is(format!("{}\n", unsafe { libc::nice(0) }));
}
#[test]

View file

@ -156,6 +156,39 @@ fn test_multi_stdin() {
}
}
#[test]
// TODO: make this test work on Windows
#[cfg(not(windows))]
fn test_delimiter_list_ending_with_escaped_backslash() {
for d in ["-d", "--delimiters"] {
let (at, mut ucmd) = at_and_ucmd!();
let mut ins = vec![];
for (i, _in) in ["a\n", "b\n"].iter().enumerate() {
let file = format!("in{}", i);
at.write(&file, _in);
ins.push(file);
}
ucmd.args(&[d, "\\\\"])
.args(&ins)
.succeeds()
.stdout_is("a\\b\n");
}
}
#[test]
fn test_delimiter_list_ending_with_unescaped_backslash() {
for d in ["-d", "--delimiters"] {
new_ucmd!()
.args(&[d, "\\"])
.fails()
.stderr_contains("delimiter list ends with an unescaped backslash: \\");
new_ucmd!()
.args(&[d, "_\\"])
.fails()
.stderr_contains("delimiter list ends with an unescaped backslash: _\\");
}
}
#[test]
fn test_data() {
for example in EXAMPLE_DATA {