Commit graph

187 commits

Author SHA1 Message Date
Joining7943
7c0ed0340b tests/util: Add stdout_check, stdout_str_check ... to CmdResult to run arbitrary assertions 2023-01-22 14:56:19 +01:00
Joining7943
c2ad54fe09 tests/util: Add methods in CmdResult to assert the received signal on unix systems
Add tests for these signal methods. Include `signals` feature in Cargo.toml uucore dev-dependencies.
2023-01-22 14:56:19 +01:00
Joining7943
19db042022 tests/util: Use ExitStatus instead of code, success in CmdResult. Rewrite tests for CmdResult 2023-01-22 14:48:23 +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
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
267a22e12c add track_caller attribute to assertion functions 2023-01-01 15:25:37 +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
c5728a61b4
fix some clippy warnings (#4229)
* fix some clippy warnings

* Fix the last two
2022-12-14 15:42:07 +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
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
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
Daniel Hofstetter
9a2174ba02 chore: standardize creation of empty strings 2022-12-01 13:49:23 +01:00
Niyaz Nigmatullin
fdd6a05259 chore: run cargo +nightly clippy --fix 2022-11-16 11:09:44 +02:00
Jeffrey Finkelstein
55b3766c10 clippy fixes 2022-10-23 13:56:20 -04:00
Terts Diepraam
153614c40e tests: update to clap 4 2022-10-13 17:50:43 +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
Jeffrey Finkelstein
2f88ba8628 tests: add AtPath.set_mode() method
Add the `AtPath.set_mode()` method that sets the permissions for a
given path in the test directory.
2022-10-09 17:28:43 -04:00
Joining7943
1725151ef8 tests/tail: Fix tests to reflect changes from the refactoring #3905 2022-10-05 13:32:35 +02:00
Sylvestre Ledru
8478570c04 Disable test_when_piped_input_then_no_broken_pipe by default
It is blocking the executions of the tests and I suspect it is breaking android
2022-10-04 17:17:01 +02:00
Niyaz Nigmatullin
84a741fe91 cp: add -H option, add tests, fix test 2022-09-23 20:31:24 +03:00
Joining7943
795ab1fb7e tests/common/util: Fix #3895 broken pipe error when using pipep input in UCommand 2022-09-10 11:10:53 +02:00
Joining7943
e860eb899e tests/common/util: Add test which provokes the broken pipe error 2022-09-10 11:10:53 +02: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
Terts Diepraam
ba713b6365 Simplify invalid encoding handling into two small methods of Args
The previous encoding handling was unnecessarily complex. This commit removes the enum that specifies the handling and instead has two separate methods to collect the strings either with lossy conversion or by ignoring invalidly encoded strings.
2022-08-17 15:20:20 +02:00
Terts Diepraam
5621502a95 all: remove accept_{any, complete, lossy} and ConversionResult
Outside of tests, only `accept_any` was used, meaning that this unnecessarily complicated the code. The behaviour of `accept_any` is now the default (and only) option.
2022-08-17 14:57:28 +02:00
Daniel Hofstetter
dd19f85d2b Fix clippy warnings in tests 2022-08-12 09:45:16 +02:00
Sylvestre Ledru
e239ed9417
Merge pull request #3692 from jfinkels/cp-preserve-perm-link
cp: correctly copy attributes of a dangling symbolic link
2022-07-11 22:50:24 +02:00
Niyaz Nigmatullin
9d285e953d
Realpath symlinks handling, solves issue #3669 (#3703) 2022-07-10 16:49:25 +02:00
Sylvestre Ledru
922afa29ff
Merge branch 'main' into cp-preserve-perm-link 2022-07-07 15:22:57 +02:00
Jeffrey Finkelstein
78a11ad69b tests/common/util: add AtPath::symlink_exists()
Add helper method for deciding whether a symbolic link exists in the
test directory.
2022-07-03 13:44:29 -04:00
Niyaz Nigmatullin
b3642b64c5 test_realpath: reformatted using rustfmt 2022-06-30 11:52:17 +02:00
Niyaz Nigmatullin
1ecc789dea test_realpath: fixed test to be the one that was supposed to be and
added non-passing test
2022-06-30 11:52:17 +02:00
Jan Scheer
12d7d9846a
test/util: improve run_ucmd_as_root for CICD
* ensure that `fn run_no_wait` is only invoked if the system running the
test has `sudo` in $path

Previously, if run inside CICD, calling `fn run_ucmd_as_root`
would provoke `fn run_no_wait` to panic because there's no `sudo`.
2022-05-10 23:41:22 +02:00
Sylvestre Ledru
eaad6c5286 more comment
mostly to retrigger the ci :)
2022-05-01 20:15:44 +02:00
Jan Scheer
bab7ba8a52 Update util.rs 2022-05-01 20:15:44 +02:00
Jan Scheer
de01b11a7d Update util.rs
add feature for `whoami`
2022-05-01 20:15:44 +02:00
Jan Scheer
e991838ca8 tests/util: add a convenience wrapper to run a ucmd with root
permissions
2022-05-01 20:15:44 +02:00
Justin Tracey
67a01a5d79 preserve LD_PRELOAD in the test env 2022-04-20 08:44:49 +02:00
Justin Tracey
1f025c19af address libc weirdness on 32 bit android 2022-04-20 08:44:49 +02:00
Justin Tracey
2a0d58d060 get android builds to compile and pass tests 2022-04-20 08:44:49 +02:00
Sylvestre Ledru
991672a030 Adjust rlimit usage with the new version 2022-04-13 11:18:37 +02:00
Jeffrey Finkelstein
7192856da4 tests: print stdout in error msg for no_stdout()
Fix a bug in which the error message displayed when using
`CmdResult::no_stdout()` was incorrectly showing stderr when it should
have been showing stdout.
2022-04-09 12:44:24 -04:00
Hanif Ariffin
30a174e6e4
realpath: Error when resolved symlink is absolute and ENOENT (#3037)
* realpath: Match behavior where resolving symlinks with absolute path is an error if ENOENT

This PR changes `realpath` to match the behavior in GNU where,

```shell
hbina@akarin ~/Documents> mkdir dir1
hbina@akarin ~/Documents> mkdir dir2
hbina@akarin ~/Documents> touch dir2/bar
hbina@akarin ~/Documents> ln -s ../dir2/bar dir1/foo1
hbina@akarin ~/Documents> ln -s /dir2/bar dir1/foo2
hbina@akarin ~/Documents> ln -s ../dir2/baz dir1/foo3
hbina@akarin ~/Documents> realpath ./dir1/foo1 ./dir1/foo2 ./dir1/foo3
/home/hbina/Documents/dir2/bar
realpath: ./dir1/foo2: No such file or directory
/home/hbina/Documents/dir2/baz
```

Currently, our `realpath` will happily print the second one out,

```shell
hbina@akarin ~/Documents> ~/git/uutils/target/debug/coreutils realpath ./dir1/foo1 ./dir1/foo2 ./dir1/foo3
/home/hbina/Documents/dir2/bar
/dir2/bar
/home/hbina/Documents/dir2/baz
```

Closes https://github.com/uutils/coreutils/issues/3036

Signed-off-by: Hanif Ariffin <hanif.ariffin.4326@gmail.com>
2022-03-03 23:06:15 +01:00
Jeffrey Finkelstein
e598bf0835 tests: add CmdResult::stdout_is_fixture_bytes()
Add helper method `CmdResult::stdout_is_fixture_bytes()`, which is
like `stdout_is_fixture()` but compares stdout to the raw bytes of a
given file instead of decoding the contents of the file to a UTF-8
string.
2022-02-15 21:50:48 -05:00