Merge pull request #3551 from jfinkels/mktemp-too-few-xs-suffix

mktemp: include suffix in error message
This commit is contained in:
Sylvestre Ledru 2022-05-23 08:38:15 +02:00 committed by GitHub
commit c818ca0039
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 1 deletions

View file

@ -267,7 +267,11 @@ fn parse_template<'a>(
let rand = right - left;
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..];

View file

@ -527,3 +527,19 @@ fn test_suffix_path_separator() {
.fails()
.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");
}