diff --git a/src/uu/cp/src/cp.rs b/src/uu/cp/src/cp.rs index dc7571b2e..95ca7eea2 100644 --- a/src/uu/cp/src/cp.rs +++ b/src/uu/cp/src/cp.rs @@ -426,6 +426,10 @@ pub fn uu_app<'a>() -> Command<'a> { .takes_value(true) .value_name("WHEN") .overrides_with_all(MODE_ARGS) + .require_equals(true) + .default_missing_value("always") + .value_parser(["auto", "always", "never"]) + .min_values(0) .help("control clone/CoW copies. See below"), ) .arg( diff --git a/tests/by-util/test_cp.rs b/tests/by-util/test_cp.rs index d6b00c344..45b331576 100644 --- a/tests/by-util/test_cp.rs +++ b/tests/by-util/test_cp.rs @@ -1334,6 +1334,24 @@ fn test_cp_reflink_auto() { assert_eq!(at.read(TEST_EXISTING_FILE), "Hello, World!\n"); } +#[test] +#[cfg(any(target_os = "linux", target_os = "android", target_os = "macos"))] +fn test_cp_reflink_none() { + let (at, mut ucmd) = at_and_ucmd!(); + let result = ucmd + .arg("--reflink") + .arg(TEST_HELLO_WORLD_SOURCE) + .arg(TEST_EXISTING_FILE) + .run(); + + if result.succeeded() { + // Check the content of the destination file + assert_eq!(at.read(TEST_EXISTING_FILE), "Hello, World!\n"); + } else { + // Older Linux versions do not support cloning. + } +} + #[test] #[cfg(any(target_os = "linux", target_os = "android", target_os = "macos"))] fn test_cp_reflink_never() { @@ -1356,7 +1374,7 @@ fn test_cp_reflink_bad() { .arg(TEST_HELLO_WORLD_SOURCE) .arg(TEST_EXISTING_FILE) .fails() - .stderr_contains("invalid argument"); + .stderr_contains("error: \"bad\" isn't a valid value for '--reflink[=...]'"); } #[test]