diff --git a/src/uu/mktemp/src/mktemp.rs b/src/uu/mktemp/src/mktemp.rs index 9466f7c63..9c0860d92 100644 --- a/src/uu/mktemp/src/mktemp.rs +++ b/src/uu/mktemp/src/mktemp.rs @@ -428,6 +428,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 6bcb37f45..db60d2453 100644 --- a/tests/by-util/test_mktemp.rs +++ b/tests/by-util/test_mktemp.rs @@ -901,3 +901,63 @@ fn test_t_ensure_tmpdir_has_higher_priority_than_p() { println!("stdout = {stdout}"); assert!(stdout.contains(&pathname)); } + +#[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("a value is required for '-p ' but none was supplied"); +}