Minor manual cleanup - inlined many format args. This makes the code a bit more readable, and helps spot a few inefficiencies and possible bugs. Note that `&foo` in a `format!` parameter results in a 6% extra performance cost, and does not get inlined by the compiler (yet).
It's not totally clear why they sometimes work, sometimes fail,
but it does appear that running `stat` on `/dev/stdin` is perhaps
not the most reliable approach.
A likely more solid approach is described in #7583.
Support precision when rendering the time of last data modification
with `stat`. For example, after this commit
$ stat --printf='%.1Y\n' f
1668645806.7
Previously, the precision in the format specification was
ignored. This is implemented with a custom renderer because GNU `stat`
seems to truncate the number as opposed to rounding the number as
would happen when using `format!` with a specified number of digits of
precision.
Fixes#3233
* stat: fix the quotes when dealing with %N
and other formats
should fix
tests/stat/stat-fmt.sh
* stats: use an enum instead of a string
* stats: split the functions into smaller functions
* stat: handle byte as a format for better display
* stat: handle error better. should make tests/stat/stat-printf.pl pass
* stat: Some escape sequences are non-standard
* Fix tests
* Take comments into account
* stat: should fail without arguments #5928
* style and lint issue stat: should fail without arguments #5928
* style and lint issue stat: should fail without arguments #5928
* style and lint 2 issue stat: should fail without arguments #5928
---------
Co-authored-by: biplab5464 <biplab5464@outlook.com>
On Android and macOS all/some tests for stdin fail with:
`cannot stat '-': No such file or directory`
Apparently the `/dev/stdin` redirect workaround doesn't work for
these targets.
`LANGUAGE=C` is not enough, `LC_ALL=C` is needed as the environment
variable that overrides all the other localization settings.
e.g.
```bash
$ LANGUAGE=C id foobar
id: ‘foobar’: no such user
$ LC_ALL=C id foobar
id: 'foobar': no such user
```
* replace `LANGUAGE` with `LC_ALL` as environment variable in the tests
* fix the the date string of affected uutils
* replace `‘` and `’` with `'`
A lot of tests depend on GNU's coreutils to be installed in order
to obtain reference values during testing.
In these cases testing is limited to `target_os = linux`.
This PR installs GNU's coreutils on "github actions" and adjusts the
tests for `who`, `stat` and `pinky` in order to be compatible with macOS.
* `brew install coreutils` (prefix is 'g', e.g. `gwho`, `gstat`, etc.
* switch paths for testing to something that's available on both OSs,
e.g. `/boot` -> `/bin`, etc.
* switch paths for testing to the macOS equivalent,
e.g. `/dev/pts/ptmx` -> `/dev/ptmx`, etc.
* exclude paths when no equivalent is available,
e.g. `/proc`, `/etc/fstab`, etc.
* refactor tests to make better use of the testing API
* fix a warning in utmpx.rs to print to stderr instead of stdout
* fix long_usage text in `who`
* fix minor output formatting in `stat`
* the `expected_result` function should be refactored
to reduce duplicate code
* more tests should be adjusted to not only run on `target_os = linux`
This is a refactor to reduce duplicate code, it affects chmod/ls/stat.
* merge `stat/src/fsext::pretty_access` into `uucore/src/lib/feature/fs::display_permissions_unix`
* move tests for `fs::display_permissions` from `test_stat::test_access` to `uucore/src/lib/features/fs::test_display_permissions`
* adjust `uu_chmod`, `uu_ls` and `uu_stat` to use `uucore::fs::display_permissions`