Commit graph

522 commits

Author SHA1 Message Date
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
Jeffrey Finkelstein
a746e37dc7 truncate: add test for -r and -s options together
Add a test for when the reference file is not found and both `-r` and
`-s` options are given on the command-line.
2021-05-22 23:45:05 -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
Chad Brewbaker
2f84f59573 fixing regex to take negative time offsets 2021-05-16 19:43:53 -05:00
Michael Debertol
fcd48813e0 sort: read files as chunks, off-thread
Instead of using a BufReader and reading each line separately,
allocating a String for each one, we read to a chunk. Lines are
references to this chunk. This makes the allocator's job much easier
and yields performance improvements.

Chunks are read on a separate thread to further improve performance.
2021-05-16 21:13:37 +02:00
Jeffrey Finkelstein
659bf58a4c head: print headings when reading multiple files
Fix a bug in which `head` failed to print headings for `stdin` inputs
when reading from multiple files, and fix another bug in which `head`
failed to print a blank line between the contents of a file and the
heading for the next file when reading multiple files. The output now
matches that of GNU `head`.
2021-05-16 12:03:10 -04:00
Jeffrey Finkelstein
97a49c7c95 wc: compute min width to format counts up front
Fix two issues with the string formatting width for counts displayed
by `wc`.

First, the output was previously not using the default minimum width
(seven characters) when reading from `stdin`. This commit corrects
this behavior to match GNU `wc`. For example,

    $ cat alice_in_wonderland.txt | wc
          5      57     302

Second, if at least 10^7 bytes were read from `stdin` *after* reading
from a smaller regular file, then every output row would have width
8. This disagrees with GNU `wc`, in which only the `stdin` row and the
total row would have width 8. This commit corrects this behavior to
match GNU `wc`. For example,

    $ printf "%.0s0" {1..10000000} | wc emptyfile.txt -
	  0       0       0 emptyfile.txt
	  0       1 10000000
	  0       1 10000000 total

Fixes #2186.
2021-05-15 21:41:47 -04:00
Sylvestre Ledru
620a5a5df6
Merge pull request #2210 from jhscheer/dns_lookup
who: fix `--lookup`
2021-05-15 21:18:12 +02:00
Jeffrey Finkelstein
e8d911d9d5 wc: correct some error messages for invalid inputs
Change the error messages that get printed to `stderr` for compatibility
with GNU `wc` when an input is a directory and when an input does not
exist.

Fixes #2211.
2021-05-15 10:35:21 -04:00
Jan Scheer
a4fc2b5106 who: fix --lookup
This closes #2181.

`who --lookup` is failing with a runtime panic (double free).
Since `crate::dns-lookup` already includes a safe wrapper for `getaddrinfo`
I used this crate instead of further debugging the existing code in
utmpx::canon_host().

* It was neccessary to remove the version constraint for libc in uucore.
2021-05-13 22:16:15 +02:00
Sylvestre Ledru
2178edf628
Merge pull request #2207 from jhscheer/issue_2204
date: fix format literal for nanoseconds
2021-05-12 13:14:23 +02:00
Jan Scheer
12a43d6eb3 date: fix format literal for nanoseconds 2021-05-12 10:21:24 +02:00
Sylvestre Ledru
a5f8ca60b5
Merge pull request #2199 from jhscheer/refactor_fsext
df/stat: refactor - reduce duplicate code
2021-05-12 08:41:16 +02:00
Sylvestre Ledru
6635301f32
Merge pull request #2194 from miDeb/sort-stable-merge
sort: make merging stable
2021-05-12 08:38:48 +02:00
Sylvestre Ledru
57ae202037
Merge pull request #2195 from nthery/wc_dash
wc: emit '-' in ouput when set on command-line
2021-05-12 08:37:55 +02:00
Sylvestre Ledru
68a3488cdc
Merge pull request #2202 from drocco007/test-negated-boolean
test: improve handling of inverted Boolean expressions
2021-05-12 08:34:41 +02:00
Jan Scheer
8200d399e8 date: fix format for nanoseconds 2021-05-11 23:03:59 +02:00
Daniel Rocco
2ec4bee350 test: improve handling of inverted Boolean expressions
- add `==` as undocumented alias of `=`

- handle negated comparison of `=` as literal

- negation generally applies to only the first expression of a Boolean chain,
  except when combining evaluation of two literal strings
