1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 11:37:44 +00:00

ls: finish the plug of mtime

Will help with tests/ls/ls-time
This commit is contained in:
Sylvestre Ledru 2024-12-28 22:50:49 +01:00
parent 2227330fe7
commit 958ac72113
2 changed files with 27 additions and 0 deletions

View file

@ -536,6 +536,7 @@ fn extract_time(options: &clap::ArgMatches) -> Time {
match field.as_str() { match field.as_str() {
"ctime" | "status" => Time::Change, "ctime" | "status" => Time::Change,
"access" | "atime" | "use" => Time::Access, "access" | "atime" | "use" => Time::Access,
"mtime" | "modification" => Time::Modification,
"birth" | "creation" => Time::Birth, "birth" | "creation" => Time::Birth,
// below should never happen as clap already restricts the values. // below should never happen as clap already restricts the values.
_ => unreachable!("Invalid field for --time"), _ => unreachable!("Invalid field for --time"),
@ -1442,12 +1443,14 @@ pub fn uu_app() -> Command {
"Show time in <field>:\n\ "Show time in <field>:\n\
\taccess time (-u): atime, access, use;\n\ \taccess time (-u): atime, access, use;\n\
\tchange time (-t): ctime, status.\n\ \tchange time (-t): ctime, status.\n\
\tmodification time: mtime, modification.\n\
\tbirth time: birth, creation;", \tbirth time: birth, creation;",
) )
.value_name("field") .value_name("field")
.value_parser(ShortcutValueParser::new([ .value_parser(ShortcutValueParser::new([
PossibleValue::new("atime").alias("access").alias("use"), PossibleValue::new("atime").alias("access").alias("use"),
PossibleValue::new("ctime").alias("status"), PossibleValue::new("ctime").alias("status"),
PossibleValue::new("mtime").alias("modification"),
PossibleValue::new("birth").alias("creation"), PossibleValue::new("birth").alias("creation"),
])) ]))
.hide_possible_values(true) .hide_possible_values(true)

View file

@ -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] #[test]
fn test_ls_non_existing() { fn test_ls_non_existing() {
new_ucmd!().arg("doesntexist").fails(); new_ucmd!().arg("doesntexist").fails();