Commit graph

2104 commits

Author SHA1 Message Date
Joining7943
fdf0f96a01 tests/util: Restructure UCommand to run in shell per default. Introduce constant TESTS_BINARY.
Summary of changes in tests/util:

* Introduce global constant TESTS_BINARY holding the path to `coreutils`
* Implement running an arbitrary command in a sh or cmd shell per default.
* Implement std::fmt::Display for UCommand.
* Change usages of UCommand::util_name from &Option<OsStr> to Option<OsStr>
* `UCommand::new_from_tmp`: Use OsStr directly instead of TempDir -> String -> OsStr
* Collect arguments in `UCommand::args` field
* Build environment variables in `UCommand` itself instead of `std::process::Command`
* Move building of std::process:Command from fields in UCommand to own method `build`
* Remove assertions of UCommand::has_run in arg, args and env.

Summary of changes in tests/by-util:

* Remove usages of UCommand::raw. Fix tests to use UCommand::to_string.
* test_test: Adjust test_invalid_utf8_integer_compare to use `UCommand::args`
* test_chmod: run_single_test
* test_pwd: symlinked_env
* test_cp:
    Fix the usage of &Option<OsStr> in `test_src_base_dot`
    Refactor test_src_base_dot to not use UCommand::new but ts.ucmd() instead
2023-02-17 17:39:33 +01:00
Terts Diepraam
9fdce975fd
Merge pull request #4359 from dmatos2012/chmod-multiple-files-error
chmod: change permissions for files present even when there is a missing file
2023-02-17 11:27:32 +01:00
David Matos
946c8d2d4a chmod: change permissions for files present even when there is a missing file 2023-02-16 23:13:06 +01:00
Joining7943
f610f33aa7
tests/util: Don't trim output in CmdResult::stdout_matches and stdout_does_not_match (#4304)
* tests/util: Fix documentation of UCommand::stderr_only and usage_error

* tests/util: Remove trimming from CmdResult::stdout_matches and stdout_does_not_match. Fix tests.

