From edbdfea3034c7e4d72eb5f9ae3f2f83b299fe196 Mon Sep 17 00:00:00 2001 From: Thayne McCombs Date: Mon, 13 Feb 2023 00:00:02 -0700 Subject: [PATCH] Add tests for mktemp tmpdir flags And set overrides_with for tmpdir flags. Tests were copied from #4275 Co-authored-by: David Matos --- src/uu/mktemp/src/mktemp.rs | 1 + tests/by-util/test_mktemp.rs | 60 ++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) diff --git a/src/uu/mktemp/src/mktemp.rs b/src/uu/mktemp/src/mktemp.rs index 677b8dcd13d..f5a3af8cdf6 100644 --- a/src/uu/mktemp/src/mktemp.rs +++ b/src/uu/mktemp/src/mktemp.rs @@ -418,6 +418,7 @@ pub fn uu_app() -> Command { .num_args(0..=1) // Require an equals to avoid ambiguity if no tmpdir is supplied .require_equals(true) + .overrides_with(OPT_P) .value_parser(ValueParser::path_buf()) .value_hint(clap::ValueHint::DirPath), ) diff --git a/tests/by-util/test_mktemp.rs b/tests/by-util/test_mktemp.rs index f99f92a805d..4c5d700dbcb 100644 --- a/tests/by-util/test_mktemp.rs +++ b/tests/by-util/test_mktemp.rs @@ -828,3 +828,63 @@ fn test_default_missing_value() { let scene = TestScenario::new(util_name!()); scene.ucmd().arg("-d").arg("--tmpdir").succeeds(); } + +#[test] +fn test_missing_xs_tmpdir_template() { + let scene = TestScenario::new(util_name!()); + scene + .ucmd() + .arg("--tmpdir") + .arg(TEST_TEMPLATE3) + .fails() + .no_stdout() + .stderr_contains("too few X's in template"); + scene + .ucmd() + .arg("--tmpdir=foobar") + .fails() + .no_stdout() + .stderr_contains("failed to create file via template"); +} + +#[test] +fn test_both_tmpdir_flags_present() { + let scene = TestScenario::new(util_name!()); + scene + .ucmd() + .arg("-p") + .arg(".") + .arg("--tmpdir") + .arg("foobarXXXX") + .succeeds() + .no_stderr() + .stdout_contains("/tmp/foobar"); + scene + .ucmd() + .arg("-p") + .arg(".") + .arg("--tmpdir=foobarXXXX") + .fails() + .no_stdout() + .stderr_contains("failed to create file via template"); + scene + .ucmd() + .arg("--tmpdir") + .arg("foobarXXXX") + .arg("-p") + .arg(".") + .succeeds() + .no_stderr() + .stdout_contains("./foobar"); +} + +#[test] +fn test_missing_short_tmpdir_flag() { + let scene = TestScenario::new(util_name!()); + scene + .ucmd() + .arg("-p") + .fails() + .no_stdout() + .stderr_contains("requires a value but none was supplied"); +}