Fix mktemp -t -p ~/projects/playground foo.XXXX

This commit is contained in:
Sylvestre Ledru 2023-05-15 21:32:35 +02:00
parent 35b5fd6a40
commit cd189b2391
2 changed files with 19 additions and 1 deletions

View file

@ -191,7 +191,9 @@ impl Options {
(tmpdir, template.to_string())
}
Some(template) => {
let tmpdir = if matches.get_flag(OPT_T) {
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 {

View file

@ -872,3 +872,19 @@ fn test_default_issue_4821_t_tmpdir() {
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));
}