Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mktemp -t foo.XXXX should create in TMPDIR #4832

Merged
merged 2 commits into from
May 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/uu/mktemp/src/mktemp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
}
Expand Down
31 changes: 31 additions & 0 deletions tests/by-util/test_mktemp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}