1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-27 19:17:43 +00:00

also support for tests/touch/no-rights.sh format

This commit is contained in:
Sylvestre Ledru 2022-05-08 21:31:42 +02:00
parent 087d4b14fc
commit d5569847bd
2 changed files with 33 additions and 1 deletions

View file

@ -280,12 +280,20 @@ const YYYYMMDDHHMMSS_FORMAT: &[time::format_description::FormatItem] = format_de
"[year repr:full]-[month repr:numerical padding:zero]-\
[day] [hour]:[minute]:[second].[subsecond]"
);
// "%Y-%m-%d %H:%M:%S" 12 chars
const YYYYMMDDHHMMS_FORMAT: &[time::format_description::FormatItem] = format_description!(
"[year repr:full]-[month repr:numerical padding:zero]-\
[day] [hour]:[minute]:[second]"
);
// "%Y-%m-%d %H:%M" 12 chars
// Used for example in tests/touch/no-rights.sh
const YYYY_MM_DD_HH_MM_FORMAT: &[time::format_description::FormatItem] = format_description!(
"[year repr:full]-[month repr:numerical padding:zero]-\
[day] [hour]:[minute]"
);
// "%Y%m%d%H%M" 12 chars
const YYYYMMDDHHMM_FORMAT: &[time::format_description::FormatItem] = format_description!(
"[year repr:full][month repr:numerical padding:zero]\
@ -325,7 +333,12 @@ fn parse_date(s: &str) -> UResult<FileTime> {
// Also support other formats found in the GNU tests like
// in tests/misc/stat-nanoseconds.sh
for fmt in [YYYYMMDDHHMMS_FORMAT, YYYYMMDDHHMMSS_FORMAT] {
// or tests/touch/no-rights.sh
for fmt in [
YYYYMMDDHHMMS_FORMAT,
YYYYMMDDHHMMSS_FORMAT,
YYYY_MM_DD_HH_MM_FORMAT,
] {
if let Ok(parsed) = time::PrimitiveDateTime::parse(s, &fmt) {
return Ok(dt_to_filename(parsed));
}

View file

@ -469,6 +469,25 @@ fn test_touch_set_date5() {
assert_eq!(mtime, expected);
}
#[test]
fn test_touch_set_date6() {
let (at, mut ucmd) = at_and_ucmd!();
let file = "test_touch_set_date";
ucmd.args(&["-d", "2000-01-01 00:00", file])
.succeeds()
.no_stderr();
assert!(at.file_exists(file));
let expected = FileTime::from_unix_time(946684800, 0);
let (atime, mtime) = get_file_times(&at, file);
assert_eq!(atime, mtime);
assert_eq!(atime, expected);
assert_eq!(mtime, expected);
}
#[test]
fn test_touch_set_date_wrong_format() {
let (_at, mut ucmd) = at_and_ucmd!();