mirror of
https://github.com/uutils/coreutils.git
synced 2026-06-10 15:48:22 -07:00
ln: Interactive and Force override each other instead of defaulting to Force if both are specified (#11129)
* ln: Interactive and Force override each other instead of defaulting to Force if both are specified. * ln: Add tests for `-i -f` and `-f -i` overrides. --------- Co-authored-by: aweinstock <avi@zellic.io>
This commit is contained in:
co-authored by
aweinstock
parent
5d9db22650
commit
38ba3663ca
@@ -163,6 +163,7 @@ pub fn uu_app() -> Command {
|
||||
.short('f')
|
||||
.long(options::FORCE)
|
||||
.help(translate!("ln-help-force"))
|
||||
.overrides_with(options::INTERACTIVE)
|
||||
.action(ArgAction::SetTrue),
|
||||
)
|
||||
.arg(
|
||||
@@ -170,6 +171,7 @@ pub fn uu_app() -> Command {
|
||||
.short('i')
|
||||
.long(options::INTERACTIVE)
|
||||
.help(translate!("ln-help-interactive"))
|
||||
.overrides_with(options::FORCE)
|
||||
.action(ArgAction::SetTrue),
|
||||
)
|
||||
.arg(
|
||||
|
||||
@@ -111,6 +111,24 @@ fn test_symlink_overwrite_force() {
|
||||
assert_eq!(at.resolve_link(link), file_b);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_symlink_overwrite_force_overrides_interactive() {
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
let file_a = "test_symlink_overwrite_force_a";
|
||||
let file_b = "test_symlink_overwrite_force_b";
|
||||
let link = "test_symlink_overwrite_force_link";
|
||||
|
||||
// Create symlink
|
||||
at.symlink_file(file_a, link);
|
||||
assert!(at.is_symlink(link));
|
||||
assert_eq!(at.resolve_link(link), file_a);
|
||||
|
||||
// Force overwrite of existing symlink
|
||||
ucmd.args(&["-i", "-f", "-s", file_b, link]).succeeds();
|
||||
assert!(at.is_symlink(link));
|
||||
assert_eq!(at.resolve_link(link), file_b);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_symlink_interactive() {
|
||||
let scene = TestScenario::new(util_name!());
|
||||
@@ -143,6 +161,38 @@ fn test_symlink_interactive() {
|
||||
assert_eq!(at.resolve_link(link), file);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_symlink_interactive_overrides_force() {
|
||||
let scene = TestScenario::new(util_name!());
|
||||
let at = &scene.fixtures;
|
||||
let file = "test_symlink_interactive_file";
|
||||
let link = "test_symlink_interactive_file_link";
|
||||
|
||||
at.touch(file);
|
||||
at.touch(link);
|
||||
|
||||
scene
|
||||
.ucmd()
|
||||
.args(&["-f", "-i", "-s", file, link])
|
||||
.pipe_in("n")
|
||||
.fails()
|
||||
.no_stdout();
|
||||
|
||||
assert!(at.file_exists(file));
|
||||
assert!(!at.is_symlink(link));
|
||||
|
||||
scene
|
||||
.ucmd()
|
||||
.args(&["-f", "-i", "-s", file, link])
|
||||
.pipe_in("Yesh") // spell-checker:disable-line
|
||||
.succeeds()
|
||||
.no_stdout();
|
||||
|
||||
assert!(at.file_exists(file));
|
||||
assert!(at.is_symlink(link));
|
||||
assert_eq!(at.resolve_link(link), file);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_symlink_simple_backup() {
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
|
||||
Reference in New Issue
Block a user