mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
uucore: allow backup suffix with hyphen value
This commit is contained in:
parent
dfc661e8b5
commit
184b65df20
5 changed files with 101 additions and 0 deletions
|
@ -231,6 +231,7 @@ pub mod arguments {
|
||||||
.help("override the usual backup suffix")
|
.help("override the usual backup suffix")
|
||||||
.takes_value(true)
|
.takes_value(true)
|
||||||
.value_name("SUFFIX")
|
.value_name("SUFFIX")
|
||||||
|
.allow_hyphen_values(true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -618,4 +619,13 @@ mod tests {
|
||||||
assert_eq!(result, BackupMode::SimpleBackup);
|
assert_eq!(result, BackupMode::SimpleBackup);
|
||||||
env::remove_var(ENV_VERSION_CONTROL);
|
env::remove_var(ENV_VERSION_CONTROL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_suffix_takes_hyphen_value() {
|
||||||
|
let _dummy = TEST_MUTEX.lock().unwrap();
|
||||||
|
let matches = make_app().get_matches_from(vec!["app", "-b", "--suffix", "-v"]);
|
||||||
|
|
||||||
|
let result = determine_backup_suffix(&matches);
|
||||||
|
assert_eq!(result, "-v");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -385,6 +385,24 @@ fn test_cp_arg_suffix() {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_cp_arg_suffix_hyphen_value() {
|
||||||
|
let (at, mut ucmd) = at_and_ucmd!();
|
||||||
|
|
||||||
|
ucmd.arg(TEST_HELLO_WORLD_SOURCE)
|
||||||
|
.arg("-b")
|
||||||
|
.arg("--suffix")
|
||||||
|
.arg("-v")
|
||||||
|
.arg(TEST_HOW_ARE_YOU_SOURCE)
|
||||||
|
.succeeds();
|
||||||
|
|
||||||
|
assert_eq!(at.read(TEST_HOW_ARE_YOU_SOURCE), "Hello, World!\n");
|
||||||
|
assert_eq!(
|
||||||
|
at.read(&*format!("{}-v", TEST_HOW_ARE_YOU_SOURCE)),
|
||||||
|
"How are you?\n"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_cp_custom_backup_suffix_via_env() {
|
fn test_cp_custom_backup_suffix_via_env() {
|
||||||
let (at, mut ucmd) = at_and_ucmd!();
|
let (at, mut ucmd) = at_and_ucmd!();
|
||||||
|
|
|
@ -815,6 +815,31 @@ fn test_install_backup_short_custom_suffix() {
|
||||||
assert!(at.file_exists(&format!("{}{}", file_b, suffix)));
|
assert!(at.file_exists(&format!("{}{}", file_b, suffix)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_install_backup_short_custom_suffix_hyphen_value() {
|
||||||
|
let scene = TestScenario::new(util_name!());
|
||||||
|
let at = &scene.fixtures;
|
||||||
|
|
||||||
|
let file_a = "test_install_backup_custom_suffix_file_a";
|
||||||
|
let file_b = "test_install_backup_custom_suffix_file_b";
|
||||||
|
let suffix = "-v";
|
||||||
|
|
||||||
|
at.touch(file_a);
|
||||||
|
at.touch(file_b);
|
||||||
|
scene
|
||||||
|
.ucmd()
|
||||||
|
.arg("-b")
|
||||||
|
.arg(format!("--suffix={}", suffix))
|
||||||
|
.arg(file_a)
|
||||||
|
.arg(file_b)
|
||||||
|
.succeeds()
|
||||||
|
.no_stderr();
|
||||||
|
|
||||||
|
assert!(at.file_exists(file_a));
|
||||||
|
assert!(at.file_exists(file_b));
|
||||||
|
assert!(at.file_exists(&format!("{}{}", file_b, suffix)));
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_install_backup_custom_suffix_via_env() {
|
fn test_install_backup_custom_suffix_via_env() {
|
||||||
let scene = TestScenario::new(util_name!());
|
let scene = TestScenario::new(util_name!());
|
||||||
|
|
|
@ -180,6 +180,33 @@ fn test_symlink_custom_backup_suffix() {
|
||||||
assert_eq!(at.resolve_link(backup), file);
|
assert_eq!(at.resolve_link(backup), file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_symlink_custom_backup_suffix_hyphen_value() {
|
||||||
|
let (at, mut ucmd) = at_and_ucmd!();
|
||||||
|
let file = "test_symlink_custom_backup_suffix";
|
||||||
|
let link = "test_symlink_custom_backup_suffix_link";
|
||||||
|
let suffix = "-v";
|
||||||
|
|
||||||
|
at.touch(file);
|
||||||
|
at.symlink_file(file, link);
|
||||||
|
assert!(at.file_exists(file));
|
||||||
|
assert!(at.is_symlink(link));
|
||||||
|
assert_eq!(at.resolve_link(link), file);
|
||||||
|
|
||||||
|
let arg = &format!("--suffix={}", suffix);
|
||||||
|
ucmd.args(&["-b", arg, "-s", file, link])
|
||||||
|
.succeeds()
|
||||||
|
.no_stderr();
|
||||||
|
assert!(at.file_exists(file));
|
||||||
|
|
||||||
|
assert!(at.is_symlink(link));
|
||||||
|
assert_eq!(at.resolve_link(link), file);
|
||||||
|
|
||||||
|
let backup = &format!("{}{}", link, suffix);
|
||||||
|
assert!(at.is_symlink(backup));
|
||||||
|
assert_eq!(at.resolve_link(backup), file);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_symlink_backup_numbering() {
|
fn test_symlink_backup_numbering() {
|
||||||
let (at, mut ucmd) = at_and_ucmd!();
|
let (at, mut ucmd) = at_and_ucmd!();
|
||||||
|
|
|
@ -340,6 +340,27 @@ fn test_mv_custom_backup_suffix() {
|
||||||
assert!(at.file_exists(&format!("{}{}", file_b, suffix)));
|
assert!(at.file_exists(&format!("{}{}", file_b, suffix)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_mv_custom_backup_suffix_hyphen_value() {
|
||||||
|
let (at, mut ucmd) = at_and_ucmd!();
|
||||||
|
let file_a = "test_mv_custom_backup_suffix_file_a";
|
||||||
|
let file_b = "test_mv_custom_backup_suffix_file_b";
|
||||||
|
let suffix = "-v";
|
||||||
|
|
||||||
|
at.touch(file_a);
|
||||||
|
at.touch(file_b);
|
||||||
|
ucmd.arg("-b")
|
||||||
|
.arg(format!("--suffix={}", suffix))
|
||||||
|
.arg(file_a)
|
||||||
|
.arg(file_b)
|
||||||
|
.succeeds()
|
||||||
|
.no_stderr();
|
||||||
|
|
||||||
|
assert!(!at.file_exists(file_a));
|
||||||
|
assert!(at.file_exists(file_b));
|
||||||
|
assert!(at.file_exists(&format!("{}{}", file_b, suffix)));
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_mv_custom_backup_suffix_via_env() {
|
fn test_mv_custom_backup_suffix_via_env() {
|
||||||
let (at, mut ucmd) = at_and_ucmd!();
|
let (at, mut ucmd) = at_and_ucmd!();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue