Commit graph

216 commits

Author SHA1 Message Date
Michael Debertol
06b3092f5f sort: fix debug output for zeros / invalid numbers
We were reporting "no match" when sorting something like "0 ". This is
because we don't distinguish between 0 and invalid lines when sorting.
For debug output we have to get this information back.
2021-06-01 18:18:51 +02:00
Sylvestre Ledru
badf7aacb7
Merge pull request #2300 from tertsdiepraam/pr
Implement `pr` (resurrection of the resurrected PR)
2021-05-31 21:14:57 +02:00
Roy Ivy III
4e20dedf58 tests ~ refactor/polish spelling (comments, names, and exceptions) 2021-05-31 08:23:57 -05:00
Terts Diepraam
7690dc018f Merge branch 'master' into pr 2021-05-31 15:23:06 +02:00
Michael Debertol
dc63133f14
sort: correctly inherit global flags for keys (#2302)
Closes #2254. We should only inherit global settings for keys when there
are absolutely no options attached to the key.

The default key (matching the whole line) is implicitly added only if no
keys are supplied.

Improved some error messages by including more context.
2021-05-29 23:25:56 +02:00
Terts Diepraam
bc1870c0a7 Merge branch 'master' into pr 2021-05-29 19:21:31 +02:00
Michael Debertol
e9656a6c32
sort: make GNU test sort-debug-keys pass (#2269)
* sort: disable support for thousand separators

In order to be compatible with GNU, we have to disable thousands
separators. GNU does not enable them for the C locale, either.

Once we add support for locales we can add this feature back.

* sort: delete unused fixtures

* sort: compare -0 and 0 equal

I must have misunderstood this when implementing, but GNU considers
-0, 0, and invalid numbers to be equal.

* sort: strip blanks before applying the char index

* sort: don't crash when key start is after key end

* sort: add "no match" for months at the first non-whitespace char

We should put the "^ no match for key" indicator at the first
non-whitespace character of a field.

* sort: improve support for e notation

* sort: use maches! macros
2021-05-28 22:38:29 +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
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
Jeffrey Finkelstein
0cafe2b70d wc: add tests for edge cases for wc on files 2021-05-03 21:07:32 -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
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
Sylvestre Ledru
a37e3181a2
Merge pull request #2130 from electricboogie/master
sort: implement --buffer-size and --temporary-directory (external sort)
2021-04-28 09:21:14 +02:00
Ricardo Iglesias
d56462a4b3 base32: Fixed style violations. Added tests
Tests now cover using "-" as standard input and reading from a file.
2021-04-26 08:00:55 -07:00
electricboogie
4c395146dd Merge branch 'master' of https://github.com/uutils/coreutils 2021-04-25 10:11:27 -05:00
Michael Debertol
e6f6b109a5 sort: implement --debug
This adds a --debug flag, which, when activated, will draw lines below
the characters that are actually used for comparisons.

This is not a complete implementation of --debug. It should, quoting the man page
for GNU sort: "annotate the part of the line used to sort, and warn
about questionable usage to stderr". Warning about "questionable usage"
is not part of this patch.

This change required some adjustments to be able to get the range that
is actually used for comparisons. Most notably, general numeric comparisons
were rewritten, fixing some bugs along the lines.

Testing is mostly done by adding fixtures for the expected debug output of
existing tests.
2021-04-23 22:36:15 +02:00
electricboogie
25021f31eb Incorporate overhead of Line struct 2021-04-19 21:24:52 -05:00
Michael Debertol
4bbbe3a3f2
sort: implement numeric string comparison (#2070)
* sort: implement numeric string comparison

This implements -n and -h using a string comparison algorithm instead
of parsing each number to a f64 and comparing those.

This should result in a moderate performance increase and eliminate loss
of precision.

* cache parsed f64 numbers

For general numeric comparisons we have to parse numbers as f64,
as this behavior is explicitly documented by GNU coreutils.
We can however cache the parsed value to speed up comparisons.

* fix leading zeroes for negative numbers

* use more appropriate name for exponent

* improvements to the parse function

* move checks into main loop and fix thousands separator condition

* remove unneeded checks

* rustfmt
2021-04-17 13:49:35 +02:00
electricboogie
a76d452f75
Sort: More small fixes (#2065)
* Various fixes and performance improvements

* fix a typo

Co-authored-by: Michael Debertol <michael.debertol@gmail.com>

* Fix month parse for months with leading whitespace

* Implement test for months whitespace fix

* Confirm human numeric works as expected with whitespace with a test

* Correct arg help value name for --parallel

* Fix SemVer non version lines/empty line sorting with a test

Co-authored-by: Sylvestre Ledru <sledru@mozilla.com>
Co-authored-by: Michael Debertol <michael.debertol@gmail.com>
2021-04-17 10:06:19 +02:00
Árni Dagur
eb4971e6f4
cat: Unrevert splice patch (#2020)
* cat: Unrevert splice patch

* cat: Add fifo test

* cat: Add tests for error cases

* cat: Add tests for character devices

* wc: Make sure we handle short splice writes

* cat: Fix tests for 1.40.0 compiler

* cat: Run rustfmt on test_cat.rs

* Run 'cargo +1.40.0 update'
2021-04-10 22:19:53 +02:00
Sylvestre Ledru
bf1944271c remove .DS_Store 2021-04-10 21:57:03 +02:00
Michael Debertol
69f4410a8a
sort: dedup using compare_by (#2064)
compare_by is the function used for sorting, we should use it for dedup
as well.
2021-04-10 19:49:10 +02:00
electricboogie
e5113ad00e
Sort: Various fixes and performance improvements (#2057)
* Various fixes and performance improvements

* fix a typo

Co-authored-by: Michael Debertol <michael.debertol@gmail.com>

Co-authored-by: Sylvestre Ledru <sledru@mozilla.com>
Co-authored-by: Michael Debertol <michael.debertol@gmail.com>
2021-04-10 11:56:20 +02:00
Sivachandran
ee070028e4
install: implement stripping symbol table (#2047) 2021-04-10 11:53:29 +02:00
Sylvestre Ledru
844e318a67
Merge branch 'master' into pr 2021-04-09 22:02:25 +02:00
electricboogie
8474249e5f
Sort: Implement stable sort, ignore non-printing, month sort dedup, auto parallel sort through rayon, zero terminated sort, check silent (#2008) 2021-04-08 22:07:09 +02:00
Yagiz Degirmenci
c965effe07
fold: move to clap, add tests (#2015) 2021-04-06 22:51:27 +02:00
Sylvestre Ledru
f57eb0fdfa
Merge pull request #1993 from cbjadwani/master
uniq: Implement --group option
2021-04-05 22:33:04 +02:00
Yagiz Degirmenci
cbe07c93c6
cksum: add tests and fixtures (#1923) 2021-04-05 22:21:21 +02:00
Daniel Rocco
e5c61a28be fold: variable width tabs, guard treating tab as whitespace
Treat tab chars as advancing to the next tab stop rather than having a fixed
8-column width.

Also treat tab as a whitespace split target only when splitting on word
boundaries.
2021-04-05 08:55:07 -04:00
Chirag Jadwani
19c6a42de5 uniq: implement group option 2021-04-04 15:22:17 +05:30
Paul Otten
7859bf885f Consistency with GNU version of du when doing du -h on an empty file 2021-04-01 19:42:43 -04:00
Mikadore
8320b1ec5f
Rewrote head (#1911)
See https://github.com/uutils/coreutils/pull/1911
for the details
2021-03-29 13:08:48 +02:00
jaggededgedjustice
88d0bb01c0
Add shuf tests (#1958)
* Add tests for shuf

* Fixup GNU tests for shuf
2021-03-28 17:52:01 +02:00
Max Semenik
62fe68850e pr: Fixes after rebasing
Only the minimum needed to:
* Make everything compile without warnings
* Move files according to the new project structure
* Make tests pass
2021-03-26 17:57:19 +03:00
tilakpatidar
75b35e6002 pr: remove not required tests 2021-03-26 14:11:15 +03:00
tilakpatidar
054c05d5d8 pr: refactor get_lines_for_printing, write_columns, recreate_arguments
pr: extract recreate_arguments

pr: refactor get_line_for_printing

pr: refactor get_lines_for_printing

pr: refactor fetch_indexes generate for write_columns

pr: refactor write_columns

pr: refactor write_columns
2021-03-26 14:11:15 +03:00
tilakpatidar
40e7f3d900 pr: add -J and -S option
pr: add -J option

pr: add -S option
2021-03-26 14:11:15 +03:00
tilakpatidar
a4b723233a pr: add more tests for form feed and include page_width option W 2021-03-26 14:11:15 +03:00
tilakpatidar
3be5dc6923 pr: fix form feed
pr: fix form feed

pr: Rustfmt

pr: add test for ff and -l option
2021-03-26 14:11:15 +03:00
Tilak Patidar
5956894d00 pr: add -m and -o option
pr: Add -o option
2021-03-26 14:11:14 +03:00
Tilak Patidar
dd07aed4d1 pr: add column separator option 2021-03-26 14:11:14 +03:00
Tilak Patidar
69371ce3ce pr: add tests for --column with across option 2021-03-26 14:11:14 +03:00
Tilak Patidar
f497fb9d88 pr: read from stdin 2021-03-26 14:11:14 +03:00
Tilak Patidar
d9084a7399 pr: implement across option and fix tests 2021-03-26 14:11:14 +03:00
Tilak Patidar
f3676573b5 pr: print padded string for each column and handle tab issues
pr: Print fixed padded string for each column

pr: Fix display length vs str length due to tabs
2021-03-26 14:11:14 +03:00
Tilak Patidar
b578bb6563 pr: add test for -t -l -r option
pr: Add test for -l option

pr: Add test for -r suppress error option
2021-03-26 14:11:14 +03:00
Tilak Patidar
b742230dbb pr: fix page ranges
pr: Fix page ranges
2021-03-26 14:11:14 +03:00
Tilak Patidar
88ec02a61c pr: add suport for -n [char][width] and -N
pr: Fix long name for -n

pr: Add -N first line number option

pr: Add -n[char][width] support
2021-03-26 14:11:14 +03:00
Tilak Patidar
afc58eb6ea pr: add tests for -n -h -d option
pr: Add test for -h option

pr: Add test for -d option
2021-03-26 14:11:14 +03:00
tilakpatidar
629236bd39 pr: add first test 2021-03-26 14:11:14 +03:00
Yagiz Degirmenci
545fe7d887
feat(unexpand): move from getopts to clap (#1883)
* feat: move unexpand to clap

* chore: allow muliple files

* test: add test fixture, test reading from a file

* test: fix typo on file name, add test for multiple inputs

* chore: use 'success()' instead of asserting

* chore: delete unused variables

* chore: use help instead of long_help, break long line
2021-03-23 09:42:05 +01:00
Neculai Balaban
c6927d97c8
cp: add support for -x/--one-file-system (#1840) 2021-03-19 21:15:35 +01:00
Sylvestre Ledru
fcccc2a973
Merge pull request #1826 from pfnsec/master
head: add support for -z/--zero-terminated
2021-03-18 21:37:12 +01:00
Peter Sherman
13e61c3234 head: add support for -z/--zero-terminated 2021-03-15 15:56:11 +00:00
Chirag Jadwani
116e253cc0 uniq: Fix skip fields
Current implementation of the skip fields logic does not handle
multibyte code points correctly. It assumes each code point (`char`) is
one byte. If the skipped part of the input line has any multibyte code
points then this can cause fields not being skipped correctly (field
start index is calculated to be before it actually starts).
2021-03-15 18:48:54 +05:30
Chirag Jadwani
ce4342d12e uniq: Fix panic on invalid utf-8 input 2021-03-15 18:48:54 +05:30
Michael Kefeder
e1626b8c64
ptx: ignore empty regex (#1808)
* ptx: ignore empty -W regex

* ptx: test to verify empty -W regex is ignored

* tests/ptx: verify word regexp from cmd-line is used
2021-03-12 21:52:37 +01:00
Daniel Rocco
0e02607dc7 numfmt: implement --field 2021-03-08 10:53:34 -05:00
Daniel Rocco
d06f91fbe2
numfmt: align format output values with GNU (#1745)
When converting to SI or IEC, produce values that align with the conventions
used by GNU numfmt.

- values > 10 are represented without a decimal place, so 10000 becomes 10K
  instead of 10.0K

- when truncating, take the ceiling of the value, so 100001 becomes 101K

- values < 10 are truncated to the highest tenth, so 1001 becomes 1.1K

closes #1726
2021-03-06 18:26:05 +01:00
Chad Brewbaker
05d8cc59c4
bug(wc): Add a test for unexpected behavior (#1723) 2021-02-16 13:36:49 +01:00
jaggededgedjustice
18c39daed7
fold: Handle input with newlines (#1680)
The read_line function appends to the given buffer which is never
cleared. This leads to lines being duplicated.
2021-01-05 09:10:01 +01:00
Stéphane Campinas
89bf7a726e csplit: refresh of the previous PR 2020-12-28 17:21:29 +01:00
Piyush Jaipuriayar
3ca8ba997c
hashsum: added blake2 as a hashing algorithm (#1651) 2020-12-08 23:32:02 +01:00
Sylvestre Ledru
601690b079 test(expand): Add some tests for expand (#1505) 2020-05-15 18:09:10 -05:00
Roy Ivy III
7b96432eff
Merge pull request #1504 from sylvestre/fmt
test(fmt): add some small initial tests
2020-05-10 12:25:18 -05:00
elgris
71ba8b3fd6 sort: add "dictionary-order" flag.
The flag makes 'sort' command ignore non-dictionary symbols
(non-alphanumeric and non-spaces). The only difference with GNU sort is
that it takes ALL alphanumeric symbols, not only ASCII ones.
2020-05-07 23:08:24 +02:00
Sylvestre Ledru
9b0129716f test(fmt): Add some tests for fmt
Even if it is a bit broken for now
2020-05-06 00:38:22 +02:00
Roy Ivy III
31655fc004 env: add support for new '--file' option (includes testing)
.# Discussion

This commit adds support for a '-f'/'--file' option which reads "KEY=VALUE" lines from
a config (or ini) style text file and sets the corresponding environment key. This is
modeled after the same option in the `dotenv` and `godotenv` commands. Notably, this
commit does *not* add automatic loading of ".env" configuration files.

The environment variables set by reading the configuration file are set prior to any
unset (eg, `-u BAR`) or set (eg, `FOO=bar`) actions. Files are loaded in order with
later files overwriting any overlapping environment variables, then, unset actions (in
command line order) are executed, then, finally, set actions (in command line order)
are executed.

[1] [`dotenv`](https://github.com/bkeepers/dotenv)
[2] [`godotenv`](https://github.com/joho/godotenv)
2019-04-29 09:50:22 -05:00
Julio Rincon
29c6ad5f6a tests: untrimmed stdout assertion (fix #1235) 2019-02-08 07:54:48 +11:00
xplorld
47f5f12759 sort: treat "NaN" as string in numeric sort 2018-09-03 22:28:18 -07:00
Konstantin Pospelov
e9fd9d623d join: implement option to suppress joined lines 2018-06-09 12:11:58 +03:00
Konstantin Pospelov
4b8d4bfc05 join: fix autoformat
There was an issue with autoformat when the files had a different
number of columns in the first line. This commit fixes the issue and
extends the related test to cover this case.
2018-04-15 17:42:52 +03:00
Konstantin Pospelov
7dc8ff62cc join: support headers 2018-04-11 22:55:44 +03:00
bootandy
ea504bf0ec du: add test for -d flag 2018-03-20 17:55:31 -04:00
bootandy
e253406026 du: Fix incorrect block size assumption.
du and other tools like stat assume a 512 byte block. ls is the only
tool to use 1024.

Add Simple set of tests
2018-03-20 16:59:29 -04:00
Konstantin Pospelov
128a38965e join: support custom empty filler 2018-01-17 23:26:00 +03:00
Konstantin Pospelov
12c5c951fb join: implement the -o option 2018-01-06 22:49:07 +03:00
Konstantin Pospelov
4e0a0cf7bb join: implement the -t option 2017-12-24 16:22:48 +03:00
Konstantin Pospelov
b33ce67d91 join: implement basic functionality
The basic implementation of join with some tests. The supported
options: -1, -2, -j, -a, -i.
2017-12-14 00:02:42 +03:00
shutefan
bf2a591b0a tail: suppress headers when --quiet flag is used 2017-10-05 21:25:21 +02:00
Joshua Miller
7dafb649d5 implement many copy flags
- Refactored towards extensibility
2017-07-16 19:20:07 -05:00
Jian Zeng
daba29b832 Merge pull request #1026 from evestera/cat-numlines-notrailing
cat: fix for numbered lines w/ no trailing newline
2017-01-23 06:39:31 -06:00
Erik Vesteraas
81996915df cat: fix for numbered lines w/ no trailing newline
Make at_line_start persist between printing each file. This fixes an
issue when numbering lines in the output and one of the input files
does not have a trailing newline.
2017-01-23 03:34:47 +01:00
Anthony Deschamps
6dc1eb54c0 sort: Implement ignore-case
Test included.
2017-01-21 13:30:22 -05:00
Wim Hueskes
2f12b06ba1 od: implement --traditional 2016-09-02 21:24:29 +02:00
Wim Hueskes
9e33c3a48c od: fix command-line parsing of file names 2016-09-01 00:23:34 +02:00
Alex Lyon
362cabe1a6 hashsum: implement SHAKE-128 and SHAKE-256 2016-08-30 17:33:18 -07:00
David Laban
e1af1520e7 sort: make compare_by honour settings.reverse
This allows sort --merge --reverse to work as well.
2016-08-13 00:42:43 +01:00
David Laban
8a8319a337 sort --merge works, but ignores --unique and --reverse
FileMerger receives Lines Iterables of the pre-sorted input files
via push_file() It implements Iterator, which yields lines from the
input files in (merged) sorted order. If the input files are not sorted,
then the behavior is undefined.

Internally, FileMerger uses a
std::collections::BinaryHeap<MergeableFile>.

MergeableFile is an internal helper that implements Ord in a way that
BinaryHeap can use (note that we want smallest-first, but BinaryHeap
returns largest first, so MergeableFile::cmp() calls reverse() on
whatever compare_by() returns.
2016-08-13 00:42:43 +01:00
Nathan Ross
1880c46acd Merge pull request #946 from ChrisNikkel/feature/zero_terminated
uniq: add -z option to allow for zero terminated input and output
2016-08-06 22:49:10 -04:00
Chris Nikkel
c0b2da7c01 uniq: add test for zero terminated input and output 2016-08-06 18:41:39 -07:00
Nathan Ross
cb6f84e3d8 tests/cut: positive testcases for feature complete 2016-08-06 17:11:54 -04:00
David Laban
6751d2c708 implement sort --stable
Made a new function sort_by(lines, compare_fns), which accepts a
list of compare_fns and calls lines.sort_by() with a closure that
calls each compare_fn in turn until one returns something other
than equal.

Default behavior ensures that String::cmp is the last element in the
compare_fns list (referred to as 'last resort' sorting by man sort).
Passing --stable (-s) turns this behaviour off.

Test cases provided for `sort --month` and `sort --month --stable`.
2016-08-03 07:56:40 +01:00
Jeremy Neptune
b59016cbd7
cp: fixed failing tests due to git's weirdness with files
Made variable names in test_cp.rs more descriptive
2016-07-15 15:29:47 -04:00
Jeremy Neptune
97bb134fc9
cp: added fixtures required for testing 2016-07-15 13:23:12 -04:00
palaviv
3fd8136423 sort: Support check 2016-06-14 22:21:30 +03:00
palaviv
3bc5a5f769 sort: support multiple input files 2016-06-14 21:25:29 +03:00
palaviv
87455f998a sort: Version sort support 2016-06-14 20:33:09 +03:00
palaviv
d4ffbe0526 sort: unique option support 2016-06-11 15:46:41 +03:00
Mariano Casco
abb9501894 tail: test -f with no files 2016-05-31 17:40:06 -03:00
Mariano Casco
9c584bab9d tail: test following multiple files
The test_follow_multiple() test verifies that input is read upon append
on both files and that headers are printed when expected.
2016-05-30 17:34:53 -03:00
Knight
92e95c7263 dircolors: tests added 2016-05-11 00:43:51 +08:00
Valentin Lorentz
2fd7164cda tail: Implement tail -z.
This options makes tail use NULL instead of newline as a line
delimiter.
2016-04-02 12:32:33 +02:00
Joseph Crail
6b129887d6 tests/sort: add test for default mode 2016-03-29 00:58:24 -04:00
Joseph Crail
b290c10845 tests/sort: refactor to match other tests
Instead of using numerals to denote individual cases, I used descriptive
case names. I also changed the extension for the expected output fixture
to match other tests.

I removed one redundant test and another unnecessary helper function.
2016-03-29 00:58:24 -04:00
Nick Fitzgerald
9824bc4db3 Add a test for tail -c <BYTES> from stdin 2016-03-26 11:56:00 -07:00
Nick Fitzgerald
445233389e Add a test for tail -c <BYTES> <FILE> 2016-03-26 11:52:10 -07:00
Joseph Crail
55c0b1786f tests/sort: add tests for month sort 2016-03-25 16:55:58 -04:00
Nick Fitzgerald
161f96dc8c tests/tail: Rename tail test fixture contents to be easier to read
The repetition of "foo" and "bar" made for difficult-to-read assertion failures
when hacking on `tail`. I think that having each line have unique contents makes
it a bit easier to parse.
2016-03-21 07:51:42 -07:00
Chirag B. Jadwani
676e3718c3 uniq: add tests 2016-02-29 11:07:16 +05:30
Nathan Ross
d1e785c1dc comm: additional tests and status/stderr checking for existing tests 2016-02-22 09:59:06 -05:00
Leonid Shalupov
1b48438b44 .gitattributes: treat tests/fixtures/** as binary data to prevent CRLF convertion by git under Windows 2016-02-14 17:09:47 +01:00
Joseph Crail
cf399faad2 Add initial tests for default values 2015-12-12 16:24:48 -05:00
Michael Gehring
2f4ae615ed comm: add basic tests 2015-11-28 20:51:11 +01:00
Nathan Ross
a21c54e2cd rewrite tests for cargo compat, decoupled directory, output handling 2015-11-23 02:04:15 -05:00