2021-05-10 22:48:40 -04:00
Jan Scheer
203ee463c7 stat/uucore: refactor - move fsext.rs to uucore 2021-05-10 10:46:00 +02:00
Sylvestre Ledru
33206e1adc
Ignore test_domain_socket as it fails too often 2021-05-09 18:42:16 +02:00
Nicolas Thery
112b042769 wc: emit '-' in ouput when set on command-line
When stdin is explicitly specified on the command-line with '-', emit it
in the output stats to match GNU wc output.

Fixes #2188.
2021-05-09 15:47:05 +02:00
Michael Debertol
e0ebf907a4 sort: make merging stable
When merging files we need to prioritize files that occur earlier in the
command line arguments with -m.

This also makes the extsort merge step (and thus extsort itself) stable again.
2021-05-09 11:43:38 +02:00
Sylvestre Ledru
01a702c6fd
Merge branch 'master' into issue2167 2021-05-08 20:26:21 +02:00
Samuel Ainsworth
b8a3a8995f Fix test_split_bytes_prime_part_size 2021-05-08 14:25:21 +02:00
Samuel Ainsworth
7c1395366e Fix split's handling of non-UTF-8 files 2021-05-08 14:25:21 +02:00
Sylvestre Ledru
a74a729aa8 rustfmt the recent change 2021-05-08 13:13:52 +02:00
Jeffrey Finkelstein
525f71bada wc: rm leading space when printing multiple counts
Remove the leading space from the output of `wc` when printing two or
more types of counts.

