Commit graph

486 commits

Author SHA1 Message Date
Jan Scheer
1c41efd732 stdbuf: use "parse_size" from uucore 2021-05-31 09:35:46 +02:00
Jan Scheer
0bf14da490 tail: use "parse_size" from uucore 2021-05-28 22:21:03 +02:00
Sylvestre Ledru
41539df91d
Merge pull request #2280 from jhscheer/symlink_tests
Improve symlink/hardlink handling in tests
2021-05-27 09:41:48 +02:00
Matt Blessed
f11f5f3abb mv: refactor backup logic to use shared uucore backup control
- add mv backup tests
2021-05-26 18:23:48 -04:00
Terts Diepraam
b4f6c81810
Merge pull request #2281 from deantvv/chmod-match-gnu-error
chmod: match GNU error
2021-05-26 21:13:05 +02:00
Terts Diepraam
658e52dde0
Merge pull request #2275 from blesson3/cp-backup-support
cp: implement backup support
2021-05-26 21:12:01 +02:00
Matt Blessed
25ed5eeb0e cp: move option check to uumain and use show_usage_error
- add test for conflicting options `--backup` and `--no-clobber`
2021-05-26 11:10:04 -04:00
Dean Li
fe25b51a66
chmod: match GNU error
Related to #2260

Signed-off-by: Dean Li <deantvv@gmail.com>
2021-05-26 22:31:02 +08:00
Jan Scheer
efd5921bda tests/test: replace call to 'ln -s' with call to 'AtPath::symlink_file' 2021-05-26 13:42:12 +02:00
Jan Scheer
6a70d89e8c tests/du: replace call to 'ln' with call to 'AtPath::hard_link' 2021-05-26 12:55:53 +02:00
Matt Blessed
a8a1ec7faf cp: implement backup control with tests 2021-05-25 23:22:32 -04:00
Yağız can Değirmenci
12f207a6d6 test: fix tests 2021-05-26 03:21:53 +03:00
Yağız can Değirmenci
8fe34c72d2 test: fix tests 2021-05-26 03:07:49 +03:00
Yağız can Değirmenci
071899d24d tests: delete 'error:' prefix from the tests 2021-05-26 02:45:53 +03:00
Yağız can Değirmenci
991fcc548c fix: log error messages properly on permission errors 2021-05-24 21:07:45 +03:00
Michael Debertol
218f523e1b expr: make substr infallible
Instead of returning an Err it should return the "null string"
(in our case that's the empty string) when the offset or length
is invalid.
2021-05-23 22:22:34 +02:00
Sylvestre Ledru
7bf076505f
Merge branch 'master' into who_fix_runlevel 2021-05-23 09:32:37 +02:00
Sylvestre Ledru
b175534a97
Merge pull request #2264 from miDeb/sort-sort-flag
sort: support --sort flag and check for conflicts
2021-05-23 09:30:03 +02:00
Sylvestre Ledru
41bd025d00
Merge pull request #2209 from jfinkels/head-ring-buffer
head: add abstractions for "all but last n lines"
2021-05-23 09:28:17 +02:00
Jeffrey Finkelstein
bc9db289e8 head: add abstractions for "all but last n lines"
Add some abstractions to simplify the `rbuf_but_last_n_lines()`
function, which implements the "take all but the last `n` lines"
functionality of the `head` program. This commit adds

- `RingBuffer`, a fixed-size ring buffer,
- `ZLines`, an iterator over zero-terminated "lines",
- `TakeAllBut`, an iterator over all but the last `n` elements of an
  iterator.

These three together make the implementation of
`rbuf_but_last_n_lines()` concise.
2021-05-22 23:56:48 -04:00
Jan Scheer
44c033a013 who: exclude --runlevel from non Linux targets (fix #2239) 2021-05-23 03:05:15 +02:00
Sylvestre Ledru
95092e6440 ignore test_should_calculate_implicit_padding_per_free_argument
Fails from time to time with
```
---- test_numfmt::test_should_calculate_implicit_padding_per_free_argument stdout ----
current_directory_resolved:
run: /target/x86_64-unknown-linux-musl/debug/coreutils numfmt --from=auto    1Ki         2K
thread 'test_numfmt::test_should_calculate_implicit_padding_per_free_argument' panicked at 'failed to write to stdin of child: Broken pipe (os error 32)', tests/common/util.rs:859:21
```
2021-05-23 00:34:01 +02:00
Sylvestre Ledru
4aaeede3d8 rustfmt the recent change 2021-05-23 00:13:53 +02:00
Michael Debertol
c1f67ed775 sort: support --sort flag and check for conflicts
`sort` supports three ways to specify the sort mode: a long option
(e.g. --numeric-sort), a short option (e.g. -n) and the sort flag
(e.g. --sort=numeric).
This adds support for the sort flag.

Additionally, sort modes now conflict, which means that an error is
shown when multiple modes are passed, instead of silently picking a mode.
For consistency, I added the `random` sort mode to the `SortMode` enum,
instead of it being a bool flag.
2021-05-22 23:10:41 +02:00
David Carlier
fcb079e20e who freebsd build fix unsupported RUN_LVL option only for other platforms. 2021-05-22 18:07:02 +01:00
Sylvestre Ledru
542deb8888
Merge pull request #2246 from miDeb/sort-automatic-extsort
sort: automatically fall back to extsort
2021-05-22 17:21:02 +02:00
Sylvestre Ledru
8055f26a73
Merge pull request #2228 from jfinkels/tail-obo-positive-bytes
tail: fix off-by-one issue for +NUM args
2021-05-22 17:18:55 +02:00
Sylvestre Ledru
66dd6dbeff
Merge pull request #2244 from jfinkels/truncate-fix-round-up-character
truncate: fix character used to indicate round up
2021-05-22 14:03:59 +02:00
Michael Debertol
088443276a sort: improve handling of buffer size cmd arg
Instead of overflowing when calculating the buffer size, use
saturating_{pow, mul}.

When failing to parse the buffer size, we now crash instead of silently
ignoring the error.
2021-05-22 14:00:07 +02:00
Sylvestre Ledru
4d3be19de3
Merge pull request #2240 from jhscheer/macos_test_coreutils
who/stat/pinky: adjust tests to be compatible with running on macOS
2021-05-22 12:39:05 +02:00
Sylvestre Ledru
424a99f0e6
Merge pull request #2193 from jfinkels/2186-min-width-stdin
wc: compute minimum width to format counts up front
2021-05-22 12:37:42 +02:00
Anup Mahindre
9f88963764 tests: fix test_ls_path for windows 2021-05-22 14:54:01 +05:30
Michael Debertol
e7da8058dc sort: automatically fall back to extsort
To make this work we make default sort a special case of external sort.

External sorting uses auxiliary files for intermediate chunks. However,
when we can keep our intermediate chunks in memory, we don't write them
to the file system at all. Only when we notice that we can't keep them
in memory they are written to the disk.

Additionally, we don't allocate buffers with the capacity of their
maximum size anymore. Instead, they start with a capacity of 8kb and are
grown only when needed.

This makes sorting smaller files about as fast as it was before
(I'm seeing a regression of ~3%), and allows us to seamlessly continue
with auxiliary files when needed.
2021-05-21 23:09:46 +02:00
Anup Mahindre
31545258ac tests: Fix test_ls_path 2021-05-21 22:24:13 +05:30
Jan Scheer
007e0a4e7f who/stat/pinky: adjust tests to be compatible with running on macOS
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`
2021-05-21 11:55:20 +02:00
Sylvestre Ledru
76844dbd56
Merge pull request #2241 from jfinkels/truncate-rustfmt-test
truncate: rustfmt test_truncate.rs file
2021-05-21 10:06:45 +02:00
Jeffrey Finkelstein
a23555e857 truncate: fix character used to indicate round up
Fix a bug in which the incorrect character was being used to indicate
"round up to the nearest multiple" mode. The character was "*" but it
should be "%". This commit corrects that.
2021-05-20 23:19:58 -04:00
Jeffrey Finkelstein
fc29846b45 truncate: fix error message for file not found
Change the error message for when the reference file (the `-r` argument)
is not found to match GNU coreutils. This commit also eliminates a
redundant call to `File::open`; the file need not be opened because the
size in bytes can be read from the result of `std::fs::metadata()`.
2021-05-20 20:59:59 -04:00
Jeffrey Finkelstein
d30393089f truncate: rustfmt test_truncate.rs file 2021-05-20 20:58:56 -04:00
Sylvestre Ledru
b9e99543db
Merge pull request #2234 from chadbrewbaker/fix-cat-random-timeout
dev random blocks on linux
2021-05-20 23:25:11 +02:00
Sylvestre Ledru
efb781f59a
Merge pull request #2221 from jfinkels/head-display-multiple-errors-2
head: display errors for each input file instead of terminating at the first error
2021-05-20 23:24:35 +02:00
Sylvestre Ledru
ca196a6dad
Merge pull request #2218 from miDeb/sort-chunks
sort: read files as chunks, off-thread
2021-05-20 23:24:02 +02:00
Jeffrey Finkelstein
63b496eaa8 truncate: refactor parse_size() function
Change the interface provided by the `parse_size()` function to reduce
its responsibilities to just a single task: parsing a number of bytes
from a string of the form '123KB', etc. Previously, the function was
also responsible for deciding which mode truncate would operate in.

Furthermore, this commit simplifies the code for parsing the number and
unit to be less verbose and use less mutable state.

Finally, this commit adds some unit tests for the `parse_size()`
function.
2021-05-19 23:07:11 -04:00
Chad Brewbaker
9167a4128d
Update test_cat.rs
Refactored to constants
2021-05-19 04:06:46 -05:00
Jan Scheer
8032c6d750 fix clippy warnings 2021-05-19 01:37:28 +02:00
Chad Brewbaker
a69cb11de9 Removing debug code 2021-05-18 15:17:07 -05:00
Chad Brewbaker
c60d3866c3 dev random blocks on linux 2021-05-18 15:10:51 -05:00
Jan Scheer
7c7d622d54 tests: add test for issue #2223 2021-05-18 02:00:16 +02:00
Jeffrey Finkelstein
bc29645531 tail: fix off-by-one issue for +NUM args
Fix an off-by-one issue for `tail -c +NUM` and `tail -n +NUM` command
line options.
2021-05-17 19:45:42 -04:00
Jeffrey Finkelstein
eeef8290df head: display errors for each input file
Change the behavior of `head` to display an error for each problematic
file, instead of displaying an error message for the first problematic
file and terminating immediately at that point. This change now matches
the behavior of GNU `head`.

Before this commit, the first error caused the program to terminate
immediately:

    $ head a b c
    head: error: head: cannot open 'a' for reading: No such file or directory

After this commit:

    $ head a b c
    head: cannot open 'a' for reading: No such file or directory
    head: cannot open 'b' for reading: No such file or directory
    head: cannot open 'c' for reading: No such file or directory
2021-05-17 08:19:47 -04:00