mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
mktemp: include suffix in error message
Include the suffix in the error message produced by `mktemp` when there are too few Xs in the template. Before this commit, $ mktemp --suffix=X aXX mktemp: too few X's in template 'aXX' After this commit, $ mktemp --suffix=X aXX mktemp: too few X's in template 'aXXX' This matches the behavior of GNU `mktemp`.
This commit is contained in:
parent
d92107362b
commit
35fb4e6ea1
2 changed files with 21 additions and 1 deletions
|
@ -267,7 +267,11 @@ fn parse_template<'a>(
|
||||||
let rand = right - left;
|
let rand = right - left;
|
||||||
|
|
||||||
if rand < 3 {
|
if rand < 3 {
|
||||||
return Err(MkTempError::TooFewXs(temp.into()));
|
let s = match suffix {
|
||||||
|
None => temp.into(),
|
||||||
|
Some(s) => format!("{}{}", temp, s),
|
||||||
|
};
|
||||||
|
return Err(MkTempError::TooFewXs(s));
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut suf = &temp[right..];
|
let mut suf = &temp[right..];
|
||||||
|
|
|
@ -527,3 +527,19 @@ fn test_suffix_path_separator() {
|
||||||
.fails()
|
.fails()
|
||||||
.stderr_only("mktemp: invalid suffix '\\b', contains directory separator\n");
|
.stderr_only("mktemp: invalid suffix '\\b', contains directory separator\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_too_few_xs_suffix() {
|
||||||
|
new_ucmd!()
|
||||||
|
.args(&["--suffix=X", "aXX"])
|
||||||
|
.fails()
|
||||||
|
.stderr_only("mktemp: too few X's in template 'aXXX'\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_too_few_xs_suffix_directory() {
|
||||||
|
new_ucmd!()
|
||||||
|
.args(&["-d", "--suffix=X", "aXX"])
|
||||||
|
.fails()
|
||||||
|
.stderr_only("mktemp: too few X's in template 'aXXX'\n");
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue