Commit graph

27 commits

Author SHA1 Message Date
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)