1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 03:27:44 +00:00

mktemp: simplify file path parameter logic

Simplify the logic of computing the file path parameters (the
directory, prefix, suffix, and number of random characters) for the
temporary file created by `mktemp`. This commits adds an `Options`
struct as a layer of indirection between the application logic and
`clap`, and a `Params` struct whose associated function is responsible
for determining the file path parameters from the `Options`. This is
an improvement because the previous code had some logic for
determining file path parameters in one place and some in another
place.
This commit is contained in:
Jeffrey Finkelstein 2022-05-28 18:35:34 -04:00
parent e276e652dc
commit 43e9fb73b1
2 changed files with 230 additions and 176 deletions

View file

@ -519,6 +519,7 @@ fn test_directory_permissions() {
/// Test that a template with a path separator is invalid.
#[test]
fn test_template_path_separator() {
#[cfg(not(windows))]
new_ucmd!()
.args(&["-t", "a/bXXX"])
.fails()
@ -526,6 +527,14 @@ fn test_template_path_separator() {
"mktemp: invalid template, {}, contains directory separator\n",
"a/bXXX".quote()
));
#[cfg(windows)]
new_ucmd!()
.args(&["-t", r"a\bXXX"])
.fails()
.stderr_only(format!(
"mktemp: invalid template, {}, contains directory separator\n",
r"a\bXXX".quote()
));
}
/// Test that a suffix with a path separator is invalid.