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

Proper columns for ls -l (#2623)

* Used .as_path() and .as_str() when required:

when the argument required is a Path and not a PathBuf,
or an str and not a Path, respectively.

* Changed display_items to take Vec<PathData>, which is passed, instead of [PathData]

* Added a pad_right function.

* Implemented column-formating to mimic the behavior of GNU coreutils's ls

Added returns in display_dir_entry_size that keep track of uname and
group lengths.
Renamed variables to make more sense.
Changed display_item_long to take all the lengths it needs to render
correctly.
Implemented owner, group, and author padding right to mimic GNU ls.

* Added a todo for future quality-of-life cache addition.

* Documented display_item_long, as a first step in documenting all functions.

* Revert "Used .as_path() and .as_str() when required:"

This reverts commit b88db6a8170f827a7adc58de14acb59f19be2db1.

* Revert "Changed display_items to take Vec<PathData>, which is passed, instead of [PathData]"

This reverts commit 0c690dda8d5eb1b257afb4c74d9c2dfc1f7cc97b.

* Ran cargo fmt to get rid of Style/format `fmt` testing error.

* Added a test for `ls -l` and `ls -lan` line formats.

* Changed uname -> username for cspell. Removed extra blank line for rustfmt.
This commit is contained in:
Mahmoud Soltan 2021-08-30 23:09:16 +02:00 committed by GitHub
parent d247cbd7e5
commit 97a0c06ff4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 143 additions and 14 deletions

View file

@ -333,6 +333,61 @@ fn test_ls_long() {
}
}
#[test]
fn test_ls_long_format() {
#[cfg(not(windows))]
let last;
#[cfg(not(windows))]
{
let _guard = UMASK_MUTEX.lock();
last = unsafe { umask(0) };
unsafe {
umask(0o002);
}
}
let scene = TestScenario::new(util_name!());
let at = &scene.fixtures;
at.mkdir(&at.plus_as_string("test-long-dir"));
at.touch(&at.plus_as_string("test-long-dir/test-long-file"));
at.mkdir(&at.plus_as_string("test-long-dir/test-long-dir"));
for arg in &["-l", "--long", "--format=long", "--format=verbose"] {
let result = scene.ucmd().arg(arg).arg("test-long-dir").succeeds();
// Assuming sane username do not have spaces within them.
// A line of the output should be:
// One of the characters -bcCdDlMnpPsStTx?
// rwx, with - for missing permissions, thrice.
// A number, preceded by column whitespace, and followed by a single space.
// A username, currently [^ ], followed by column whitespace, twice (or thrice for Hurd).
// A number, followed by a single space.
// A month, followed by a single space.
// A day, preceded by column whitespace, and followed by a single space.
// Either a year or a time, currently [0-9:]+, preceded by column whitespace,
// and followed by a single space.
// Whatever comes after is irrelevant to this specific test.
#[cfg(not(windows))]
result.stdout_matches(&Regex::new(
r"\n[-bcCdDlMnpPsStTx?]([r-][w-][xt-]){3} +\d+ [^ ]+ +[^ ]+( +[^ ]+)? +\d+ [A-Z][a-z]{2} {0,2}\d{0,2} {0,2}[0-9:]+ "
).unwrap());
}
let result = scene.ucmd().arg("-lan").arg("test-long-dir").succeeds();
// This checks for the line with the .. entry. The uname and group should be digits.
#[cfg(not(windows))]
result.stdout_matches(&Regex::new(
r"\nd([r-][w-][xt-]){3} +\d+ \d+ +\d+( +\d+)? +\d+ [A-Z][a-z]{2} {0,2}\d{0,2} {0,2}[0-9:]+ \.\."
).unwrap());
#[cfg(not(windows))]
{
unsafe {
umask(last);
}
}
}
#[test]
fn test_ls_long_total_size() {
let scene = TestScenario::new(util_name!());