1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-09-15 11:36:16 +00:00

Merge pull request #4342 from tmccombs/mktemp-req-equals

Require = for --tmpdir in mktemp
This commit is contained in:
Sylvestre Ledru 2023-07-21 14:36:25 +02:00 committed by GitHub
commit e77a1bf54c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 119 additions and 67 deletions

View file

@ -901,3 +901,82 @@ 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!());
#[cfg(not(windows))]
let template = format!(".{MAIN_SEPARATOR}foobarXXXX");
let (at, mut ucmd) = at_and_ucmd!();
let result = ucmd
.env(TMPDIR, ".")
.arg("-p")
.arg("nonsense")
.arg("--tmpdir")
.arg("foobarXXXX")
.succeeds();
let filename = result.no_stderr().stdout_str().trim_end();
#[cfg(not(windows))]
assert_matches_template!(&template, filename);
#[cfg(windows)]
assert_suffix_matches_template!("foobarXXXX", filename);
assert!(at.file_exists(filename));
scene
.ucmd()
.arg("-p")
.arg(".")
.arg("--tmpdir=does_not_exist")
.fails()
.no_stdout()
.stderr_contains("failed to create file via template");
let (at, mut ucmd) = at_and_ucmd!();
let result = ucmd
.arg("--tmpdir")
.arg("foobarXXXX")
.arg("-p")
.arg(".")
.succeeds();
let filename = result.no_stderr().stdout_str().trim_end();
#[cfg(not(windows))]
assert_matches_template!(&template, filename);
#[cfg(windows)]
assert_suffix_matches_template!("foobarXXXX", filename);
assert!(at.file_exists(filename));
}
#[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 <DIR>' but none was supplied");
}