Commit graph

2277 commits

Author SHA1 Message Date
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
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
Joining7943
1d7447d42e tests/util: Add setting timeout for UChild::kill and run and wait methods in UCommand and UChild.
Additional notes:
* Set default timeout to 30s
* Fix UChild::kill to always fail on timeout if zero
2022-12-17 21:53:39 +01:00
Sylvestre Ledru
8489e9b69c Ignore some cp tests on android
Closes: #4233
2022-12-17 16:54:23 +01:00
Sylvestre Ledru
c5728a61b4
fix some clippy warnings (#4229)
* fix some clippy warnings

* Fix the last two
2022-12-14 15:42:07 +01: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
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
Terts Diepraam
7555527d07
Merge pull request #4225 from Joining7943/4223-fix-intermittent-test-failures
tests/util: Fix #4223: intermittent failing uchild tests
2022-12-13 11:40:11 +01: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
Joining7943
7ef9504952 tests/util: Fix intermittent failing uchild tests on macos. The ci can be slow, so increase delay.
Closes #4223
2022-12-12 12:52:10 +01: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