mirror of
https://github.com/uutils/coreutils.git
synced 2026-06-10 15:48:22 -07:00
date: fix inconsistent input parsing between -s and -d flags (#9690)
Add allow_hyphen_values(true) to -s flag to accept hyphen-prefixed values like '-3 days', making it consistent with -d flag behavior and GNU coreutils compatibility. Fixes #9679
This commit is contained in:
@@ -487,6 +487,7 @@ pub fn uu_app() -> Command {
|
||||
.short('s')
|
||||
.long(OPT_SET)
|
||||
.value_name("STRING")
|
||||
.allow_hyphen_values(true)
|
||||
.help({
|
||||
#[cfg(not(any(target_os = "macos", target_os = "redox")))]
|
||||
{
|
||||
|
||||
@@ -293,6 +293,27 @@ fn test_date_set_permissions_error() {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(all(unix, not(any(target_os = "android", target_os = "macos"))))]
|
||||
fn test_date_set_hyphen_prefixed_values() {
|
||||
// test -s flag accepts hyphen-prefixed values like "-3 days"
|
||||
if !(geteuid() == 0 || uucore::os::is_wsl_1()) {
|
||||
let test_cases = vec!["-1 hour", "-2 days", "-3 weeks", "-1 month"];
|
||||
|
||||
for date_str in test_cases {
|
||||
let result = new_ucmd!().arg("--set").arg(date_str).fails();
|
||||
result.no_stdout();
|
||||
// permission error, not argument parsing error
|
||||
assert!(
|
||||
result.stderr_str().starts_with("date: cannot set date: "),
|
||||
"Expected permission error for '{}', but got: {}",
|
||||
date_str,
|
||||
result.stderr_str()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(target_os = "macos")]
|
||||
fn test_date_set_mac_unavailable() {
|
||||
|
||||
Reference in New Issue
Block a user