Skip to content

Commit

Permalink
Add tests for mktemp tmpdir flags
Browse files Browse the repository at this point in the history
And set overrides_with for tmpdir flags.

Tests were copied from #4275

Co-authored-by: David Matos <[email protected]>
  • Loading branch information
tmccombs and dmatos2012 committed Feb 13, 2023
1 parent 49ddd6f commit 5423deb
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/uu/mktemp/src/mktemp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
)
Expand Down
60 changes: 60 additions & 0 deletions tests/by-util/test_mktemp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -826,3 +826,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");
}

0 comments on commit 5423deb

Please sign in to comment.