mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
Merge pull request #3568 from jfinkels/mktemp-tmpdir-subdirectory
mktemp: combine `--tmpdir` and subdirectory info
This commit is contained in:
commit
69c2871336
1 changed files with 37 additions and 12 deletions
|
@ -27,6 +27,18 @@ const TMPDIR: &str = "TMPDIR";
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
const TMPDIR: &str = "TMP";
|
const TMPDIR: &str = "TMP";
|
||||||
|
|
||||||
|
/// An assertion that uses [`matches_template`] and adds a helpful error message.
|
||||||
|
macro_rules! assert_matches_template {
|
||||||
|
($template:expr, $s:expr) => {{
|
||||||
|
assert!(
|
||||||
|
matches_template($template, $s),
|
||||||
|
"\"{}\" != \"{}\"",
|
||||||
|
$template,
|
||||||
|
$s
|
||||||
|
);
|
||||||
|
}};
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_mktemp_mktemp() {
|
fn test_mktemp_mktemp() {
|
||||||
let scene = TestScenario::new(util_name!());
|
let scene = TestScenario::new(util_name!());
|
||||||
|
@ -417,6 +429,21 @@ fn test_mktemp_directory_tmpdir() {
|
||||||
assert!(PathBuf::from(result.stdout_str().trim()).is_dir());
|
assert!(PathBuf::from(result.stdout_str().trim()).is_dir());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Test for combining `--tmpdir` and a template with a subdirectory.
|
||||||
|
#[test]
|
||||||
|
fn test_tmpdir_template_has_subdirectory() {
|
||||||
|
let (at, mut ucmd) = at_and_ucmd!();
|
||||||
|
at.mkdir("a");
|
||||||
|
#[cfg(not(windows))]
|
||||||
|
let (template, joined) = ("a/bXXXX", "./a/bXXXX");
|
||||||
|
#[cfg(windows)]
|
||||||
|
let (template, joined) = (r"a\bXXXX", r".\a\bXXXX");
|
||||||
|
let result = ucmd.args(&["--tmpdir=.", template]).succeeds();
|
||||||
|
let filename = result.no_stderr().stdout_str().trim_end();
|
||||||
|
assert_matches_template!(joined, filename);
|
||||||
|
assert!(at.file_exists(filename));
|
||||||
|
}
|
||||||
|
|
||||||
/// Test that an absolute path is disallowed when --tmpdir is provided.
|
/// Test that an absolute path is disallowed when --tmpdir is provided.
|
||||||
#[test]
|
#[test]
|
||||||
fn test_tmpdir_absolute_path() {
|
fn test_tmpdir_absolute_path() {
|
||||||
|
@ -466,18 +493,6 @@ fn matches_template(template: &str, s: &str) -> bool {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
/// An assertion that uses [`matches_template`] and adds a helpful error message.
|
|
||||||
macro_rules! assert_matches_template {
|
|
||||||
($template:expr, $s:expr) => {{
|
|
||||||
assert!(
|
|
||||||
matches_template($template, $s),
|
|
||||||
"\"{}\" != \"{}\"",
|
|
||||||
$template,
|
|
||||||
$s
|
|
||||||
);
|
|
||||||
}};
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Test that the file is created in the directory given by the template.
|
/// Test that the file is created in the directory given by the template.
|
||||||
#[test]
|
#[test]
|
||||||
fn test_respect_template() {
|
fn test_respect_template() {
|
||||||
|
@ -550,6 +565,16 @@ fn test_suffix_path_separator() {
|
||||||
.arg(r"aXXX\b")
|
.arg(r"aXXX\b")
|
||||||
.fails()
|
.fails()
|
||||||
.stderr_only("mktemp: invalid suffix '\\b', contains directory separator\n");
|
.stderr_only("mktemp: invalid suffix '\\b', contains directory separator\n");
|
||||||
|
#[cfg(not(windows))]
|
||||||
|
new_ucmd!()
|
||||||
|
.arg("XXX/..")
|
||||||
|
.fails()
|
||||||
|
.stderr_only("mktemp: invalid suffix '/..', contains directory separator\n");
|
||||||
|
#[cfg(windows)]
|
||||||
|
new_ucmd!()
|
||||||
|
.arg(r"XXX\..")
|
||||||
|
.fails()
|
||||||
|
.stderr_only("mktemp: invalid suffix '\\..', contains directory separator\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue