diff --git a/src/uu/mktemp/src/mktemp.rs b/src/uu/mktemp/src/mktemp.rs index ae44225c9..00f23c50a 100644 --- a/src/uu/mktemp/src/mktemp.rs +++ b/src/uu/mktemp/src/mktemp.rs @@ -236,8 +236,13 @@ impl Params { let (i, j) = match find_last_contiguous_block_of_xs(&options.template) { None => { let s = match options.suffix { + // If a suffix is specified, the error message includes the template without the suffix. + Some(_) => options + .template + .chars() + .take(options.template.len()) + .collect::(), None => options.template, - Some(s) => format!("{}{}", options.template, s), }; return Err(MkTempError::TooFewXs(s)); } diff --git a/tests/by-util/test_mktemp.rs b/tests/by-util/test_mktemp.rs index 611a42e43..8a919948c 100644 --- a/tests/by-util/test_mktemp.rs +++ b/tests/by-util/test_mktemp.rs @@ -629,7 +629,7 @@ fn test_too_few_xs_suffix() { new_ucmd!() .args(&["--suffix=X", "aXX"]) .fails() - .stderr_only("mktemp: too few X's in template 'aXXX'\n"); + .stderr_only("mktemp: too few X's in template 'aXX'\n"); } #[test] @@ -637,7 +637,7 @@ 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"); + .stderr_only("mktemp: too few X's in template 'aXX'\n"); } #[test]