From 0105531b7f368ffa25464b17aaaba33ca3fa1608 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Wed, 2 Jun 2021 20:59:53 +0200 Subject: [PATCH 1/4] show the backtrace in case of a rust crash --- util/run-gnu-test.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/util/run-gnu-test.sh b/util/run-gnu-test.sh index 61034e015..044c6c140 100644 --- a/util/run-gnu-test.sh +++ b/util/run-gnu-test.sh @@ -5,4 +5,5 @@ BUILDDIR="${PWD}/uutils/target/release" GNULIB_DIR="${PWD}/gnulib" pushd gnu +export RUST_BACKTRACE=1 timeout -sKILL 2h make -j "$(nproc)" check SUBDIRS=. RUN_EXPENSIVE_TESTS=yes RUN_VERY_EXPENSIVE_TESTS=yes VERBOSE=no || : # Kill after 4 hours in case something gets stuck in make From e7f59168646b1f2ccd533ce3991694a53970906c Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Wed, 2 Jun 2021 21:21:12 +0200 Subject: [PATCH 2/4] gnu/ci: allow to run a single gnu test (and document it) --- CONTRIBUTING.md | 1 + README.md | 4 ++++ util/run-gnu-test.sh | 8 +++++++- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 3793a0968..47793977e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -18,6 +18,7 @@ search the issues to make sure no one else is working on it. ## Best practices 1. Follow what GNU is doing in term of options and behavior. +1. If possible, look at the GNU test suite execution in the CI and make the test work if failing. 1. Use clap for argument management. 1. Make sure that the code coverage is covering all of the cases, including errors. 1. The code must be clippy-warning-free and rustfmt-compliant. diff --git a/README.md b/README.md index 8ab4c6128..fde01d64a 100644 --- a/README.md +++ b/README.md @@ -327,8 +327,12 @@ To run locally: ```bash $ bash util/build-gnu.sh $ bash util/run-gnu-test.sh +# To run a single test: +$ bash util/run-gnu-test.sh tests/touch/not-owner.sh # for example ``` +Note that it relies on individual utilities (not the multicall binary). + ## Contribute To contribute to uutils, please see [CONTRIBUTING](CONTRIBUTING.md). diff --git a/util/run-gnu-test.sh b/util/run-gnu-test.sh index 044c6c140..9d51a983e 100644 --- a/util/run-gnu-test.sh +++ b/util/run-gnu-test.sh @@ -6,4 +6,10 @@ GNULIB_DIR="${PWD}/gnulib" pushd gnu export RUST_BACKTRACE=1 -timeout -sKILL 2h make -j "$(nproc)" check SUBDIRS=. RUN_EXPENSIVE_TESTS=yes RUN_VERY_EXPENSIVE_TESTS=yes VERBOSE=no || : # Kill after 4 hours in case something gets stuck in make + +if test -n "$1"; then + # if set, run only the test passed + export RUN_TEST="TESTS=$1" +fi + +timeout -sKILL 2h make -j "$(nproc)" check $RUN_TEST SUBDIRS=. RUN_EXPENSIVE_TESTS=yes RUN_VERY_EXPENSIVE_TESTS=yes VERBOSE=no || : # Kill after 4 hours in case something gets stuck in make From eb2c06c37e29ebdc97a58eeb4002bccae7a46709 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Wed, 2 Jun 2021 22:53:10 +0200 Subject: [PATCH 3/4] touch/gnu compat: when touch fails because of a permission error, change the error message + return 1 as error code when having this error --- src/uu/touch/src/touch.rs | 24 ++++++++++++++++++++---- tests/by-util/test_touch.rs | 10 ++++++++++ 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/uu/touch/src/touch.rs b/src/uu/touch/src/touch.rs index b76e04b7a..ed65cb659 100644 --- a/src/uu/touch/src/touch.rs +++ b/src/uu/touch/src/touch.rs @@ -155,6 +155,8 @@ pub fn uumain(args: impl uucore::Args) -> i32 { (now, now) }; + let mut error_code = 0; + for filename in &files { let path = &filename[..]; @@ -202,14 +204,28 @@ pub fn uumain(args: impl uucore::Args) -> i32 { if matches.is_present(options::NO_DEREF) { if let Err(e) = set_symlink_file_times(path, atime, mtime) { - show_warning!("cannot touch '{}': {}", path, e); + // we found an error, it should fail in any case + error_code = 1; + if e.kind() == std::io::ErrorKind::PermissionDenied { + // GNU compatibility (not-owner.sh) + show_error!("setting times of '{}': {}", path, "Permission denied"); + } else { + show_error!("setting times of '{}': {}", path, e); + } } } else if let Err(e) = filetime::set_file_times(path, atime, mtime) { - show_warning!("cannot touch '{}': {}", path, e); + // we found an error, it should fail in any case + error_code = 1; + + if e.kind() == std::io::ErrorKind::PermissionDenied { + // GNU compatibility (not-owner.sh) + show_error!("setting times of '{}': {}", path, "Permission denied"); + } else { + show_error!("setting times of '{}': {}", path, e); + } } } - - 0 + error_code } fn stat(path: &str, follow: bool) -> (FileTime, FileTime) { diff --git a/tests/by-util/test_touch.rs b/tests/by-util/test_touch.rs index 3c803e1c6..cd780f670 100644 --- a/tests/by-util/test_touch.rs +++ b/tests/by-util/test_touch.rs @@ -449,3 +449,13 @@ fn test_touch_mtime_dst_fails() { ucmd.args(&["-m", "-t", &s, file]).fails(); } } + +#[test] +#[cfg(unix)] +fn test_touch_system_fails() { + let (_at, mut ucmd) = at_and_ucmd!(); + let file = "/"; + ucmd.args(&[file]) + .fails() + .stderr_contains("setting times of '/'"); +} From 31875a241fc1b1c3582b8e876cf3c44d1145d468 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Wed, 2 Jun 2021 23:43:16 +0200 Subject: [PATCH 4/4] touch/gnu compat: 'touch no-file' exit code should be 1 --- src/uu/touch/src/touch.rs | 1 + tests/by-util/test_touch.rs | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/src/uu/touch/src/touch.rs b/src/uu/touch/src/touch.rs index ed65cb659..1b560553f 100644 --- a/src/uu/touch/src/touch.rs +++ b/src/uu/touch/src/touch.rs @@ -168,6 +168,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { if let Err(e) = File::create(path) { show_warning!("cannot touch '{}': {}", path, e); + error_code = 1; continue; }; diff --git a/tests/by-util/test_touch.rs b/tests/by-util/test_touch.rs index cd780f670..c861a50dd 100644 --- a/tests/by-util/test_touch.rs +++ b/tests/by-util/test_touch.rs @@ -459,3 +459,10 @@ fn test_touch_system_fails() { .fails() .stderr_contains("setting times of '/'"); } + +#[test] +fn test_touch_trailing_slash() { + let (_at, mut ucmd) = at_and_ucmd!(); + let file = "no-file/"; + ucmd.args(&[file]).fails(); +}