mirror of
https://github.com/uutils/coreutils
synced 2024-11-16 09:48:03 +00:00
touch: add --ref as an alias (#2641)
This commit is contained in:
parent
2170d81621
commit
ed258e3c9c
2 changed files with 18 additions and 9 deletions
|
@ -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"),
|
||||
)
|
||||
|
|
|
@ -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]
|
||||
|
|
Loading…
Reference in a new issue