Fixes #2173.
2021-05-08 13:11:09 +02:00
Jan Scheer
a885376583 uucore: refactor - reduce duplicate code related to fs::display_permissions
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`
2021-05-08 11:52:41 +02:00
David Carlier
c0c240f194 du: fix couple of du unit tests for FreeBSD. 2021-05-08 11:37:42 +02:00
Sylvestre Ledru
928fc59845 Ignore test_lookup until issue #2181 is fixed 2021-05-06 11:05:32 +02:00
jaggededgedjustice
a2658250fc
Fix fmt crashing on subtracting unsigned numbers (#2178) 2021-05-05 23:12:17 +02:00
Anup Mahindre
7d2b051866
Implement Total size feature (#2170)
* ls: Implement total size feature

- Implement total size reporting that was missing
- Fix minor formatting / readability nits

* tests: Add tests for ls total sizes feature

* ls: Fix MSRV build errors due to unsupported attributes for if blocks

* ls: Add windows support for total sizes feature

- Add windows support (defaults to file size as block sizes related
infromation is not avialable on windows)
- Renamed some functions
2021-05-05 23:03:25 +02:00
rethab
231bb7be93
Migrate mknod to clap, closes #2051 (#2056)
* mknod: add tests for fifo

* mknod: add test for character device
2021-05-05 22:59:40 +02:00
Sylvestre Ledru
86a8195166
Merge pull request #2172 from jhscheer/stat_test_selinux
stat: fix test to ignore selinux related output
2021-05-05 22:35:32 +02:00
Sylvestre Ledru
f83316f36e
Merge pull request #2156 from miDeb/sort-no-json-extsort
sort: don't rely on serde-json for extsort
2021-05-05 22:33:18 +02:00
Sylvestre Ledru
482e340e11
Merge branch 'master' into implement-more 2021-05-04 13:35:38 +02:00
Sylvestre Ledru
1edf4064f3
Merge pull request #2162 from bashi8128/basename-clap
basename: move from getopts to clap
2021-05-04 10:59:19 +02:00
Sylvestre Ledru
3f5dda66f4
Merge pull request #2138 from jhscheer/who2clap
who: move from getopts to clap (#2124)
2021-05-04 10:58:52 +02:00
Sylvestre Ledru
e3b7a8bd22
Merge pull request #2166 from jfinkels/wc-word-countable-lines
wc: add lines() method for iterating over lines
2021-05-04 09:53:08 +02:00
Jeffrey Finkelstein
0cafe2b70d wc: add tests for edge cases for wc on files 2021-05-03 21:07:32 -04:00
Jan Scheer
5bcfa88f0a stat: fix test to ignore selinux related output 2021-05-03 23:09:45 +02:00
Jan Scheer
56761ba584 stat: implement support for macos 2021-05-03 22:30:56 +02:00
David CARLIER
224c8b3f94 df output update (non inode mode) proposal specific for mac. on this platform, capacity column is also displayed. 2021-05-03 15:49:55 +01:00
bashi8128
91c736bd95 tests/basename: add tests for error messages 2021-05-03 23:22:00 +09:00
Sylvestre Ledru
0dfb3e36ab
Merge pull request #2164 from jhscheer/patch-4
tr: add test
2021-05-02 21:35:32 +02:00
Sylvestre Ledru
6c04d0d21e
Merge pull request #2155 from nthery/kill_clap
kill: migrate to clap
2021-05-02 18:45:29 +02:00
Jan Scheer
3fcac152f8
tr: add test 2021-05-02 18:35:52 +02:00
Michael Debertol
e99f157e6a Merge branch 'master' of https://github.com/uutils/coreutils into sort-no-json-extsort 2021-05-02 18:08:15 +02:00
Michael Debertol
8b35dd9741 add requested tests 2021-05-02 17:27:52 +02:00
Sylvestre Ledru
f8ec4a554c
Merge pull request #2161 from tertsdiepraam/ls/sort_order_and_subdirectory_listing
`ls`: C sort order and fix subdirectory listing
2021-05-02 17:21:56 +02:00
Sylvestre Ledru
79068d231f
Merge pull request #2158 from jhscheer/issue2147
tr: implement complement separately from delete or squeeze (#2147)
2021-05-02 17:21:21 +02:00
Terts Diepraam
fba245b176 ls: add -1 to tests to separate names with \n on windows 2021-05-02 14:26:23 +02:00
Dean Li
0e6b63b47b Add tests to check link fails with 1 or 3 argument(s) 2021-05-02 18:36:02 +08:00
Jan Scheer
8739139a7f Merge branch 'master' into issue2147 2021-05-02 12:35:19 +02:00
Jan Scheer
34c22dc3ad tr: fix complement if set2 is range 2021-05-02 12:15:16 +02:00
Terts Diepraam
361408cbe5 ls: remove case-insensitivity and leading period of name sort 2021-05-02 10:04:11 +02:00
Terts Diepraam
28c7800f73 ls: fix subdirectory name 2021-05-02 10:03:01 +02:00
Sylvestre Ledru
a34b49ad60 relpath(test) - fix: 'value assigned to 'result_stdout' is never read' 2021-05-02 09:42:53 +02:00
Sylvestre Ledru
c03a7d8856 uname(test): fix 'unused variable: result' 2021-05-02 09:41:09 +02:00
bashi8128
4275661020 tests/basename: add tests for --version, --help 2021-05-02 13:47:36 +09:00
Daniel Rocco
3c126bad72 test: implement parenthesized expressions, additional tests
- Replace the parser with a recursive descent implementation that handles
  parentheses and produces a stack of operations in postfix order.

  Parsing now operates directly on OsStrings passed by the uucore framework.

- Replace the dispatch mechanism with a stack machine operating on the
  symbol stack produced by the parser.

- Add tests for parenthesized expressions.

- Begin testing character encoding handling.
2021-05-01 22:40:47 -04:00
Daniel Rocco
c3912d53ac test: add tests for basic tests & edge cases
Some edge cases covered:

- no args
- operator by itself (!, -a, etc.)
- string, file tests of nothing
- compound negations
2021-05-01 22:40:47 -04:00
Sylvestre Ledru
7e07438b38
Merge pull request #2151 from jfinkels/2141-translate-and-squeeze
tr: implement translate and squeeze (-s) mode
2021-05-01 23:27:43 +02:00
Sylvestre Ledru
038025899d
Merge pull request #2137 from ricardoaiglesias/base64-clap
base64: Moved argument parsing to clap.
2021-05-01 23:20:21 +02:00
Sylvestre Ledru
e2c228e821
Merge pull request #2157 from tertsdiepraam/ls/fix_style_text
`ls`: fix time style test
2021-05-01 21:38:39 +02:00
Ricardo Iglesias
f307de22d0 base64: Refactor argument parsing
Moved most of the argument parsing logic to `base32/base_common.rs` to
allow for significant code reuse.
2021-05-01 11:36:46 -07:00
Ricardo Iglesias
05b20c32a9 base64: Moved argument parsing to clap.
Moved argument parsing to clap and added tests to cover using "-" as
stdin, passing in too many file arguments, and updated the "wrap" error
message in the tests.
2021-05-01 11:36:46 -07:00
Jan Scheer
83eb704415 Merge branch 'master' into issue2147 2021-05-01 18:52:35 +02:00
Jan Scheer
117e84eed3 tr: implement complement separately from delete or squeeze (#2147) 2021-05-01 18:46:13 +02:00
Sylvestre Ledru
bffcb431b5
Merge pull request #2148 from jhscheer/pinky2clap
pinky: move from getopts to clap (#2123)
2021-05-01 17:49:10 +02:00
Sylvestre Ledru
34bf7cc5ea
Merge pull request #2150 from jhscheer/fix_clap_short
tr/dirname: fix clap short_alias
2021-05-01 17:39:15 +02:00