-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
ls: correct the order of custom time formats #14780
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2397,13 +2397,13 @@ fn test_ls_time_styles() { | |
| .stdout_matches(&re_custom_format_recent) | ||
| .stdout_matches(&re_custom_format_old); | ||
|
|
||
| //+FORMAT_RECENT\nFORMAT_OLD | ||
| //+FORMAT_OLD\nFORMAT_RECENT | ||
| let re_custom_format_old = | ||
| Regex::new(r"[a-z-]* \d* [\w.]* [\w.]* \d* \d{4}--\d{2} test-old\n").unwrap(); | ||
| scene | ||
| .ucmd() | ||
| .arg("-l") | ||
| .arg("--time-style=+%Y__%M\n%Y--%M") | ||
| .arg("--time-style=+%Y--%M\n%Y__%M") | ||
| .succeeds() | ||
| .stdout_matches(&re_custom_format_recent) | ||
| .stdout_matches(&re_custom_format_old); | ||
|
|
@@ -2419,7 +2419,7 @@ fn test_ls_time_styles() { | |
| scene | ||
| .ucmd() | ||
| .arg("-l") | ||
| .arg("--time-style=+%Y__%M\n%Y--%M\n") | ||
| .arg("--time-style=+%Y--%M\n%Y__%M\n") | ||
| .fails_with_code(2); | ||
|
|
||
| //Overwrite options tests | ||
|
|
@@ -2534,12 +2534,12 @@ fn test_ls_time_recent_future() { | |
| .stdout_matches(&re_iso_old); | ||
|
|
||
| // Also test that we can set a format that varies for recent of older files. | ||
| //+FORMAT_RECENT\nFORMAT_OLD | ||
| //+FORMAT_OLD\nFORMAT_RECENT | ||
| f.set_modified(SystemTime::now()).unwrap(); | ||
| scene | ||
| .ucmd() | ||
| .arg("-l") | ||
| .arg("--time-style=+RECENT\nOLD") | ||
| .arg("--time-style=+OLD\nRECENT") | ||
| .succeeds() | ||
| .stdout_contains("RECENT"); | ||
|
|
||
|
|
@@ -2549,7 +2549,7 @@ fn test_ls_time_recent_future() { | |
| scene | ||
| .ucmd() | ||
| .arg("-l") | ||
| .arg("--time-style=+RECENT\nOLD") | ||
| .arg("--time-style=+OLD\nRECENT") | ||
| .succeeds() | ||
| .stdout_contains("OLD"); | ||
|
|
||
|
|
@@ -8250,3 +8250,41 @@ ls: invalid --block-size argument '1fb' | |
| .stderr_is("ls: invalid --block-size argument '1fb'\n"); | ||
| } | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_ls_custom_time_style_recent_and_older() { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this overlaps quite a bit with test_ls_time_styles, could the new empty-half cases go there instead? thanks
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moved the empty-half and environment cases into test_ls_time_styles in c0212f7, reusing its recent and old fixtures. The focused test and clippy pass. |
||
| let scene = TestScenario::new(util_name!()); | ||
| scene.fixtures.touch("recent"); | ||
| scene | ||
| .fixtures | ||
| .make_file("older") | ||
| .set_modified(std::time::UNIX_EPOCH) | ||
| .unwrap(); | ||
|
|
||
| for (style, recent, older) in [ | ||
| ("+OLD\nNEW", "NEW", "OLD"), | ||
| ("+\nNEW", "NEW", ""), | ||
| ("+OLD\n", "", "OLD"), | ||
| ("+SAME", "SAME", "SAME"), | ||
| ] { | ||
| for use_env in [false, true] { | ||
| for (file, expected) in [("recent", recent), ("older", older)] { | ||
|
Copilot marked this conversation as resolved.
Outdated
|
||
| let mut cmd = scene.ucmd(); | ||
| cmd.arg("-l"); | ||
| if use_env { | ||
| cmd.env("TIME_STYLE", style); | ||
| } else { | ||
| cmd.arg(format!("--time-style={style}")); | ||
| } | ||
| let result = cmd.arg(file).succeeds(); | ||
| assert!( | ||
| result | ||
| .stdout_str() | ||
| .ends_with(&format!(" {expected} {file}\n")), | ||
| "unexpected output: {}", | ||
| result.stdout_str() | ||
| ); | ||
|
Copilot marked this conversation as resolved.
Outdated
|
||
| } | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
olderis passed as the recent format just below, could you rename it tofirst? it reads wrong otherwiseThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renamed the first parsed format to first in c0212f7. It is used for both timestamps when there is no newline, and for older timestamps when there is one.