From e5a7bcbb9d6a29d0f9c3b8911ed4d4764cf51882 Mon Sep 17 00:00:00 2001 From: Michael Debertol Date: Mon, 21 Jun 2021 21:13:40 +0200 Subject: [PATCH 1/4] tests: keep env vars for the temporary directory On some Windows machines this would otherwise cause `std::env::temp_dir` to fall back to a path that is not writeable (C:\\Windows). Since by default integration tests don't inherit env vars from the parent, we have to override this in some cases. --- tests/by-util/test_mktemp.rs | 4 ++-- tests/by-util/test_sort.rs | 15 ++++++++++----- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/tests/by-util/test_mktemp.rs b/tests/by-util/test_mktemp.rs index d601bad5b..413b35bc5 100644 --- a/tests/by-util/test_mktemp.rs +++ b/tests/by-util/test_mktemp.rs @@ -386,7 +386,7 @@ fn test_mktemp_tmpdir_one_arg() { let scene = TestScenario::new(util_name!()); let result = scene - .ucmd() + .ucmd_keepenv() .arg("--tmpdir") .arg("apt-key-gpghome.XXXXXXXXXX") .succeeds(); @@ -399,7 +399,7 @@ fn test_mktemp_directory_tmpdir() { let scene = TestScenario::new(util_name!()); let result = scene - .ucmd() + .ucmd_keepenv() .arg("--directory") .arg("--tmpdir") .arg("apt-key-gpghome.XXXXXXXXXX") diff --git a/tests/by-util/test_sort.rs b/tests/by-util/test_sort.rs index 0f9a9d3f1..01fafae00 100644 --- a/tests/by-util/test_sort.rs +++ b/tests/by-util/test_sort.rs @@ -28,7 +28,8 @@ fn test_helper(file_name: &str, possible_args: &[&str]) { fn test_buffer_sizes() { let buffer_sizes = ["0", "50K", "50k", "1M", "100M"]; for buffer_size in &buffer_sizes { - new_ucmd!() + TestScenario::new(util_name!()) + .ucmd_keepenv() .arg("-n") .arg("-S") .arg(buffer_size) @@ -40,7 +41,8 @@ fn test_buffer_sizes() { { let buffer_sizes = ["1000G", "10T"]; for buffer_size in &buffer_sizes { - new_ucmd!() + TestScenario::new(util_name!()) + .ucmd_keepenv() .arg("-n") .arg("-S") .arg(buffer_size) @@ -877,7 +879,8 @@ fn test_compress() { #[test] fn test_compress_fail() { - new_ucmd!() + TestScenario::new(util_name!()) + .ucmd_keepenv() .args(&[ "ext_sort.txt", "-n", @@ -892,7 +895,8 @@ fn test_compress_fail() { #[test] fn test_merge_batches() { - new_ucmd!() + TestScenario::new(util_name!()) + .ucmd_keepenv() .args(&["ext_sort.txt", "-n", "-S", "150b"]) .succeeds() .stdout_only_fixture("ext_sort.expected"); @@ -900,7 +904,8 @@ fn test_merge_batches() { #[test] fn test_merge_batch_size() { - new_ucmd!() + TestScenario::new(util_name!()) + .ucmd_keepenv() .arg("--batch-size=2") .arg("-m") .arg("--unique") From 622504467f369198ce5839560617130199b6b917 Mon Sep 17 00:00:00 2001 From: Michael Debertol Date: Tue, 22 Jun 2021 17:36:56 +0200 Subject: [PATCH 2/4] mktemp: note that windows uses a different env var for tmpdir On windows `std::env::temp_dir` uses the `TMP` environment variable instead of `TMPDIR`. --- src/uu/mktemp/src/mktemp.rs | 4 ++-- tests/by-util/test_mktemp.rs | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/uu/mktemp/src/mktemp.rs b/src/uu/mktemp/src/mktemp.rs index e04de8702..bd77e9d51 100644 --- a/src/uu/mktemp/src/mktemp.rs +++ b/src/uu/mktemp/src/mktemp.rs @@ -77,14 +77,14 @@ pub fn uumain(args: impl uucore::Args) -> i32 { .long(OPT_TMPDIR) .help( "interpret TEMPLATE relative to DIR; if DIR is not specified, use \ - $TMPDIR if set, else /tmp. With this option, TEMPLATE must not \ + $TMPDIR ($TMP on windows) if set, else /tmp. With this option, TEMPLATE must not \ be an absolute name; unlike with -t, TEMPLATE may contain \ slashes, but mktemp creates only the final component", ) .value_name("DIR"), ) .arg(Arg::with_name(OPT_T).short(OPT_T).help( - "Generate a template (using the supplied prefix and TMPDIR if set) \ + "Generate a template (using the supplied prefix and TMPDIR (TMP on windows) if set) \ to create a filename template [deprecated]", )) .arg( diff --git a/tests/by-util/test_mktemp.rs b/tests/by-util/test_mktemp.rs index 413b35bc5..bcf75ee20 100644 --- a/tests/by-util/test_mktemp.rs +++ b/tests/by-util/test_mktemp.rs @@ -17,7 +17,10 @@ static TEST_TEMPLATE8: &str = "tempXXXl/ate"; #[cfg(windows)] static TEST_TEMPLATE8: &str = "tempXXXl\\ate"; +#[cfg(not(windows))] const TMPDIR: &str = "TMPDIR"; +#[cfg(windows)] +const TMPDIR: &str = "TMP"; #[test] fn test_mktemp_mktemp() { From ce0801db909c979ad2cce37d25879159d71dbbc2 Mon Sep 17 00:00:00 2001 From: Michael Debertol Date: Tue, 22 Jun 2021 15:31:49 +0200 Subject: [PATCH 3/4] tests/mv: test uutils mv instead of system util Calling `cmd_keepenv("mv")` spawned the system `mv` instead of the uutils `mv`. Also, `keepenv` isn't necessary because it doesn't need to inherit environment variables. We now actually check the stderr, because previously the result of `ends_with` was not used, making the test pass even when it shouldn't. I disabled the test on windows because `mkdir` does not support `-m` on windows, making the test fail because there will be no permission error. On FreeBSD there isn't a permission error either, and `mv` succeeds. --- tests/by-util/test_mv.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/by-util/test_mv.rs b/tests/by-util/test_mv.rs index 2f35bf5eb..d8733a4f0 100644 --- a/tests/by-util/test_mv.rs +++ b/tests/by-util/test_mv.rs @@ -729,6 +729,7 @@ fn test_mv_verbose() { } #[test] +#[cfg(target_os = "linux")] // mkdir does not support -m on windows. Freebsd doesn't return a permission error either. fn test_mv_permission_error() { let scene = TestScenario::new("mkdir"); let folder1 = "bar"; @@ -738,12 +739,11 @@ fn test_mv_permission_error() { scene.ucmd().arg("-m777").arg(folder2).succeeds(); scene - .cmd_keepenv(util_name!()) + .ccmd("mv") .arg(folder2) .arg(folder_to_move) - .run() - .stderr_str() - .ends_with("Permission denied"); + .fails() + .stderr_contains("Permission denied"); } // Todo: From d60afb89472c0166d4c884239d8b5784f518d1b4 Mon Sep 17 00:00:00 2001 From: Michael Debertol Date: Tue, 22 Jun 2021 16:02:50 +0200 Subject: [PATCH 4/4] mkdir: note that -m is not supported on windows --- src/uu/mkdir/src/mkdir.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/uu/mkdir/src/mkdir.rs b/src/uu/mkdir/src/mkdir.rs index e8a8ef2db..c5ff8b76c 100644 --- a/src/uu/mkdir/src/mkdir.rs +++ b/src/uu/mkdir/src/mkdir.rs @@ -40,7 +40,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { Arg::with_name(OPT_MODE) .short("m") .long(OPT_MODE) - .help("set file mode") + .help("set file mode (not implemented on windows)") .default_value("755"), ) .arg(