1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-08-01 13:37:48 +00:00

Fix touch parse date error

Now it can parse `touch -d 2000-01-23 file` and add test for parse date
error.

Related to #2311
This commit is contained in:
Dean Li 2021-05-31 20:13:58 +08:00
parent 6141fdcc73
commit 9d8e7b9acb
No known key found for this signature in database
GPG key ID: 4F55BB69D480672A
3 changed files with 36 additions and 26 deletions

View file

@ -354,6 +354,34 @@ fn test_touch_set_date() {
assert_eq!(mtime, start_of_year);
}
#[test]
fn test_touch_set_date2() {
let (at, mut ucmd) = at_and_ucmd!();
let file = "test_touch_set_date";
ucmd.args(&["-d", "2000-01-23", file])
.succeeds()
.no_stderr();
assert!(at.file_exists(file));
let start_of_year = str_to_filetime("%Y%m%d%H%M", "200001230000");
let (atime, mtime) = get_file_times(&at, file);
assert_eq!(atime, mtime);
assert_eq!(atime, start_of_year);
assert_eq!(mtime, start_of_year);
}
#[test]
fn test_touch_set_date_wrong_format() {
let (_at, mut ucmd) = at_and_ucmd!();
let file = "test_touch_set_date_wrong_format";
ucmd.args(&["-d", "2005-43-21", file])
.fails()
.stderr_contains("Unable to parse date: 2005-43-21");
}
#[test]
fn test_touch_mtime_dst_succeeds() {
let (at, mut ucmd) = at_and_ucmd!();