Skip to content

Commit

Permalink
fixup! mktemp: add message for directory not found
Browse files Browse the repository at this point in the history
  • Loading branch information
jfinkels committed Sep 18, 2022
1 parent 0764fba commit 61e0b9c
Showing 1 changed file with 34 additions and 36 deletions.
70 changes: 34 additions & 36 deletions tests/by-util/test_mktemp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -738,56 +738,54 @@ fn test_tmpdir_env_var() {

#[test]
fn test_nonexistent_tmpdir_env_var() {
let result = new_ucmd!().env(TMPDIR, "no/such/dir").fails();
result.no_stdout();
let stderr = result.stderr_str();
#[cfg(not(windows))]
assert_eq!(stderr, "mktemp: failed to create file via template 'no/such/dir/tmp.XXXXXXXXXX': No such file or directory\n");
new_ucmd!().env(TMPDIR, "no/such/dir").fails().stderr_only("mktemp: failed to create file via template 'no/such/dir/tmp.XXXXXXXXXX': No such file or directory\n");
#[cfg(windows)]
assert!(
stderr.starts_with("mktemp: failed to create file via template")
&& stderr.ends_with("'no/such/dir/tmp.XXXXXXXXXX': No such file or directory\n")
);
{
let result = new_ucmd!().env(TMPDIR, r"no\such\dir").fails();
result.no_stdout();
let stderr = result.stderr_str();
assert!(stderr.starts_with("mktemp: failed to create file via template"));
assert!(stderr.ends_with(r"no\such\dir/tmp.XXXXXXXXXX': No such file or directory\n"));
}

let result = new_ucmd!().env(TMPDIR, "no/such/dir").arg("-d").fails();
result.no_stdout();
let stderr = result.stderr_str();
#[cfg(not(windows))]
assert_eq!(stderr, "mktemp: failed to create directory via template 'no/such/dir/tmp.XXXXXXXXXX': No such file or directory\n");
new_ucmd!().env(TMPDIR, "no/such/dir").arg("-d").fails().stderr_only("mktemp: failed to create directory via template 'no/such/dir/tmp.XXXXXXXXXX': No such file or directory\n");
#[cfg(windows)]
assert!(
stderr.starts_with("mktemp: failed to create directory via template")
&& stderr.ends_with("'no/such/dir/tmp.XXXXXXXXXX': No such file or directory\n")
);
{
let result = new_ucmd!().env(TMPDIR, r"no\such\dir").arg("-d").fails();
result.no_stdout();
let stderr = result.stderr_str();
assert!(stderr.starts_with("mktemp: failed to create directory via template"));
assert!(stderr.ends_with(r"no\such\dir/tmp.XXXXXXXXXX': No such file or directory\n"));
}
}

#[test]
fn test_nonexistent_dir_prefix() {
let result = new_ucmd!().arg("d/XXX").fails();
result.no_stdout();
let stderr = result.stderr_str();
#[cfg(not(windows))]
assert_eq!(
stderr,
"mktemp: failed to create file via template 'd/XXX': No such file or directory\n"
new_ucmd!().arg("d/XXX").fails().stderr_only(
"mktemp: failed to create file via template 'd/XXX': No such file or directory\n",
);
#[cfg(windows)]
assert!(
stderr.starts_with("mktemp: failed to create file via template")
&& stderr.ends_with("d/XXX': No such file or directory\n")
);
{
let result = new_ucmd!().arg(r"d\XXX").fails();
result.no_stdout();
let stderr = result.stderr_str();
assert!(stderr.starts_with("mktemp: failed to create file via template"));
assert!(stderr.ends_with(r"d\XXX': No such file or directory\n"));
}

let result = new_ucmd!().args(&["-d", "d/XXX"]).fails();
result.no_stdout();
let stderr = result.stderr_str();
#[cfg(not(windows))]
assert_eq!(
stderr,
"mktemp: failed to create directory via template 'd/XXX': No such file or directory\n"
new_ucmd!().arg("-d").arg("d/XXX").fails().stderr_only(
"mktemp: failed to create directory via template 'd/XXX': No such file or directory\n",
);
#[cfg(windows)]
assert!(
stderr.starts_with("mktemp: failed to create directory via template")
&& stderr.ends_with("d/XXX': No such file or directory\n")
);
{
let result = new_ucmd!().arg("-d").arg(r"d\XXX").fails();
result.no_stdout();
let stderr = result.stderr_str();
assert!(stderr.starts_with("mktemp: failed to create file via template"));
assert!(stderr.ends_with(r"d\XXX': No such file or directory\n"));
}
}

0 comments on commit 61e0b9c

Please sign in to comment.