1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 19:47:45 +00:00

Merge pull request #4832 from sylvestre/issue_4821

mktemp -t foo.XXXX should create in TMPDIR
This commit is contained in:
Daniel Hofstetter 2023-05-18 14:12:40 +02:00 committed by GitHub
commit 74e73bee06
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 39 additions and 1 deletions

View file

@ -191,7 +191,14 @@ impl Options {
(tmpdir, template.to_string())
}
Some(template) => {
let tmpdir = matches.get_one::<String>(OPT_TMPDIR).map(String::from);
let tmpdir = if matches.contains_id(OPT_TMPDIR) {
matches.get_one::<String>(OPT_TMPDIR).map(String::from)
} else if matches.get_flag(OPT_T) {
// mktemp -t foo.xxx should export in TMPDIR
Some(env::temp_dir().display().to_string())
} else {
matches.get_one::<String>(OPT_TMPDIR).map(String::from)
};
(tmpdir, template.to_string())
}
}

View file

@ -857,3 +857,34 @@ fn test_default_missing_value() {
let scene = TestScenario::new(util_name!());
scene.ucmd().arg("-d").arg("--tmpdir").succeeds();
}
#[test]
fn test_default_issue_4821_t_tmpdir() {
let scene = TestScenario::new(util_name!());
let pathname = scene.fixtures.as_string();
let result = scene
.ucmd()
.env(TMPDIR, &pathname)
.arg("-t")
.arg("foo.XXXX")
.succeeds();
let stdout = result.stdout_str();
println!("stdout = {stdout}");
assert!(stdout.contains(&pathname));
}
#[test]
fn test_default_issue_4821_t_tmpdir_p() {
let scene = TestScenario::new(util_name!());
let pathname = scene.fixtures.as_string();
let result = scene
.ucmd()
.arg("-t")
.arg("-p")
.arg(&pathname)
.arg("foo.XXXX")
.succeeds();
let stdout = result.stdout_str();
println!("stdout = {stdout}");
assert!(stdout.contains(&pathname));
}