The tests are fixed to match the trailing newline instead of ignoring it.
2023-02-16 15:33:33 +01:00
Terts Diepraam
ff5000d4d0
Merge pull request #4239 from Joining7943/tail-fix-parsing-of-sleep-interval
`tail`: fix argument parsing of sleep interval
2023-02-16 15:14:53 +01:00
Sylvestre Ledru
d3fc0e8706
Merge pull request #4314 from cakebaker/comm_total_with_output_delimiter
comm: use delimiter on "total" line
2023-02-16 14:24:02 +01:00
Terts Diepraam
df7fe29095
Merge pull request #4339 from howjmay/tr-newline
tr: Remove the extra newline in stderr
2023-02-14 22:58:40 +01:00
Yang Hau
ec81a23afc tr: Remove the extra newline in stderr
closes #4301
2023-02-15 02:04:43 +08:00
Jeffrey Finkelstein
c6d9d7f11c Clippy fixes 2023-02-13 21:33:42 -05:00
Joining7943
0ed6a9f882 tail: Fix parsing of sleep interval. Use duration parser from fundu crate.
Activate tests for parsing sleep interval
2023-02-12 20:23:55 +01:00
Daniel Hofstetter
a22749ec57 comm: enable "no_arguments" & "one_argument" tests 2023-02-09 10:51:32 +01:00
Daniel Hofstetter
ccf999473c comm: use delimiter on "total" line 2023-02-07 09:22:55 +01:00
Sylvestre Ledru
efc70ade68
Merge pull request #4260 from sbentmar/expand-fix-perl-failures
expand: improve plus specifier handling
2023-01-28 18:15:08 +01:00
Sylvestre Ledru
d8c3205d4c
Merge pull request #4300 from cakebaker/comm_total
comm: implement --total
2023-01-28 18:14:17 +01:00
Joining7943
c809bb3888 tests/tail: Disable test_follow_with_pid on freebsd because of intermittent failures in the ci 2023-01-28 13:02:33 +01:00
Sebastian Bentmar Holgersson
1bf723fe40 expand: fix formatting issues and cleanup 2023-01-27 21:08:16 +01:00
Sebastian Bentmar Holgersson
69d8729598 expand: replace while loop with constant time algorithm 2023-01-27 21:08:16 +01:00
Sebastian Bentmar Holgersson
ddc6fabca0 expand: all perl tests passing 2023-01-27 21:08:16 +01:00
Sebastian Bentmar Holgersson
cbab8677e6 expand: improve handing of + 2023-01-27 21:08:16 +01:00
Daniel Hofstetter
f6b646e4e5 clippy: fix warnings introduced with Rust 1.67.0 2023-01-27 17:37:56 +01:00
Terts Diepraam
fc7e51a4f8
Merge pull request #4261 from Joining7943/tests-util-enhance-cmdresult
`tests/util`: Implement enhancements of `CmdResult` #4259
2023-01-25 10:06:32 +01:00
Daniel Hofstetter
b06485990d comm: implement --total 2023-01-24 16:49:43 +01:00
Terts Diepraam
8c35465e03
Merge pull request #4265 from sylvestre/add_test_test
test: add a test matching what busybox is doing
2023-01-22 23:42:54 +01:00
Sylvestre Ledru
6f95f0953b
Merge pull request #4271 from eds-collabora/eds/nice
Support legacy argument syntax for nice
2023-01-22 20:57:08 +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
Joining7943
37e06edadc tests/util: Introduce CmdResult::stdout_str_apply ... to preprocess stdout, stderr before asserting 2023-01-22 14:48:23 +01:00
Emil Suleymanov
50c1833c11
cp: require preserve only certain attributes (#4099)
* cp: require preserve only certain attributes

# Conflicts:
#	src/uu/cp/src/copydir.rs
#	src/uu/cp/src/cp.rs

* tests/cp: preserve all and preserve xattr tests with todos

* tests/cp: rename preserve tests

* tests/cp: add android fail test for preserve=xattr

On Android, this cp with explicit preserve of xattr must fail, because of the limitations of the filesystem setup used on Android.

* cp: verify some metadata in cp preserve tests

# Conflicts:
#	tests/by-util/test_cp.rs

* cp: run test_cp_preserve_all in all OS's but only check metadata on linux

* test/cp: don't expect the mode to change in explicit cp preserve

* cp: attributes struct instead of enum for unified required tracking

* cp: refactor preserver and handle_preserve

# Conflicts:
#	src/uu/cp/src/cp.rs

* cp: update preserve attr to max

* test/cp: fix the preserve xattr test

Access timestamps appear to be modified only in this test. Running the command directly does not alter the access timestamp.

* cp/test: preserve all and context case

* cp: fix preserve args value source

* test/cp: don't check mtime on freebsd

* test/cp: don't check mtime on macos

* test/cp: fix freebsd deps

* test/cp: support freebsd tests

* cp: simplify try_set_from_string

* cp: parse context attr in preserve in any case to show warning later

* cp: print warnings for attribute errors if not required

* cp: show SELinux warning only once

* cp: show SELinux warning without error

* Revert "cp: show SELinux warning without error"

This reverts commit d130cf0d8c8e28ac2c903413992613241decf879.

* cp: add documentation for preserve components

* cp: simplify try_set_from_string

* cp: EN_US "behavior" spelling for cspell
2023-01-19 13:02:06 +01:00
Ed Smith
8aa9f346ef Support legacy argument syntax for nice
This introduces an argument preprocessing step for the nice tool in
order to support the legacy nice adjustment syntax (`nice -1 foo`,
`nice --1 foo`, `nice -+1 foo` and so forth).

This is a preprocessing step because the interaction between these
arguments and the existing `nice -n -1` syntax becomes context
dependent, in a way that is currently difficult to capture through
clap.

Signed-off-by: Ed Smith <ed.smith@collabora.com>
2023-01-18 11:44:41 +01:00
Sylvestre Ledru
afbe850115
Merge pull request #4279 from rivy/up.uname
change/uname ~ update and revise
2023-01-18 11:33:29 +01:00
Roy Ivy III
b4e3e66236 test/uname ~ test for invisible characters in output (ie, NULs) 2023-01-14 22:16:41 -06:00
Roy Ivy III
cfdbaca6c1 test/uname ~ update tests for expected platform-v1.0.2 outputs 2023-01-14 22:16:41 -06:00
Roy Ivy III
d78e1e7399 tests: revise/standardize usage error testing (for dd, install, mktemp, rm, seq, and touch) 2023-01-13 22:14:48 -06:00
Sylvestre Ledru
6a9660f9f6
Merge pull request #4268 from rivy/fix.sleep
Fix `sleep` argument parsing and errors
2023-01-12 18:41:04 +01:00
Roy Ivy III
f8b545d6f8 test/sleep: add and refine sleep test cases 2023-01-08 12:10:32 -06:00
Sylvestre Ledru
b9e972094b test: add a test matching what busybox is doing 2023-01-07 09:50:50 +01:00
Joining7943
463c58afd0 tests/tail: Remove redundant set_stdin(Stdio::null()) 2023-01-03 16:30:12 +01:00
Joining7943
9b35c5d5c1 tests/util: Use Stdio::null as default in UCommand for Child stdin instead of Stdio::piped 2023-01-03 16:30:08 +01:00
Terts Diepraam
44ea43f058 tests: remove status_code, which is the same as code_is 2023-01-01 17:25:59 +01:00
Terts Diepraam
36f3507bed
Merge pull request #4232 from TechHara/whitespace
cut: add whitespace option for separating fields
2023-01-01 12:58:28 +01:00
Sylvestre Ledru
a3c76678fe
Merge pull request #4247 from tertsdiepraam/rm/add-fifo-test
rm: add test for #4246
2022-12-30 12:09:53 +01:00
Roy Ivy III
737271de96 test/expr: add regex tests 2022-12-29 23:22:13 -06:00
Roy Ivy III
812d811ff6 test/expr: add simple value and EXIT_CODE tests 2022-12-29 22:49:02 -06:00
Roy Ivy III
be37e033be test/expr: add more index testing of unicode strings 2022-12-29 22:49:02 -06:00
Roy Ivy III
8e7dbb0bf6 test/expr: add 'index' operator tests 2022-12-29 22:48:55 -06:00
Terts Diepraam
ea8085e2ca rm: add test for #4246 2022-12-29 16:15:41 +01:00
jaggededgedjustice
b8a755a396
date: Catch panic from invalid format string (#4240)
* Catch panic from invalid date string
2022-12-25 21:11:34 +01:00
Terts Diepraam
bdd6f56ae4
Merge pull request #4231 from Joining7943/add-timeout-in-tests
`tests/common/util`: Add possibility to set timeout for UCommand and UChild. Add `rstest` with timeout macro to dev dependencies
2022-12-23 01:12:57 +01:00
TechHara
c29839f4f9 Merge branch 'main' into whitespace 2022-12-18 09:07:03 -05:00
Joining7943
09c04d9f3f tests: Set timeout for tests which would fail with the default timeout in test_factor, test_sort 2022-12-17 21:55:01 +01:00
Sylvestre Ledru
8489e9b69c Ignore some cp tests on android
Closes: #4233
2022-12-17 16:54:23 +01:00
TechHara
bae78e62e0
Merge branch 'main' into whitespace 2022-12-15 22:23:03 -05:00
Terts Diepraam
e4bed1c087
Merge pull request #4135 from Joining7943/refactor-tail-check-warnings
`tail`: Refactor handling of warnings and early exits
2022-12-14 13:21:54 +01:00
TechHara
9798ae7987 fix clippy complaint 2022-12-13 20:34:01 -05:00
TechHara
11e64958d6 add test cases to cover cut -w failing options 2022-12-13 11:43:20 -05:00
Joining7943
b339f6d80c tests/tail: Add all additional tests written during refactoring tail from tip of refactoring branch
Other changes summmary:
* Use module level imports instead of fully qualified imports where appropriate
* Fix intermittent failing test_positive_zero_bytes because of broken pipe
* Cleanup old disabled test for warning of following indefinitely
2022-12-13 16:16:14 +01:00
Joining7943
d57545d09c tail: Refactor: Handle warnings and early exits in one place. Remove InputService ...
Other changes summary:
* Cleanup imports
* Remove stdin_is_pipe_of_fifo function
* Rename WatcherService to Observer
2022-12-13 16:16:08 +01:00
TechHara
6516519af3 Merge branch 'main' into whitespace 2022-12-12 22:07:05 -05:00
Sylvestre Ledru
f9c0ca4383
Merge pull request #4184 from jfinkels/cp-verbose
cp: correct --verbose --parents output for both files and directories
2022-12-12 21:31:15 +01:00
TechHara
f6a0abaee3 add whitespace delimiter option 2022-12-12 12:00:57 -05:00
Kai M
42b9b7b62c
install: fix issue #3814 (#3950)
* install: fix installing one file when using -Dt options

* install: fix installing multiple files with -Dt

Code was missing the logic to create the target dir when multiple files
should be copied and target dir is given by -t option.
This simplifies the copy logic also when only one file should be copied
to the target dir.

* install: fix verbose output when using -D

Also adds a unit test to verify the same behaviour as the gnu tools.

* install: add more testcases for create leading dir

Tests various combinations of "-D" with and w/o "-t" when installing
either a single file or multiple files into a non existing directory.

  install -D file1 file2 (-t) not_existing_dir
  install -D file1 (-t) not_existing_dir/

Also fixes file formatting, spelling and adds some more test asserts.

* install: fix error for nonex. dir path ending on /

The install command failed with a different error message than the
original GNU install tool. Checking for a trailing slash fixes this.
Only works on unix though.

* install: add windows support when checking for '/'

* install.rs: fix spelling

* install.rs: add more tests regarding omitting dir

This increases the CI test coverage and also checks for more corner
cases to ensure uu_install is compliant with GNU's original.

    export C=coreutils/target/debug/

    rm -rf dir1 no-dir2 dir3 file
    mkdir -p dir1 dir3
    touch file

    ${C}install dir1/file1 dir1/.. no-dir2
    ${C}install dir1/file1 dir1/.. dir3
    ${C}install dir1/.. dir3

* install: improve test_install_missing_arguments

Also check that install returns the correct error messages, when only a
target directory is given via -t and that is is not created (-D option).

* install: rework the checks for missing file args

This ensures correct (GNU install like) behavior. Tests from the last
commit will pass now.
2022-12-06 09:11:23 +01:00
Jeffrey Finkelstein
1a839fb2c4 cp: correct --verbose --parents output for dirs
This commit corrects the behavior of `cp -r --parents --verbose` when
the source path is a directory, so that it prints the copied ancestor
directories. For example,

    $ mkdir -p a/b/c d
    $ cp -r --verbose --parents a/b/c d
    a -> d/a
    a/b -> d/a/b
    'a/b/c' -> 'd/a/b/c'
2022-12-05 21:37:13 -05:00
Jeffrey Finkelstein
bd665ea44a cp: correct --verbose --parents output for files
This commit corrects the behavior of `cp --parents --verbose` when the
source path is a file so that it prints the copied ancestor
directories. For example,

    $ mkdir -p a/b d
    $ touch a/b/c
    $ cp --verbose --parents a/b/c d
    a -> d/a
    a/b -> d/a/b
    'a/b/c' -> 'd/a/b/c'

Fixes #3332.
2022-12-05 21:36:56 -05:00
Sylvestre Ledru
b7925465a8 factor: trim the input to fix some busybox results 2022-12-05 22:49:48 +01:00
Jeffrey Finkelstein
682667fd1d cp: force link between two files that exist
Allow `cp` to link files that exist. For example,

    $ touch src dest
    $ cp -f --link src dest

Before this commit, an error was raised.
2022-12-04 19:36:05 -05:00
Jeffrey Finkelstein
bf54fce055 tests: skip inode check on BSD 2022-12-03 23:50:39 -05:00
Jeffrey Finkelstein
3a5b31a30f dd: correct rendering of SI and IEC byte counts
Adjust the rendering of the concise byte counts in both SI and IEC
units to better match the behavior of GNU dd.

Before this commit,

    $ head -c 1024 /dev/zero | dd > /dev/null
    2+0 records in
    2+0 records out
    1024 bytes (1 KB, 1024 B) copied, 0.0 s, 1.0 MB/s

After this commit,

    $ head -c 1024 /dev/zero | dd > /dev/null
    2+0 records in
    2+0 records out
    1024 bytes (1.0 kB, 1.0 KiB) copied, 0.0 s, 1.0 MB/s

For comparison, GNU dd produces the following:

    $ head -c 1024 /dev/zero | dd > /dev/null
    2+0 records in
    2+0 records out
    1024 bytes (1.0 kB, 1.0 KiB) copied, 0.000332864 s, 3.1 MB/s
2022-12-03 10:14:00 -05:00
Sylvestre Ledru
75502aba93
Merge pull request #4136 from Joining7943/tail-test-runner
`tests/common/util`: Implement UChild, an abstraction for std::process::Child, to return UChild from run_no_wait instead
2022-12-03 10:18:25 +01:00
Sylvestre Ledru
818012e30b
Merge pull request #4193 from jfinkels/touch-relative-time
touch: add support for some relative times
2022-12-03 10:16:21 +01:00
Jeffrey Finkelstein
66ee373373 cp: preserve hard links when target already exists
Prevent a panic in `cp -a` when the target of a hard link already
exists in the target directory structure.

For example,

    $ mkdir -p src dest/src
    $ touch src/f dest/src/f
    $ ln src/f src/link
    $ cp -a src dest

The `cp` command now succeeds without error.
2022-12-02 23:50:18 -05:00
Joining7943
4a2ced5940 tests: Adjust some tests to use improved UChild. test_tac: Ignore pipe tests on windows.
Summary:
* Disable test_retry6 on android because of intermittent failures
* Use wait() instead of wait_with_output in test_cat, test_cp, test_sort
* tests/sort: Simplify usage of test_sigpipe_panic
* Fix tests in test_tee.

tests/tac:
There was a change in the `tests/common/util.rs` test api concerning piped input which may have
revealed a bug in the implementation of tac. Please see also
https://github.com/uutils/coreutils/pull/4136
2022-12-02 13:13:10 +01:00
Joining7943
4f54eedb74 tests/util: Improve UChild. Cleanup redundant functions in util.rs.
A short summary of changes:

* Add some basic tests for UChild and the run methods.
* Try more often in a fixed interval to create the tempfile for CapturedOutput.
* Fix drop order of struct fields for better cleanup of temporary files/dirs.
* Mark UChild::wait_with_output and UChild::pipe_in_and_wait_with_output deprecated
* Make CapturedOutput private
* Panic in stdout_all, stdout_all_bytes etc. if output is not captured.
* Rename some methods, refactor, clean up, fix documentation, add try_... methods
2022-12-02 08:06:48 +01:00
Joining7943
982fb682e9 tests: Use UChild in tests. Rename run_no_wait_child to run_no_wait and return UChild
tests/tail:
* test_stdin_redirect_file:. Test fails now when assert_alive()!
The follow test `tail -f < file` where file's content is `foo` fails with:
    Assertion failed. Expected 'tail' to be running but exited with status=exit status: 0

I also tried on the command line and can confirm that tail isn't runnning when following by
descriptor. The test is deactivated until the implementation is fixed.

* test_follow_stdin_descriptor
* test_follow_stdin_explicit_indefinitely.
* test_follow_single
* test_follow_non_utf8_bytes
* test_follow_multiple
* test_follow_name_multiple
* test_follow_invalid_pid
* test_single_big_args
* test_retry3
* test_retry4
* test_retry5
* test_retry7
* test_retry8
* test_retry9
* test_follow_descriptor_vs_rename1
* test_follow_descriptor_vs_rename2
* test_follow_name_retry_headers
* test_follow_name_remove
* test_follow_name_truncate1
* test_follow_name_truncate2
* test_follow_name_truncate3
* test_follow_name_truncate4
* test_follow_truncate_fast
* test_follow_name_move_create1
* test_follow_name_move_create2
* test_follow_name_move1
* test_follow_name_move2
* test_follow_name_move_retry1
* test_follow_name_move_retry2
* test_follow_inotify_only_regular
* test_fifo
* test_illegal_seek

tests/cat:
* test_dev_full
* test_dev_full_show_all
* test_dev_random
* test_fifo_symlink

tests/dd:
* test_random_73k_test_lazy_fullblock
* test_sync_delayed_reader

tests/factor:
* test_parallel

tests/rm:
* test_rm_force_prompts_order
* test_rm_descend_directory
* test_rm_prompts

tests/seq:
* the helper run method

tests/sort:
* test_sigpipe_panic

tests/tee:
* the helper run_tee method

tests/tty:
* test_tty module

tests/yes:
* the helper run method
2022-12-02 08:06:45 +01:00
Joining7943
040a5e8301 tests/util: Implement UChild. UCommand: implement stderr_to_stdout, capture output as default
See pr #4136 (https://github.com/uutils/coreutils/pull/4136)
2022-12-02 08:05:05 +01:00
Joining7943
9b446bf261 tests/tail: Fix clippy warning same-item-push. Do not push same flag twice. 2022-12-02 08:05:05 +01:00
Daniel Hofstetter
9a2174ba02 chore: standardize creation of empty strings 2022-12-01 13:49:23 +01:00
Jeffrey Finkelstein
9632db4f86 dd: correctly set file size when conv=sparse
Before this commit, if `sparsefile` were a regular file of non-zero
size whose contents are all null bytes, then

    dd if=sparsefile of=outfile conv=notrunc

would have resulted in `outfile` having zero size as reported by
`stat`. After this commit, `outfile` will have the same size as
`sparsefile` (even if the contents are represented sparsely by the
filesystem).
2022-11-29 22:53:18 +01:00
Jeffrey Finkelstein
a396ebd883 touch: add support for some relative times
For example,

    $ touch -d +1 days

Fixes #3964.
2022-11-29 22:53:13 +01:00
Sylvestre Ledru
27958a27ef
Merge pull request #4159 from sylvestre/issue_3780
date: add a test for the issue 3780 to make sure we don't regress
2022-11-27 18:24:07 +01:00
Miles Liu
3896aa31be
cp: fix cp --force --backup f f fails on macOS 2022-11-20 18:14:42 +08:00
Jeffrey Finkelstein
903ad1656d dd: move tests of slow reader to test_dd.rs
Move some tests that simulate a slow reader from `dd.rs` to
`tests/by-util/test_dd.rs`, and employ a FIFO and `sleep()` to
simulate the slow reader instead of a custom struct that implements
`Read`. This change restricts the type of `Input`s the
`Output::dd_out()` function can accept, facilitating a future change
to make `Input` an enum.
2022-11-19 09:27:23 -05:00
Terts Diepraam
1b35e467ac
Merge pull request #4137 from jfinkels/dd-bytes-suffix
dd: allow B as a suffix for count, seek, and skip
2022-11-19 12:23:43 +01:00
Sylvestre Ledru
0e3d3f780b
Merge pull request #4155 from miles170/issue-3779-fix-ci-freebsd
CI: fix FreeBSD CI passed when tests failed
2022-11-19 10:06:59 +01:00
Sylvestre Ledru
6d7850549b
Merge pull request #4150 from tertsdiepraam/stat-refactor
`stat` refactor
2022-11-19 09:57:23 +01:00
Jeffrey Finkelstein
701550d76b dd: allow B as a suffix for count, seek, and skip
Allow uppercase "B" on its own as a unit specifier for the `count`,
`seek`, and `skip` arguments to `dd`.

For example,

    $ printf "abcdef" | dd count=3B status=none
    abc
2022-11-18 20:27:42 -05:00
Sylvestre Ledru
4d16132948 date: add a test for the issue 3780 to make sure we don't regress 2022-11-18 21:32:59 +01:00
Miles Liu
d748e3900b
test_cp: ignore failing tests for FreeBSD 2022-11-19 00:05:37 +08:00
Sylvestre Ledru
435ef5da8b
Merge pull request #4132 from tertsdiepraam/sort-accept-sort-mode-multiple-times
`sort`: allow a sort mode to appear multiple times
2022-11-17 21:43:28 +01:00
Terts Diepraam
33cbc94f25 rm: use uucore::prompt_yes over custom prompt function 2022-11-17 15:12:18 +01:00
Terts Diepraam
91df2b1709 mv: use uucore::prompt_yes over custom function 2022-11-17 15:11:19 +01:00
Terts Diepraam
7bb0e8f849 ln: use uucore::prompt_yes over custom function 2022-11-17 15:10:26 +01:00
Terts Diepraam
ed34264b95 cp: use uucore prompt_yes instead of custom 2022-11-17 15:09:34 +01:00
Sylvestre Ledru
c00fc0a8c4
Merge pull request #4146 from niyaznigmatullin/clippy_fix
Run `cargo +nightly clippy --fix`
2022-11-17 10:33:40 +01:00
Terts Diepraam
b0224e8145 stat: move unit tests to stat.rs instead of test_stat.rs 2022-11-16 21:17:39 +01:00
Terts Diepraam
7e5b6400e3 stat: use Flags struct instead of u8 bit manipulation 2022-11-16 21:12:40 +01:00
Niyaz Nigmatullin
fdd6a05259 chore: run cargo +nightly clippy --fix 2022-11-16 11:09:44 +02:00
Emil Suleymanov
a6c48b084c test_cp: verify metadata for preserve no args case 2022-11-16 01:39:25 +01:00
Terts Diepraam
03c40b2db2 sort: allow a sort mode to appear multiple times
A test case for this is `sort -k 2n,2n` which should be accepted, because `n` is
compatible with itself.

Resolves issue #4129.
2022-11-15 14:22:01 +01:00
Niyaz Nigmatullin
f73f686ca3 test_cp: temporarily disable non-working test on Android 2022-11-15 10:00:59 +02:00
Jeffrey Finkelstein
416a742e31 cp: use sparse copy on --sparse=always
Correct the behavior of `cp --reflink=never --sparse=always` so that
it performs a sparse copy. Before this commit, it was incorrectly
performing a dense copy.
2022-11-10 21:43:19 -05:00
Emil Suleymanov
1172a7e781
cp: remove interactive mode message on 'no' (#4069) 2022-11-10 12:45:18 +01:00
Sylvestre Ledru
9a5d18b8f6 Weird env variable names should trigger an error.
For example `env a=b=c printenv a=b` should fail

Tested by tests/misc/printenv.sh
2022-11-06 17:35:00 +01:00
Sylvestre Ledru
8e5c259e4b
Merge pull request #3966 from jfinkels/cp-backup-force
cp: force copying file to itself with --backup
2022-11-06 08:43:52 +01:00
Sylvestre Ledru
3ea7a061d7
Merge pull request #4097 from devnexen/fbsd_test_fix
fix cp tests build since they re supposed to be ignored on freebsd an…
2022-11-06 07:41:16 +01:00
Sylvestre Ledru
446df9da5a
Merge branch 'main' into cp-backup-force 2022-11-06 07:24:48 +01:00
Sylvestre Ledru
47e3149e85
Merge pull request #3978 from jfinkels/cp-copy-contents-fifo
cp: implement --copy-contents option for fifos
2022-11-06 07:23:25 +01:00
Jeffrey Finkelstein
5b100fef62 cp: implement --copy-contents option for fifos
Implement the `--copy-contents` option when the source is a FIFO, so
that the contents of the FIFO are copied (when the bytes become
available for reading) instead of the FIFO object itself. For example,

    $ mkfifo fifo
    $ cp --copy-contents fifo outfile &
    [1] 1614080
    $ echo foo > fifo
    $ cat outfile
    foo
    [1]+  Done                    cp --copy-contents fifo outfile
2022-11-05 19:25:37 -04:00
Jeffrey Finkelstein
fbed01dd54 cp: force copying file to itself with --backup
Fix the behavior of `cp` when both `--backup` and `--force` are
specified and the source and destination are the same file.  Before
this commit, `cp` terminated without copying and without making a
backup. After this commit, the copy is made and the backup file is
made. For example,

    $ touch f
    $ cp --force --backup f f

results in a backup file `f~` being created.
2022-11-05 19:23:50 -04:00
Sylvestre Ledru
6bc68cdcdf
Merge branch 'main' into refactor/add_nix_error_auto_conversion 2022-11-04 12:54:35 +01:00
Orhun Parmaksız
be49eb68f3
fix: address test failures 2022-11-04 13:35:54 +03:00
Daniel Hofstetter
8114abc956 Fix "needless borrow" clippy warning in env test 2022-11-04 11:10:35 +01:00
Sylvestre Ledru
2d79c4f693
Merge pull request #4091 from dmatos2012/allow-default-value-mktemp
mktemp: allow default missing value
2022-11-03 20:46:11 +01:00
Sylvestre Ledru
f60e861232
Merge pull request #4074 from jfinkels/cp-force-dangling-symlink
cp: restrict copy through dangling symlink with -f
2022-11-03 08:27:41 +01:00
David Matos
53c4b0b81e mktemp: allow default missing value 2022-11-03 08:27:08 +01:00
David CARLIER
40b1ce7151 disable cp tests on FreeBSD where they are supposed to be ignored. 2022-11-03 08:25:40 +01:00
Daniel Hofstetter
2d4810b91b numfmt: allow ' ' as field separator 2022-11-01 10:04:46 +01:00
Daniel Hofstetter
27c233f294 numfmt: allow "-" in field list 2022-10-31 14:53:41 +01:00
Sylvestre Ledru
b942054568
Merge pull request #4093 from cakebaker/numfmt_test_all_fields
numfmt: add test for "--field -" (all fields)
2022-10-31 11:01:32 +01:00
Terts Diepraam
ba3bb56041
Merge pull request #4013 from palaster/rm-correct-prompts
rm: rm3 now passes
2022-10-31 10:17:27 +01:00
Daniel Hofstetter
5d27c19853 numfmt: add test for "--field -" (all fields) 2022-10-31 09:26:28 +01:00
Sylvestre Ledru
bc126085c4
Merge branch 'main' into cp-force-dangling-symlink 2022-10-29 20:01:07 +02:00
Daniel Hofstetter
3a8feedf2d numfmt: allow hyphen values for --field option 2022-10-29 16:50:41 +02:00
Sylvestre Ledru
b3af47a390
Merge branch 'main' into cp-force-dangling-symlink 2022-10-28 21:24:42 +02:00
Pat Laster
c4417bf9b2
Merge branch 'main' into rm-correct-prompts 2022-10-27 13:38:41 -05:00
Sylvestre Ledru
00d93ff451
Merge pull request #4088 from tertsdiepraam/hashsum-test-no-names
hashsum: enable testing --no-names
2022-10-27 19:55:45 +02:00
Daniel Hofstetter
2eb0b6dfe0 numfmt: round values if precision is 0 2022-10-27 15:33:20 +02:00
Sylvestre Ledru
34eabca299 pwd: support the env variable 'POSIXLY_CORRECT'
Should fix tests/misc/pwd-option.sh
2022-10-26 11:40:46 +02:00
Terts Diepraam
96b6252910
Merge pull request #4081 from sylvestre/chown-sep
chown: fails when XXXX. or XXXX: is provided (when XXXX is numeric value)
2022-10-26 11:24:35 +02:00
Terts Diepraam
bbc3495896 hashsum: enable testing --no-names
Co-authored-by: Huijeong Kim <herehuijeong@gmail.com>
2022-10-26 11:10:26 +02:00
Pat Laster
0079f73568
Merge branch 'main' into rm-correct-prompts 2022-10-25 20:58:01 -05:00
Sylvestre Ledru
52d82d54a3 Revert "hashsum: test b3sum::test_nonames for real (#4027)"
This reverts commit 02f6fa7b24.
2022-10-25 23:44:05 +02:00
Sylvestre Ledru
76a0794823
Merge pull request #4072 from jfinkels/clippy-fixes
clippy fixes
2022-10-25 23:28:20 +02:00
Sylvestre Ledru
42fad7c4e5
Merge pull request #4078 from sylvestre/update-i
{cp, mv} -i --update source existing should not do anything and exit 0
2022-10-25 08:31:39 +02:00
Sylvestre Ledru
9f1ac221cd chown: fails when XXXX. or XXXX: is provided (when XXXX is numeric values)
If the arg starts with an id numeric value, the group isn't set but the separator is provided,
we should fail with an error

Should fix tests/chown/separator.sh
2022-10-25 08:25:05 +02:00
Pat Laster
9069d4832a
Merge branch 'main' into rm-correct-prompts 2022-10-24 18:36:52 -05:00
Sylvestre Ledru
6e8f8034ba {cp, mv} -i --update source existing should not do anything and exit 0
Should fix tests/mv/update.sh
2022-10-24 21:03:30 +02:00
Daniel Hofstetter
dedb6289dd numfmt: handle negative zero values 2022-10-24 15:13:02 +02:00
Jeffrey Finkelstein
d48a650966 cp: restrict copy through dangling symlink with -f
Change `cp` to terminate with an error when attempting to copy through
a dangling symbolic link with the `--force` option. Before this
commit,

    touch src
    ln -s no-such-file dest
    cp -f src dest

would incorrectly replace `dest` with the contents of `src`. After
this commit, it correctly fails with the error message

    cp: not writing through dangling symlink 'dest'
2022-10-23 20:17:20 -04:00
Jeffrey Finkelstein
55b3766c10 clippy fixes 2022-10-23 13:56:20 -04:00
Sylvestre Ledru
c766726e8b
Merge pull request #3281 from jfinkels/split-round-robin
split: implement round-robin arg to --number
2022-10-23 09:57:01 +02:00
Jeffrey Finkelstein
ac3fcca6c0 cp: correctly copy ancestor dirs in --parents mode
Fix a bug where `cp` failed to copy ancestor directories when using
the `--parents` option. For example, before this commit:

    $ mkdir -p a/b/c d
    $ cp --parents a/b/c d
    $ find d
    d
    d/c

After this commit

    $ mkdir -p a/b/c d
    $ cp --parents a/b/c d
    $ find d
    d
    d/a
    d/a/b
    d/a/b/c

This commit also adds the correct messages for `--verbose` mode:

    $ cp -r --parents --verbose a/b/c d
    a -> d/a
    a/b -> d/a/b
    'a/b/c' -> 'd/a/b/c'

Fixes #3332.
2022-10-23 00:06:56 -04:00
Jeffrey Finkelstein
cee6c25cc4 cp: make test for interactive mode more specific 2022-10-23 00:03:26 -04:00
Jeffrey Finkelstein
7dc96697c9 split: implement round-robin arg to --number
Implement distributing lines of a file in a round-robin manner to a
specified number of chunks. For example,

    $ (seq 1 10 | split -n r/3) && head -v xa[abc]
    ==> xaa <==
    1
    4
    7
    10

    ==> xab <==
    2
    5
    8

    ==> xac <==
    3
    6
    9
2022-10-22 23:15:55 -04:00
Pat Laster
99942b4234
Merge branch 'main' into rm-correct-prompts 2022-10-22 14:12:55 -05:00
Huijeong Kim
02f6fa7b24
hashsum: test b3sum::test_nonames for real (#4027)
* hashsum: test b3sum::test_nonames for real

Signed-off-by: Huijeong Kim <herehuijeong@gmail.com>

* apply cargo format

Signed-off-by: Huijeong Kim <herehuijeong@gmail.com>
2022-10-22 11:23:39 +02:00
Sylvestre Ledru
1d9ec1ed94
Merge pull request #3927 from niyaznigmatullin/fix_timeout_test_tmp_files_deleted_on_sigint
test_sort: Fix timeout issue `test_tmp_files_deleted_on_sigint`
2022-10-22 10:24:30 +02:00
Sylvestre Ledru
fd13ceddcb
Merge branch 'main' into rm-correct-prompts 2022-10-22 10:22:29 +02:00
Sylvestre Ledru
e4fe2b10fa
Merge pull request #4014 from tertsdiepraam/ls-windows-permissions
`ls`, `stat`: Show more info in long format on Windows
2022-10-22 10:21:43 +02:00
Sylvestre Ledru
49c435a25b
ignore a word 2022-10-20 07:46:38 +02:00
David Matos
d46e5df3d3 hashsum: warn on file not found rather than fail 2022-10-19 22:46:47 +02:00
Pat Laster
79895a73e6
Merge branch 'main' into rm-correct-prompts 2022-10-18 10:48:26 -05:00
Niyaz Nigmatullin
729d97e993 test_sort: use Pcg32 random number generator 2022-10-18 13:18:50 +03:00
Niyaz Nigmatullin
ec8e610e48 test_sort: created a new big file for sort
Before, the sort could work faster and we could be late with
the signal.
Now we create a new big file, `sort` can't process it in a minute,
so we can safely wait for the temporary directory to be created
and send a signal afterwards
2022-10-18 13:18:50 +03:00
Niyaz Nigmatullin
95e7b53402 test_sort: make timeout smarter, wait if failed to create dir
Before the change it slept for 0.1 seconds and right after that
asserted if `sort` has created the directory. Sometimes `sort`
didn't manage to create the directory in 0.1 seconds.
So the change is it tries to wait for `timeout` starting with
0.1 seconds, and if directory was not found, it tries 4 more times,
each time increasing timeout twice. Once the directory is found
it breaks.
2022-10-18 13:18:50 +03:00
Niyaz Nigmatullin
cefc4f6736 tests: fixed some tests on Windows
Tests used to use system `touch` and `ls` instead of
testing bench `fixtures.touch` and `uu_ls`
2022-10-18 10:00:28 +03:00
Pat Laster
87df47dee3
Merge branch 'main' into rm-correct-prompts 2022-10-17 17:41:44 -05:00
Sylvestre Ledru
969f821830
Merge pull request #4009 from andrewbaptist/fix_eof_linebytes
Match GNU semantics for missing EOF
2022-10-17 16:23:20 +02:00
Niyaz Nigmatullin
277e3d17a1 tests: change error messages for wrong arguments
Clap used `"` for argument values, now uses `'`.
2022-10-16 19:28:04 +03:00
Pat Laster
7e62945fd3
Merge branch 'main' into rm-correct-prompts 2022-10-15 14:58:13 -05:00
Pat Laster
0507270f90 Clippy is going to be the death of me 2022-10-13 20:03:35 -05:00
Pat Laster
70bf4f36a0 Added test to check rm force prompts order 2022-10-13 20:03:35 -05:00
Pat Laster
6245029445 rm: rm3 now passes 2022-10-13 20:03:35 -05:00
Terts Diepraam
14e3c5176c realpath: require arguments again 2022-10-13 20:06:27 +02:00
Terts Diepraam
b0c200e831 env: handle - correctly again 2022-10-13 20:06:02 +02:00
Terts Diepraam
53567deb0f who: update to clap 4 2022-10-13 17:50:43 +02:00
Terts Diepraam
12048cda68 unlink: update to clap 4 2022-10-13 17:50:43 +02:00
Terts Diepraam
9cce0bed7f truncate: update to clap 4 2022-10-13 17:50:43 +02:00
Terts Diepraam
72d7287b11 test: update to clap 4 2022-10-13 17:50:43 +02:00
Terts Diepraam
b6a4f32889 stdbuf: update to clap 4 2022-10-13 17:50:40 +02:00
Terts Diepraam
4cfc90c077 seq: update to clap 4 2022-10-13 17:50:40 +02:00
Terts Diepraam
5faae817ba mv: update to clap 4 2022-10-13 17:50:36 +02:00
Terts Diepraam
1d6c5d14b2 mknod: update to clap 4 2022-10-13 17:50:36 +02:00
Terts Diepraam
c6cff20f18 ls: update to clap 4 2022-10-13 17:50:36 +02:00
Terts Diepraam
838479f86a link: update to clap 4 2022-10-13 17:50:33 +02:00
Terts Diepraam
458c2c8b85 factor: update to clap 4 2022-10-13 17:50:29 +02:00
Terts Diepraam
b7c1216a1a env: update to clap 4 2022-10-13 17:50:29 +02:00
Terts Diepraam
042bb3c4e3 cp: update to clap 4 2022-10-13 17:50:26 +02:00
Terts Diepraam
075245235e chgrp: update to clap 4 2022-10-13 17:50:23 +02:00
Terts Diepraam
649dab36f1 basename: update to clap 4 2022-10-13 16:22:45 +02:00
Terts Diepraam
26309dc9d7 base{32, 64, enc}: update to clap 4 2022-10-13 16:22:24 +02:00
Sylvestre Ledru
6e14dea73b Fix some clippy warnings
Fixed with `cargo clippy --features unix  --fix`
and manually
2022-10-13 09:07:22 +02:00
Sylvestre Ledru
b7c298afee
Merge pull request #4020 from ackerleytng/main
dircolors: align TERM matching behavior with that of GNU dircolors
2022-10-12 09:27:34 +02:00
Chad Brewbaker
cbb9db7be7 fix MIRI crash of long test 2022-10-11 12:11:52 -05:00
Sylvestre Ledru
d768b19f2b chroot: improve support of --skip-chdir
Should unbreak tests/misc/chroot-fail.sh
2022-10-10 14:07:45 +02:00
Sylvestre Ledru
ad0ca2f042
Merge pull request #3973 from jfinkels/cp-directory-preserve-permissions
cp: preserve permissions when copying directory and don't terminate early on inaccessible file
2022-10-10 08:16:27 +02:00
Ackerley Tng
1239fc477b dircolors: align TERM matching behavior with that of GNU dircolors 2022-10-09 18:47:20 -07:00
Jeffrey Finkelstein
b89e8e54c4 cp: continue directory walk if file inaccessible
Stop `cp` from terminating prematurely if a file in a directory is
inaccesible due to insufficient permissions.
2022-10-09 17:31:41 -04:00
Jeffrey Finkelstein
2450493302 cp: preserve permissions when copying directory
Make cp preserve the permissions of a directory when copying
it. Before this commit,

    cp -pR src/ dest/

failed to copy the permissions of `src/` to `dest/`. After this
commit, the permissions are correctly copied.
2022-10-09 17:29:29 -04:00
Jeffrey Finkelstein
fba8d495d2 tests: create assert_metadata_eq!() macro
Create `assert_metadata_eq!()` macro to contain a series of assertions
that check whether two `Metadata` objects are equal.
2022-10-09 17:28:43 -04:00
jfinkels
349320ae61
Merge branch 'main' into cp-symbolic-link-loop 2022-10-09 17:28:30 -04:00
Sylvestre Ledru
538e8eca0b
Fix coding style 2022-10-09 20:03:06 +02:00
Terts Diepraam
b3e6472d02 test_ls: adapt to new windows permissions 2022-10-09 12:03:44 +02:00
Terts Diepraam
7d8917bb35
Merge pull request #4003 from sylvestre/sync2
sync: various compatibility improvement
2022-10-09 11:07:44 +02:00
Ackerley Tng
d84803b72f ls: align --ignore behavior with that of GNU ls 2022-10-08 16:54:07 -07:00
Andrew Baptist
4922d34177 Match GNU semantics for missing EOF
While the rust coreutils semantics were arguably more correct,
they were different than the gnu split semantics when handling a
file without a trailing EOF. This patch addresses that difference
and allows passing one more GNU test suite.
2022-10-07 17:50:26 -04:00
Sylvestre Ledru
97dd4824e5
Merge pull request #3976 from andrewbaptist/implement_suffix_start
Add support for starting suffix numbers
2022-10-07 21:07:07 +02:00
Sylvestre Ledru
97f3dfad54
Merge pull request #3965 from Joining7943/fix-windows-pipe
`tests/tail`: Fix tests to reflect changes from the refactoring #3905
2022-10-06 11:17:25 +02:00
Sylvestre Ledru
88fb43c8e4
Merge branch 'main' into cp-symbolic-link-loop 2022-10-06 09:53:02 +02:00
Jeffrey Finkelstein
8bfd96fb59 cp: correct error message on copying dir to itself
Correct the error message produced when attempting to copy a directory
into itself with `cp`. Before this commit, the error message was

    $ cp -R d d
    cp: cannot copy a directory, 'd', into itself, 'd'

After this commit, the error message is

    $ cp -R d d
    cp: cannot copy a directory, 'd', into itself, 'd/d'
2022-10-05 21:37:30 -04:00
Sylvestre Ledru
ae7c45d27a
Merge pull request #3988 from dmatos2012/add-date-format-ls
ls: add support for +FORMAT in timestyle
2022-10-05 18:41:15 +02:00
Andrew Baptist
49e1cc6c71 Add support for starting suffix numbers
This commit now allows split to pass split/numeric.sh
2022-10-05 09:52:20 -04:00
Pat Laster
493a2628d2
rm: Added descend messages for interactive mode Fixes #3817 (#3931)
Co-authored-by: Terts Diepraam <terts.diepraam@gmail.com>
2022-10-05 13:35:31 +02:00
Joining7943
1725151ef8 tests/tail: Fix tests to reflect changes from the refactoring #3905 2022-10-05 13:32:35 +02:00
Jeffrey Finkelstein
24630db45e cp: allow removing symbolic link loop destination
Allow `cp --remove-destination` to remove a symbolic link loop (or a
symbolic link that initiates a chain of too many symbolic
links). Before this commit, if `loop` were a symbolic link to itself,
then

    cp --remove-destination file loop

would fail with an error message. After this commit, it succeeds. This
matches the behaviotr of GNU cp.
2022-10-05 13:32:21 +02:00
Sylvestre Ledru
6edf8ebf41 sync: Verify that the files can be opened 2022-10-05 13:30:19 +02:00
Sylvestre Ledru
fc1c7755b9 sync: make fail like GNU - tests/misc/sync.sh 2022-10-05 13:30:19 +02:00
David Matos
b8a5588b81 ls: add support for +FORMAT in timestyle 2022-10-05 13:29:19 +02:00
Sylvestre Ledru
858b2a5b99 disable the new tests 2022-10-04 17:24:06 +02:00
Sylvestre Ledru
3cda177d34 Disable test_preference_of_userspec on android 2022-10-04 17:17:01 +02:00
Terts Diepraam
25db814671
Merge pull request #4002 from sylvestre/cmd-test
test: add a bunch of operations
2022-10-04 12:00:00 +02:00
Sylvestre Ledru
33de6c89db test: allow parsing of bigger numbers
Fixes: tests/misc/test.pl
2022-10-03 20:25:45 +02:00
Sylvestre Ledru
f0b8b33dc1 test: add support for -ef, -nt & -ot 2022-10-03 20:25:42 +02:00
Emil Suleymanov
a7b637b1eb
cp: assume --reflink=always on no value (#3992)
* Set reflink to auto by default
2022-10-03 20:20:55 +02:00
Sylvestre Ledru
63203a0a68 test: add -N FILE exists and has been modified since it was last read
Upstream: tests/misc/test-N.sh
2022-10-03 00:59:39 -10:00
Terts Diepraam
4b517a361d
Merge pull request #3959 from Joining7943/tail-reactivate-presume-input-pipe
tail: Reactivate ---presume-input-pipe option
2022-09-28 00:09:18 +02:00
Terts Diepraam
a3ba02a791
Merge pull request #3971 from niyaznigmatullin/cp_H_option
cp: add `-H` option
2022-09-25 15:16:37 +02:00
Terts Diepraam
9ce600ffa8
Merge pull request #3904 from cakebaker/pr_use_clap_for_help_and_version
pr: use clap to handle help & version
2022-09-25 14:10:00 +02:00
Niyaz Nigmatullin
84a741fe91 cp: add -H option, add tests, fix test 2022-09-23 20:31:24 +03:00
jfinkels
dd0daa5e06
df: remove trailing spaces in rightmost column (#3882)
Co-authored-by: Daniel Hofstetter <daniel.hofstetter@42dh.com>
2022-09-22 08:37:20 +02:00
Jeffrey Finkelstein
60ca9a03bb mktemp: add message for directory not found
Add special handling in `mktemp` for when the directory that will
contain the temporary file is not found. This situation now produces
the message

    mktemp: failed to create file via template 'XXX': No such file or directory

to match the behavior of GNU mktemp.
2022-09-21 21:26:39 -04:00
Sylvestre Ledru
68ad9e4301
Merge pull request #3951 from jfinkels/mktemp-too-many-templates
mktemp: match GNU error message on too many args
2022-09-21 22:39:55 +02:00
Sylvestre Ledru
5a746a778f
Merge pull request #3938 from tertsdiepraam/dd-positional-args
`dd`: parse operands manually via positional args
2022-09-21 22:39:13 +02:00
Sylvestre Ledru
69b52b4a1b chroot: add a new test to verify that 'chroot / ls -al' works 2022-09-21 19:47:01 +02:00
Sylvestre Ledru
2e26e1d2bd chroot: implement --skip-chdir 2022-09-21 19:46:58 +02:00
Terts Diepraam
e377e4f046 dd: custom positional argument parsing 2022-09-21 18:41:12 +02:00
Joining7943
c32d61dcfb tests/tail: Add system tests for ---presume-input-pipe 2022-09-21 16:39:52 +02:00
Sylvestre Ledru
3654efe8e7 chroot: add more tests 2022-09-21 14:53:50 +02:00
Jeffrey Finkelstein
7b35749ea6 mktemp: match GNU error message on too many args
Update the usage message when too many template arguments are given on
the command line to match that of GNU mktemp:

    mktemp: too many templates
    Try 'mktemp --help' for more information.

This fixes the test case `too-many` in the GNU test suite file
`tests/misc/mktemp.pl`.
2022-09-21 10:02:56 +02:00
Sylvestre Ledru
a857002def
Merge pull request #3949 from niyaznigmatullin/cp-i_gnu_test
cp: fix `cp-i` GNU test
2022-09-18 22:06:12 +02:00
Terts Diepraam
8c839888e1
Merge pull request #3905 from Joining7943/refactor-tail
Refactor tail
2022-09-17 20:39:53 +02:00
Niyaz Nigmatullin
2ce999c959 cp: fix cp-i GNU test
`cp` in interactive mode used to write to stdout asking for
overwrite. GNU version writes to stderr.

Changed: write to stderr to make compatible with GNU.
2022-09-17 19:15:52 +03:00
Jeffrey Finkelstein
61345cbdc9 mktemp: respect TMPDIR environment variable
Change `mktemp` so that it respects the value of the `TMPDIR`
environment variable if no directory is otherwise specified in its
arguments. For example, before this commit

    $ TMPDIR=. mktemp
    /tmp/tmp.WDJ66MaS1T

After this commit,

    $ TMPDIR=. mktemp
    ./tmp.h96VZBhv8P

This matches the behavior of GNU `mktemp`.
2022-09-13 19:38:25 -04:00
Joining7943
951c51e740 tail: large refactoring and cleanup of the tail code base. See also #3905 for details 2022-09-13 22:54:36 +02:00
Sylvestre Ledru
78a9f6edf8
Merge pull request #3908 from tertsdiepraam/chroot-err-codes
`chroot`: set exit codes to 125, 126 or 127 for errors from chroot itself
2022-09-12 22:43:12 +02:00
Niyaz Nigmatullin
8bd9427d0d tests/ls: added exit code to some test failures 2022-09-12 19:47:16 +03:00
Daniel Hofstetter
ebbf8ade1e pr: use clap to handle help & version 2022-09-12 15:28:08 +02:00
Terts Diepraam
51bd8a2ba8 chroot: set exit codes to 125, 126 or 127 for errors from chroot itself 2022-09-11 12:02:54 +02:00
Terts Diepraam
9177cb7b24 all: add tests for usage error exit code 2022-09-10 20:59:42 +02:00
Niyaz Nigmatullin
999db68042 pr: migrate from chrono crate to time
It seems that `chrono` is the reason of deadlock or UB in android
CI. Also `chrono` had some security issues and wasn't maintained for
two years until March 2022, so other unstabilities can happen. Plus
`chrono` uses old `time` dependency.
2022-09-09 21:59:08 +03:00
Niyaz Nigmatullin
0d6383dd19 test_cp: comment out bad syscall failing piece of code for Android 2022-09-09 16:12:05 +03:00
Joining7943
2658f8ae5b tail: improve performance of piped stdin
Rewrite handling of stdin when it is piped and read input in chunks.

Fixes https://github.com/uutils/coreutils/issues/3842
2022-09-09 13:51:37 +02:00
Sylvestre Ledru
a8d1d73465 fix a test on cp counting the number of fd:
The testsuite runs in parallel, we have pipe, sockets
opened by other tests.
So, we take in account the various fd to increase the limit
2022-09-07 21:26:03 +02:00
Jan Scheer
88d3aee71c tail: fix offset for stdin redirect if multiple input files 2022-09-05 10:09:04 +02:00
Jan Scheer
74f359bd76 tail: use same-file crate to get a handle of stdin redirected file 2022-09-05 10:09:04 +02:00
Jan Scheer
942928b0ea tail: fix stdin redirect when file is not at its beginning
Previously, if stdin redirect pointed to a regular file,
tailing started at the beginning of the file. However,
tailing needs to start at the current position because this
is expected by tests/tail-2/start-middle.sh.

This fixes the issue by taking the current offset into account
while going backwards through the stdin redirected file.
2022-09-05 10:09:04 +02:00
Jan Scheer
92c3f60440 tail: fix stdin redirect (#3842)
This fixes a bug where calling `tail - < file.txt` would result
in invoking `unbounded_tail()`.
However, it is a stdin redirect to a seekable regular file and
therefore `bounded_tail` should be invoked as if `tail file.txt` had
been called.
2022-09-05 10:09:04 +02:00
Sylvestre Ledru
282774a3ef
Merge pull request #3853 from stefins/rm-write-protected
rm: added write-protected check for files
2022-08-29 17:03:24 +02:00
Owen Anderson
08d3da8f6c
Fix a TODO by making conv_block_unblock_helper consume the input. (#3787)
* Fix a TODO by making `conv_block_unblock_helper` consume the input.
2022-08-28 10:07:04 +02:00
Stefin
4c1c9ebf89 rm: change InteractiveMode::Default to InteractiveMode::PromptProtected
Signed-off-by: Stefin <stefin@pm.me>
2022-08-27 19:38:10 +05:30
Tavo Annus
09cfa44560 Fix tail panicing when seeking backwards
Previously `tail -c n file.txt` caused panic if n > sizeof file.txt.
Now it prints out whole file similarly to GNU tail.
2022-08-24 21:02:47 +03:00
Jeffrey Finkelstein
8458bf1387 Clippy fixes in multiple crates 2022-08-23 18:30:43 -04:00
Stefin
ad4eac867f rm: added test for rm_prompt_write_protected
Signed-off-by: Stefin <stefin@pm.me>
2022-08-23 21:17:48 +05:30
Niyaz Nigmatullin
306272bf60 unix_sockets is deprecated, use std::os::unix::net instead 2022-08-20 17:02:29 +03:00
Terts Diepraam
f861fc0854 stty: print special terminal information 2022-08-18 11:33:04 +02:00
Terts Diepraam
6896a85b41 test_stty: fix spell checker errors 2022-08-18 11:33:04 +02:00
Terts Diepraam
a23702caeb add some simple tests to stty (still failing) 2022-08-18 11:33:04 +02:00
Niyaz Nigmatullin
52d767ed5a test_pr: follow clippy advice 2022-08-17 13:13:27 +03:00
Przemysław Fuchs
3acbd1c048
dd: Error message of invalid args is matched with GNU (#3831) 2022-08-17 11:40:42 +02:00
Owen Anderson
9fad6fde35
Fix a bug in split where chunking would be skipped when the chunk size (#3800)
* Fix a bug in split where chunking would be skipped when the chunk size
happened to be an exact divisor of the buffer size used to read the
input stream.

The issue here was that file was being split byte-wise in chunks of 1G.
The input stream was being read in chunks of 8KB, which evenly divides
the chunk size. Because the check to allocate the next output chunk was
done at the bottom of the loop previously, it would never occur because
the current input chunk was fully consumed at that point. By moving the
check to the top of the loop (but still late enough that we know we have
bytes to write) we resolve this issue.

This scenario is unfortunately hard to write a test for, since we don't
explicitly control the input chunk size.

Fixes https://github.com/uutils/coreutils/issues/3790
2022-08-16 11:02:52 +02:00
Niyaz Nigmatullin
5d4ad4de13 tests/readlink: add test for delimiters usage 2022-08-16 08:21:43 +03:00
Niyaz Nigmatullin
6879ed7b34 tests/readlink: refactor added tests 2022-08-15 23:33:41 +03:00
Niyaz Nigmatullin
38add34d31 tests/readlink: fix for Windows 2022-08-15 23:31:45 +03:00
Niyaz Nigmatullin
a5e0a14415 tests/readlink: fix Windows "Not a directory" error message 2022-08-15 23:04:51 +03:00
Niyaz Nigmatullin
b74e2f9d9b tests/readlink: follow clippy advice 2022-08-15 22:48:35 +03:00
Niyaz Nigmatullin
e826ab5f0f tests/readlink: follow clippy advice 2022-08-15 22:47:03 +03:00
Niyaz Nigmatullin
df403334c0 tests/readlink: add spell-checker ignore 2022-08-15 22:47:03 +03:00
Niyaz Nigmatullin
94860f8af6 tests/realpath: add trailing slash usage tests 2022-08-15 22:47:03 +03:00
Niyaz Nigmatullin
1c6f71e0e1 tests/readlink: add tests for trailing slashes and canonicalize -e and
-f usages
2022-08-15 22:47:03 +03:00
Przemysław Fuchs
e2bab1d515
mv: fix error when moving directory to itself (#3809) 2022-08-15 10:10:04 +02:00
Sylvestre Ledru
00f5d91886 sha1sum: fix the -c usage (Closes: #3815) 2022-08-14 23:32:46 +02:00
Jan Scheer
391709c911
tests: ignore failing tests for FreeBSD (#3778) 2022-08-13 10:09:05 +02:00
Daniel Hofstetter
dd19f85d2b Fix clippy warnings in tests 2022-08-12 09:45:16 +02:00
Sylvestre Ledru
8692301ec7
Merge pull request #3754 from ackerleytng/main
Add `parse_glob` module and update `du` to use `parse_glob`
2022-08-10 19:28:40 +02:00
Niyaz Nigmatullin
ca6b4ca7de test/touch: fix tests for Windows and MacOS 2022-08-10 11:07:22 +03:00
Niyaz Nigmatullin
7e1c6d1baf tests/touch: add tests for trailing slashes + -c 2022-08-10 11:07:22 +03:00
Ackerley Tng
c2bb9596d9 du: update du to use parse_glob::from_str 2022-08-09 10:36:23 +02:00
Sylvestre Ledru
ab791b6c0b
Merge pull request #3796 from niyaznigmatullin/fix_broken_pipe_test_positive_zero_lines
test/tail: ignore broken pipe for tail -n 0
2022-08-09 00:24:32 +02:00
Niyaz Nigmatullin
161fc6b642 test/dd: add ignore_stdin_write_error, because count=0 and dd doesn't
read anything
2022-08-08 22:44:59 +03:00
Niyaz Nigmatullin
04df57ebd4 test/tail: ignore pipe errors when tail -n 0, since it doesn't read
anything
2022-08-08 22:29:53 +03:00
Niyaz Nigmatullin
fee851dc1c
test/cp: fix test_copy_through_dangling_symlink_no_dereference_permissions (#3789)
* test/cp: -p changes ctime and added sleep for better timestamp testing

* test/cp: add nanoseconds checking for copied timestamps

* test/cp: made compilable on other OSes

* test/cp: added error messages to assert_eq calls
2022-08-08 11:11:17 +02:00
Jan Scheer
0555745052
tests: fix Freebsd test failures 2022-08-05 08:04:25 +02:00
Pierre Marsais
e1991525af
cp: Implement --sparse flag (#3766)
* cp: Refactor `reflink`/`sparse` handling to enable `--sparse` flag

`--sparse` and `--reflink` options have a lot of similarities:
 - They have similar options (`always`, `never`, `auto`)
 - Both need OS specific handling
 - They can be mutually exclusive

Prior to this change, `sparse` was defined as `CopyMode`, but `reflink`
wasn't. Given the similarities, it makes sense to handle them similarly.

The idea behind this change is to move all OS specific file copy
handling in the `copy_on_write_*` functions. Those function then
dispatch to the correct logic depending on the arguments (at the moment,
the tuple `(reflink, sparse)`).

Also, move the handling of `--reflink=never` from `copy_file` to the
`copy_on_write_*` functions, at the cost of a bit of code duplication,
to allow `copy_on_write_*` to handle all cases (and later handle
`--reflink=never` with `--sparse`).

* cp: Implement `--sparse` flag

This begins to address #3362

At the moment, only the `--sparse=always` logic matches the requirement
form GNU cp info page, i.e. always make holes in destination when
possible.

Sparse copy is done by copying the source to the destination block by
block (blocks being of the destination's fs block size). If the block
only holds NUL bytes, we don't write to the destination.

About `--sparse=auto`: according to GNU cp info page, the destination
file will be made sparse if the source file is sparse as well. The next
step are likely to use `lseek` with `SEEK_HOLE` detect if the source
file has holes. Currently, this has the same behaviour as
`--sparse=never`. This `SEEK_HOLE` logic can also be applied to
`--sparse=always` to improve performance when copying sparse files.

About `--sparse=never`: from my understanding, it is not guaranteed that
Rust's `fs::copy` will always produce a file with no holes, as
["platform-specific behavior may change in the
future"](https://doc.rust-lang.org/std/fs/fn.copy.html#platform-specific-behavior)

About other platforms:
 - `macos`: The solution may be to use `fcntl` command `F_PUNCHHOLE`.
 - `windows`: I only see `FSCTL_SET_SPARSE`.

This should pass the following GNU tests:
 - `tests/cp/sparse.sh`
 - `tests/cp/sparse-2.sh`
 - `tests/cp/sparse-extents.sh`
 - `tests/cp/sparse-extents-2.sh`

`sparse-perf.sh` needs `--sparse=auto`, and in particular a way to skip
holes in the source file.

Co-authored-by: Sylvestre Ledru <sylvestre@debian.org>
2022-08-04 13:22:59 +02:00
Pierre Marsais
90a9829287
cp: truncate destination when --reflink is set (#3759)
* cp: truncate destination when `--reflink` is set

This is needed in order to allow overriding an existing file.

```
$ truncate -s 512M /tmp/disk.img
$ mkfs.btrfs /tmp/disk.img
[...]
$ mkdir /tmp/disk
$ sudo mount /tmp/disk.img /tmp/disk
$ sudo chown $(id -u):$(id -g) -R /tmp/disk
$ for i in $(seq 0 8192); do echo -ne 'a' >>/tmp/disk/src1; done
$ echo "success" >/tmp/disk/src2
$
$ # GNU ls supports overriding files created with `--reflink`
$ cp --reflink=always /tmp/disk/src1 /tmp/disk/dst1
$ cp --reflink=always /tmp/disk/src2 /tmp/disk/dst1
$ cat /tmp/disk/dst1
success
$
$ # Now testing with uutils
$ cargo run cp --reflink=always /tmp/disk/src1 /tmp/disk/dst2
    Finished dev [unoptimized + debuginfo] target(s) in 0.25s
     Running `target/debug/coreutils cp --reflink=always /tmp/disk/src1 /tmp/disk/dst2`
$ cargo run cp --reflink=always /tmp/disk/src2 /tmp/disk/dst2
    Finished dev [unoptimized + debuginfo] target(s) in 0.26s
     Running `target/debug/coreutils cp --reflink=always /tmp/disk/src2 /tmp/disk/dst2`
cp: failed to clone "/tmp/disk/src2" from "/tmp/disk/dst2": Invalid argument (os error 22)
$ cat /tmp/disk/dst2
[lots of 'a']
$
$ # With truncate(true)
$ cargo run cp --reflink=always /tmp/disk/src1 /tmp/disk/dst3
    Finished dev [unoptimized + debuginfo] target(s) in 7.98s
     Running `target/debug/coreutils cp --reflink=always /tmp/disk/src1 /tmp/disk/dst3`
$ cargo run cp --reflink=always /tmp/disk/src2 /tmp/disk/dst3
    Finished dev [unoptimized + debuginfo] target(s) in 0.27s
     Running `target/debug/coreutils cp --reflink=always /tmp/disk/src2 /tmp/disk/dst3`
$ cat /tmp/disk/dst3
success
```
2022-08-04 08:50:19 +02:00
Sylvestre Ledru
c660fc700f
Merge pull request #3757 from cakebaker/clap_update
bump clap from 3.1.18 to 3.2.15
2022-08-02 09:56:01 +02:00
Sylvestre Ledru
9b81e09f7a
Merge pull request #3764 from cakebaker/numfmt_preserve_trailing_zeros
numfmt: preserve trailing zeros
2022-08-01 13:32:55 +02:00
Daniel Hofstetter
e642ca90dd numfmt: preserve trailing zeros 2022-08-01 09:48:13 +02:00
Pierre Marsais
4ad0d5c5a3
ls: Implement --zero flag. (#2929) (#3746)
* ls: Implement --zero flag. (#2929)

This flag can be used to provide a easy machine parseable output from
ls, as discussed in the GNU bug report
https://debbugs.gnu.org/cgi/bugreport.cgi?bug=49716.

There are some peculiarities with this flag:

 - Current implementation of GNU ls of the `--zero` flag implies some
   other flags. Those can be overridden by setting those flags after
   `--zero` in the command line.
 - This flag is not compatible with `--dired`. This patch is not 100%
   compliant with GNU ls: GNU ls `--zero` will fail if `--dired` and
   `-l` are set, while with this patch only `--dired` is needed for the
   command to fail.

We also add `--dired` flag to the parser, with no additional behaviour
change.

Testing done:
```
$ bash util/build-gnu.sh
 [...]
$ bash util/run-gnu-test.sh tests/ls/zero-option.sh
 [...]
 PASS: tests/ls/zero-option.sh
 ============================================================================
 Testsuite summary for GNU coreutils 9.1.36-8ec11
 ============================================================================
 # TOTAL: 1
 # PASS:  1
 # SKIP:  0
 # XFAIL: 0
 # FAIL:  0
 # XPASS: 0
 # ERROR: 0
 ============================================================================
```

* Use the US way to spell Behavior

* Fix formatting with cargo fmt -- tests/by-util/test_ls.rs

* Simplify --zero flag overriding logic by using index_of

Also, allow multiple --zero flags, as this is possible with GNU ls
command. Only the last one is taken into account.

Co-authored-by: Sylvestre Ledru <sledru@mozilla.com>
2022-07-31 19:02:50 +02:00
Daniel Hofstetter
fc4544c42b bump clap from 3.1.18 to 3.2.15 2022-07-29 14:05:02 +02:00
Daniel Hofstetter
ee13bc41e7 numfmt: implement --format 2022-07-28 09:59:30 +02:00
Sam Nystrom
4e72e284b5
ls: silently ignore -T option (#3718)
* ls: silently ignore `-T` option
2022-07-26 10:35:43 +02:00
Sylvestre Ledru
2fa4d6a2bb
Merge pull request #3740 from resistor/main
Implement wc fast paths that skip Unicode decoding.
2022-07-25 21:15:13 +02:00
Owen Anderson
0e7f1c4c0d Add missing testcases for wc. 2022-07-24 21:56:07 -07:00
Daniel Hofstetter
34b4853890 numfmt: don't round floats if --from is "none" 2022-07-24 16:25:52 +02:00
Sylvestre Ledru
62305e67d1
Merge pull request #3719 from andrewbaptist/main
split: Don't overwrite files
2022-07-23 22:54:57 +02:00
Niyaz Nigmatullin
5f3f1112d1
Basename arguments simple format (#3736)
* basename: support simple format

* tests/basename: add tests for simple format

* basename: follow clippy advice
2022-07-22 13:28:54 +02:00
Andrew Baptist
f2cfc15a70 split: Don't overwrite files
Check that a file exists by calling create_new and changing the
interface of instantiate_current_writer to return a Result rather
than calling unwrap.
2022-07-21 12:06:13 -04:00
Daniel Hofstetter
29c4d08ee9 numfmt: enable ignored test 2022-07-21 13:20:42 +02:00
Sylvestre Ledru
ba24565b60
Merge pull request #3732 from cakebaker/numfmt_auto_suf_si_i
numfmt: show "invalid suffix" error for "i" suffix
2022-07-20 22:51:14 +02:00
Daniel Hofstetter
74bd9a26d6 numfmt: show "invalid suffix" error for "i" suffix 2022-07-20 17:51:36 +02:00
Niyaz Nigmatullin
406d3931e9 tests/ln: fix tests according to new messages 2022-07-19 17:34:52 +03:00
Owen Anderson
735db78b3d
wc: specialize scanning loop on settings. (#3708)
* wc: specialize scanning loop on settings.

The primary computational loop in wc (iterating over all the
characters and computing word lengths, etc) is configured by a
number of boolean options that control the text-scanning behavior.
If we monomorphize the code loop for each possible combination of
scanning configurations, the rustc is able to generate better code
for each instantiation, at the least by removing the conditional
checks on each iteration, and possibly by allowing things like
vectorization.

On my computer (aarch64/macos), I am seeing at least a 5% performance
improvement in release builds on all wc flag configurations
(other than those that were already specialized) against
odyssey1024.txt, with wc -l showing the greatest improvement at 15%.

* Reduce the size of the wc dispatch table by half.

By extracting the handling of hand-written fast-paths to the
same dispatch as the automatic specializations, we can avoid
needing to pass `show_bytes` as a const generic to
`word_count_from_reader_specialized`. Eliminating this parameter
halves the number of arms in the dispatch.
2022-07-18 12:16:52 +02:00