Commit graph

43 commits

Author SHA1 Message Date
Ben Wiederhake
4fcf912c85 truncate: remove two-year-old file-creation todos
In commit 129cfe12b8
2024-03-23 13:57:15 +01:00
zhitkoff
cb7479e823 uucore: implement SI suffixes R and Q 2023-10-17 10:50:50 -04:00
Terts Diepraam
c3f9e19a3b all: normalize license notice in all *.rs files 2023-08-24 12:21:09 +02:00
Daniel Hofstetter
6988eb7ec6 tests: expand wildcard imports 2023-03-20 15:32:35 +01:00
Daniel Hofstetter
3eeb5dda30 tests: adapt to clap's modified error messages 2023-03-09 10:06:20 +01:00
Daniel Hofstetter
f6b646e4e5 clippy: fix warnings introduced with Rust 1.67.0 2023-01-27 17:37:56 +01:00
Joining7943
1fadeb43b2 tests/util: Do not trim stderr in CmdResult::stderr_is. Add method stderr_trimmed_is.
Fix tests assert whitespace instead of trimming it. Disable some tests in `test_tr` because `tr`
produces too many newlines.
2023-01-22 14:56:19 +01:00
Terts Diepraam
9cce0bed7f truncate: update to clap 4 2022-10-13 17:50:43 +02:00
Omer Tuchfeld
f3895124b9 Remove impractical test creating a file too large 2022-02-22 14:23:46 +01:00
Omer Tuchfeld
fa60898354 Adjust 32-bit tests for tail,split,truncate,head 2022-02-22 13:49:20 +01:00
Sylvestre Ledru
c2e3f4109c
Merge pull request #2944 from jfinkels/truncate-fifo
truncate: error when trying to truncate a fifo
2022-02-12 11:36:17 +01:00
Sam Caldwell
ea5541db56 truncate: add test_invalid_option 2022-02-01 13:42:50 -07:00
Jeffrey Finkelstein
fe5b537f56 truncate: error when trying to truncate a fifo
Terminate the `truncate` program with an error message when trying to
truncate a named pipe (also known as a fifo).
2022-01-30 22:03:12 -05:00
Sylvestre Ledru
57ee6b5302
Merge branch 'main' into truncate-no-such-dir 2022-01-29 09:58:17 +01:00
Jeffrey Finkelstein
0454d3b243 truncate: prevent underflow when reducing size
Prevent usize underflow when reducing the size of a file by more than
its current size. For example, if `f` is a file with 3 bytes, then

    truncate -s-5 f

will now set the size of the file to 0 instead of causing a panic.
2022-01-28 22:44:07 -05:00
Jeffrey Finkelstein
c780c96e17 truncate: better error msg when dir does not exist
Improve the error message that gets printed when a directory does not
exist. After this commit, the error message is

    truncate: cannot open '{file}' for writing: No such file or directory

where `{file}` is the name of a file in a directory that does not
exist.
2022-01-28 21:21:37 -05:00
Jeffrey Finkelstein
1e5e637990 truncate: add a division by zero error
Add an error for division by zero. Previously, running `truncate -s /0
file` or `-s %0` would panic due to division by zero. After this
change, it writes an error message "division by zero" to stderr and
terminates with an error code.
2022-01-27 21:12:59 -05:00
Jeffrey Finkelstein
129cfe12b8 truncate: create non-existent file by default
Fix the behavior of truncate when given a non-existent file so that it
correctly creates the file before truncating it (unless the
`--no-create` option is also given).
2022-01-23 11:24:53 -05:00
Jan Scheer
c0be979611 fix some issues with locale (replace "LANGUAGE" with "LC_ALL")
`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 `'`
2021-06-23 11:30:28 +02:00
Jan Scheer
f8e96150f8 fix clippy warnings and spelling
* add some missing LICENSE headers
2021-06-04 15:39:34 +02:00
Jan Scheer
5898b99627 truncate: add error handling for SIZE argument
* add tests for SIZE argument
* fix clap argument handling for --size and --reference
2021-06-02 22:08:42 +02:00
Jan Scheer
cc659c8572 Merge branch 'master' of github.com:uutils/coreutils into refactoring_parse_size 2021-06-01 12:35:48 +02:00
Jan Scheer
8bf1e33b5d Merge branch 'master' of github.com:uutils/coreutils into refactoring_parse_size
* truncate: use "parse_size" from uucore
* workaround fix for "test_reference"
2021-05-31 19:11:06 +02:00
Roy Ivy III
3f35e0a421 refactor ~ cargo make format 2021-05-31 08:23:58 -05:00
Roy Ivy III
4e20dedf58 tests ~ refactor/polish spelling (comments, names, and exceptions) 2021-05-31 08:23:57 -05:00
Jeffrey Finkelstein
4e73b919e9 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-29 15:11:27 +02:00
Jan Scheer
3aeccfd802 fix a lot of clippy warnings 2021-05-29 15:11:22 +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
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
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
Sylvestre Ledru
d2913f8080 rustfmt the recent change 2021-05-01 13:12:10 +02:00
Sylvestre Ledru
33139817a2
Merge pull request #2136 from jaggededgedjustice/allow-truncate-size-and-reference
Allow truncate to take --size and --reference
2021-04-27 22:43:25 +02:00
Ricardo Iglesias
ae0cabc60a Moved argument parsing to uumain. 2021-04-26 20:15:11 -07:00
James Robson
a7037b1ca9 Allow truncate to take --size and --reference 2021-04-26 18:39:32 +01:00
James Robson
9f6a881592 improve assert error messages 2021-04-25 13:46:57 +01:00
James Robson
e9e3d41008 Expand tests for truncate 2021-04-24 15:25:14 +01:00
Sylvestre Ledru
3ac481e4d3 rustfmt the recent change 2021-04-24 12:46:06 +02:00
James Robson
b68ecf1269 Allow space in truncate --size 2021-04-23 16:36:46 +01:00
Sylvestre Ledru
f888616c0b tests(truncate): Add more tests 2020-10-23 00:36:09 +02:00
Roy Ivy III
de0375f909 tests ~ reorganize tests 2020-06-01 18:30:04 -05:00
Renamed from tests/test_truncate.rs (Browse further)