mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 03:27:44 +00:00
ls: finish the plug of mtime
Will help with tests/ls/ls-time
This commit is contained in:
parent
2227330fe7
commit
958ac72113
2 changed files with 27 additions and 0 deletions
|
@ -536,6 +536,7 @@ fn extract_time(options: &clap::ArgMatches) -> Time {
|
|||
match field.as_str() {
|
||||
"ctime" | "status" => Time::Change,
|
||||
"access" | "atime" | "use" => Time::Access,
|
||||
"mtime" | "modification" => Time::Modification,
|
||||
"birth" | "creation" => Time::Birth,
|
||||
// below should never happen as clap already restricts the values.
|
||||
_ => unreachable!("Invalid field for --time"),
|
||||
|
@ -1442,12 +1443,14 @@ pub fn uu_app() -> Command {
|
|||
"Show time in <field>:\n\
|
||||
\taccess time (-u): atime, access, use;\n\
|
||||
\tchange time (-t): ctime, status.\n\
|
||||
\tmodification time: mtime, modification.\n\
|
||||
\tbirth time: birth, creation;",
|
||||
)
|
||||
.value_name("field")
|
||||
.value_parser(ShortcutValueParser::new([
|
||||
PossibleValue::new("atime").alias("access").alias("use"),
|
||||
PossibleValue::new("ctime").alias("status"),
|
||||
PossibleValue::new("mtime").alias("modification"),
|
||||
PossibleValue::new("birth").alias("creation"),
|
||||
]))
|
||||
.hide_possible_values(true)
|
||||
|
|
|
@ -2099,6 +2099,30 @@ fn test_ls_order_time() {
|
|||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_ls_order_mtime() {
|
||||
use std::time::SystemTime;
|
||||
let scene = TestScenario::new(util_name!());
|
||||
let at = &scene.fixtures;
|
||||
|
||||
let f3 = at.make_file("test-3");
|
||||
f3.set_modified(SystemTime::now()).unwrap();
|
||||
let f4 = at.make_file("test-4");
|
||||
f4.set_modified(SystemTime::now()).unwrap();
|
||||
let f1 = at.make_file("test-1");
|
||||
f1.set_modified(SystemTime::now()).unwrap();
|
||||
let f2 = at.make_file("test-2");
|
||||
f2.set_modified(SystemTime::now()).unwrap();
|
||||
|
||||
let result = scene.ucmd().arg("-t").arg("--time=mtime").succeeds();
|
||||
result.stdout_only("test-2\ntest-1\ntest-4\ntest-3\n");
|
||||
f3.set_modified(SystemTime::now()).unwrap();
|
||||
|
||||
f4.set_modified(SystemTime::now()).unwrap();
|
||||
let result = scene.ucmd().arg("-t").arg("--time=mtime").succeeds();
|
||||
result.stdout_only("test-4\ntest-3\ntest-2\ntest-1\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_ls_non_existing() {
|
||||
new_ucmd!().arg("doesntexist").fails();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue