From ed258e3c9c411f5d9c41950d10d6f094b8fa07e6 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Thu, 9 Sep 2021 21:48:17 +0200 Subject: [PATCH] touch: add --ref as an alias (#2641) --- src/uu/touch/src/touch.rs | 3 ++- tests/by-util/test_touch.rs | 24 ++++++++++++++++-------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/uu/touch/src/touch.rs b/src/uu/touch/src/touch.rs index 8dd7bf7d2..6997def09 100644 --- a/src/uu/touch/src/touch.rs +++ b/src/uu/touch/src/touch.rs @@ -6,7 +6,7 @@ // For the full copyright and license information, please view the LICENSE file // that was distributed with this source code. -// spell-checker:ignore (ToDO) filetime strptime utcoff strs datetime MMDDhhmm +// spell-checker:ignore (ToDO) filetime strptime utcoff strs datetime MMDDhhmm clapv pub extern crate filetime; @@ -176,6 +176,7 @@ pub fn uu_app() -> App<'static, 'static> { Arg::with_name(options::sources::REFERENCE) .short("r") .long(options::sources::REFERENCE) + .alias("ref") // clapv3 .help("use this file's times instead of the current time") .value_name("FILE"), ) diff --git a/tests/by-util/test_touch.rs b/tests/by-util/test_touch.rs index e8a17bbca..983d14fe2 100644 --- a/tests/by-util/test_touch.rs +++ b/tests/by-util/test_touch.rs @@ -6,6 +6,7 @@ use self::touch::filetime::{self, FileTime}; extern crate time; use crate::common::util::*; +use std::fs::remove_file; use std::path::PathBuf; fn get_file_times(at: &AtPath, path: &str) -> (FileTime, FileTime) { @@ -323,7 +324,8 @@ fn test_touch_no_dereference() { #[test] fn test_touch_reference() { - let (at, mut ucmd) = at_and_ucmd!(); + let scenario = TestScenario::new("touch"); + let (at, mut _ucmd) = (scenario.fixtures.clone(), scenario.ucmd()); let file_a = "test_touch_reference_a"; let file_b = "test_touch_reference_b"; let start_of_year = str_to_filetime("%Y%m%d%H%M", "201501010000"); @@ -331,15 +333,21 @@ fn test_touch_reference() { at.touch(file_a); set_file_times(&at, file_a, start_of_year, start_of_year); assert!(at.file_exists(file_a)); + for &opt in &["-r", "--ref", "--reference"] { + scenario + .ccmd("touch") + .args(&[opt, file_a, file_b]) + .succeeds() + .no_stderr(); - ucmd.args(&["-r", file_a, file_b]).succeeds().no_stderr(); + assert!(at.file_exists(file_b)); - assert!(at.file_exists(file_b)); - - let (atime, mtime) = get_file_times(&at, file_b); - assert_eq!(atime, mtime); - assert_eq!(atime, start_of_year); - assert_eq!(mtime, start_of_year); + let (atime, mtime) = get_file_times(&at, file_b); + assert_eq!(atime, mtime); + assert_eq!(atime, start_of_year); + assert_eq!(mtime, start_of_year); + let _ = remove_file(file_b); + } } #[test]