diff --git a/src/uu/date/src/date.rs b/src/uu/date/src/date.rs index d95a71b7c9..28fed44974 100644 --- a/src/uu/date/src/date.rs +++ b/src/uu/date/src/date.rs @@ -774,6 +774,7 @@ pub fn uu_app() -> Command { .long(OPT_SET) .value_name("STRING") .allow_hyphen_values(true) + .conflicts_with_all([OPT_DATE, OPT_FILE, OPT_REFERENCE, OPT_RESOLUTION]) .help({ #[cfg(not(target_os = "redox"))] { diff --git a/tests/by-util/test_date.rs b/tests/by-util/test_date.rs index 3b4be7fd9e..04bba9bbda 100644 --- a/tests/by-util/test_date.rs +++ b/tests/by-util/test_date.rs @@ -3446,3 +3446,28 @@ fn test_non_utf8_operands_are_octal_escaped() { .stderr_contains(expected); } } + +#[test] +fn test_date_print_and_set_conflict() { + // Invalid set input also prevents any clock change if validation regresses. + for print_args in [ + vec!["-d", "@0"], + vec!["-f", "missing"], + vec!["-r", "missing"], + vec!["--resolution"], + ] { + for set_first in [true, false] { + let mut args = vec!["-s", "not-a-date"]; + if set_first { + args.extend(&print_args); + } else { + args.splice(0..0, print_args.iter().copied()); + } + new_ucmd!() + .args(&args) + .fails_with_code(1) + .no_stdout() + .stderr_contains("cannot be used with"); + } + } +}