2016-01-03 10:10:47 +00:00
|
|
|
use common::util::*;
|
2016-08-06 03:18:34 +00:00
|
|
|
extern crate tempdir;
|
|
|
|
use self::tempdir::TempDir;
|
2016-01-03 10:10:47 +00:00
|
|
|
|
|
|
|
static TEST_TEMPLATE1: &'static str = "tempXXXXXX";
|
|
|
|
static TEST_TEMPLATE2: &'static str = "temp";
|
|
|
|
static TEST_TEMPLATE3: &'static str = "tempX";
|
|
|
|
static TEST_TEMPLATE4: &'static str = "tempXX";
|
|
|
|
static TEST_TEMPLATE5: &'static str = "tempXXX";
|
|
|
|
static TEST_TEMPLATE6: &'static str = "tempXXXlate";
|
|
|
|
static TEST_TEMPLATE7: &'static str = "XXXtemplate";
|
|
|
|
#[cfg(unix)]
|
|
|
|
static TEST_TEMPLATE8: &'static str = "tempXXXla/te";
|
|
|
|
#[cfg(windows)]
|
|
|
|
static TEST_TEMPLATE8: &'static str = "tempXXXla\\te";
|
|
|
|
|
|
|
|
const TMPDIR: &'static str = "TMPDIR";
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_mktemp_mktemp() {
|
2016-08-23 11:52:43 +00:00
|
|
|
let scene = TestScenario::new(util_name!());
|
2016-01-03 10:10:47 +00:00
|
|
|
|
2016-07-29 21:26:32 +00:00
|
|
|
let pathname = scene.fixtures.as_string();
|
2016-01-03 10:10:47 +00:00
|
|
|
|
2020-04-13 18:36:03 +00:00
|
|
|
scene
|
|
|
|
.ucmd()
|
|
|
|
.env(TMPDIR, &pathname)
|
|
|
|
.arg(TEST_TEMPLATE1)
|
|
|
|
.succeeds();
|
|
|
|
scene
|
|
|
|
.ucmd()
|
|
|
|
.env(TMPDIR, &pathname)
|
|
|
|
.arg(TEST_TEMPLATE2)
|
|
|
|
.fails();
|
|
|
|
scene
|
|
|
|
.ucmd()
|
|
|
|
.env(TMPDIR, &pathname)
|
|
|
|
.arg(TEST_TEMPLATE3)
|
|
|
|
.fails();
|
|
|
|
scene
|
|
|
|
.ucmd()
|
|
|
|
.env(TMPDIR, &pathname)
|
|
|
|
.arg(TEST_TEMPLATE4)
|
|
|
|
.fails();
|
|
|
|
scene
|
|
|
|
.ucmd()
|
|
|
|
.env(TMPDIR, &pathname)
|
|
|
|
.arg(TEST_TEMPLATE5)
|
|
|
|
.succeeds();
|
|
|
|
scene
|
|
|
|
.ucmd()
|
|
|
|
.env(TMPDIR, &pathname)
|
|
|
|
.arg(TEST_TEMPLATE6)
|
|
|
|
.succeeds();
|
|
|
|
scene
|
|
|
|
.ucmd()
|
|
|
|
.env(TMPDIR, &pathname)
|
|
|
|
.arg(TEST_TEMPLATE7)
|
|
|
|
.succeeds();
|
|
|
|
scene
|
|
|
|
.ucmd()
|
|
|
|
.env(TMPDIR, &pathname)
|
|
|
|
.arg(TEST_TEMPLATE8)
|
|
|
|
.fails();
|
2016-01-03 10:10:47 +00:00
|
|
|
}
|
|
|
|
|
2016-06-18 09:44:07 +00:00
|
|
|
#[test]
|
|
|
|
fn test_mktemp_make_temp_dir() {
|
2016-08-23 11:52:43 +00:00
|
|
|
let scene = TestScenario::new(util_name!());
|
2016-06-18 09:44:07 +00:00
|
|
|
|
2016-07-29 21:26:32 +00:00
|
|
|
let pathname = scene.fixtures.as_string();
|
2016-06-18 09:44:07 +00:00
|
|
|
|
2020-04-13 18:36:03 +00:00
|
|
|
scene
|
|
|
|
.ucmd()
|
|
|
|
.env(TMPDIR, &pathname)
|
|
|
|
.arg("-d")
|
|
|
|
.arg(TEST_TEMPLATE1)
|
|
|
|
.succeeds();
|
|
|
|
scene
|
|
|
|
.ucmd()
|
|
|
|
.env(TMPDIR, &pathname)
|
|
|
|
.arg("-d")
|
|
|
|
.arg(TEST_TEMPLATE2)
|
|
|
|
.fails();
|
|
|
|
scene
|
|
|
|
.ucmd()
|
|
|
|
.env(TMPDIR, &pathname)
|
|
|
|
.arg("-d")
|
|
|
|
.arg(TEST_TEMPLATE3)
|
|
|
|
.fails();
|
|
|
|
scene
|
|
|
|
.ucmd()
|
|
|
|
.env(TMPDIR, &pathname)
|
|
|
|
.arg("-d")
|
|
|
|
.arg(TEST_TEMPLATE4)
|
|
|
|
.fails();
|
|
|
|
scene
|
|
|
|
.ucmd()
|
|
|
|
.env(TMPDIR, &pathname)
|
|
|
|
.arg("-d")
|
|
|
|
.arg(TEST_TEMPLATE5)
|
|
|
|
.succeeds();
|
|
|
|
scene
|
|
|
|
.ucmd()
|
|
|
|
.env(TMPDIR, &pathname)
|
|
|
|
.arg("-d")
|
|
|
|
.arg(TEST_TEMPLATE6)
|
|
|
|
.succeeds();
|
|
|
|
scene
|
|
|
|
.ucmd()
|
|
|
|
.env(TMPDIR, &pathname)
|
|
|
|
.arg("-d")
|
|
|
|
.arg(TEST_TEMPLATE7)
|
|
|
|
.succeeds();
|
|
|
|
scene
|
|
|
|
.ucmd()
|
|
|
|
.env(TMPDIR, &pathname)
|
|
|
|
.arg("-d")
|
|
|
|
.arg(TEST_TEMPLATE8)
|
|
|
|
.fails();
|
2016-06-18 09:44:07 +00:00
|
|
|
}
|
2016-01-03 17:11:15 +00:00
|
|
|
|
2016-01-03 10:10:47 +00:00
|
|
|
#[test]
|
|
|
|
fn test_mktemp_dry_run() {
|
2016-08-23 11:52:43 +00:00
|
|
|
let scene = TestScenario::new(util_name!());
|
2016-01-03 10:10:47 +00:00
|
|
|
|
2016-07-29 21:26:32 +00:00
|
|
|
let pathname = scene.fixtures.as_string();
|
2016-01-03 10:10:47 +00:00
|
|
|
|
2020-04-13 18:36:03 +00:00
|
|
|
scene
|
|
|
|
.ucmd()
|
|
|
|
.env(TMPDIR, &pathname)
|
|
|
|
.arg("-u")
|
|
|
|
.arg(TEST_TEMPLATE1)
|
|
|
|
.succeeds();
|
|
|
|
scene
|
|
|
|
.ucmd()
|
|
|
|
.env(TMPDIR, &pathname)
|
|
|
|
.arg("-u")
|
|
|
|
.arg(TEST_TEMPLATE2)
|
|
|
|
.fails();
|
|
|
|
scene
|
|
|
|
.ucmd()
|
|
|
|
.env(TMPDIR, &pathname)
|
|
|
|
.arg("-u")
|
|
|
|
.arg(TEST_TEMPLATE3)
|
|
|
|
.fails();
|
|
|
|
scene
|
|
|
|
.ucmd()
|
|
|
|
.env(TMPDIR, &pathname)
|
|
|
|
.arg("-u")
|
|
|
|
.arg(TEST_TEMPLATE4)
|
|
|
|
.fails();
|
|
|
|
scene
|
|
|
|
.ucmd()
|
|
|
|
.env(TMPDIR, &pathname)
|
|
|
|
.arg("-u")
|
|
|
|
.arg(TEST_TEMPLATE5)
|
|
|
|
.succeeds();
|
|
|
|
scene
|
|
|
|
.ucmd()
|
|
|
|
.env(TMPDIR, &pathname)
|
|
|
|
.arg("-u")
|
|
|
|
.arg(TEST_TEMPLATE6)
|
|
|
|
.succeeds();
|
|
|
|
scene
|
|
|
|
.ucmd()
|
|
|
|
.env(TMPDIR, &pathname)
|
|
|
|
.arg("-u")
|
|
|
|
.arg(TEST_TEMPLATE7)
|
|
|
|
.succeeds();
|
|
|
|
scene
|
|
|
|
.ucmd()
|
|
|
|
.env(TMPDIR, &pathname)
|
|
|
|
.arg("-u")
|
|
|
|
.arg(TEST_TEMPLATE8)
|
|
|
|
.fails();
|
2016-01-03 10:10:47 +00:00
|
|
|
}
|
|
|
|
|
2016-06-18 09:44:07 +00:00
|
|
|
#[test]
|
|
|
|
fn test_mktemp_quiet() {
|
2016-08-23 11:52:43 +00:00
|
|
|
let scene = TestScenario::new(util_name!());
|
2016-06-18 09:44:07 +00:00
|
|
|
|
2020-04-13 18:36:03 +00:00
|
|
|
scene
|
|
|
|
.ucmd()
|
|
|
|
.arg("-p")
|
|
|
|
.arg("/definitely/not/exist/I/promise")
|
|
|
|
.arg("-q")
|
|
|
|
.fails()
|
|
|
|
.no_stdout()
|
|
|
|
.no_stderr();
|
|
|
|
scene
|
|
|
|
.ucmd()
|
|
|
|
.arg("-d")
|
|
|
|
.arg("-p")
|
|
|
|
.arg("/definitely/not/exist/I/promise")
|
|
|
|
.arg("-q")
|
|
|
|
.fails()
|
|
|
|
.no_stdout()
|
|
|
|
.no_stderr();
|
2016-06-18 09:44:07 +00:00
|
|
|
}
|
2016-01-03 10:10:47 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_mktemp_suffix() {
|
2016-08-23 11:52:43 +00:00
|
|
|
let scene = TestScenario::new(util_name!());
|
2016-01-03 10:10:47 +00:00
|
|
|
|
2016-07-29 21:26:32 +00:00
|
|
|
let pathname = scene.fixtures.as_string();
|
2016-01-03 17:11:15 +00:00
|
|
|
|
2020-04-13 18:36:03 +00:00
|
|
|
scene
|
|
|
|
.ucmd()
|
|
|
|
.env(TMPDIR, &pathname)
|
|
|
|
.arg("--suffix")
|
|
|
|
.arg("suf")
|
|
|
|
.arg(TEST_TEMPLATE1)
|
|
|
|
.succeeds();
|
|
|
|
scene
|
|
|
|
.ucmd()
|
|
|
|
.env(TMPDIR, &pathname)
|
|
|
|
.arg("--suffix")
|
|
|
|
.arg("suf")
|
|
|
|
.arg(TEST_TEMPLATE2)
|
|
|
|
.fails();
|
|
|
|
scene
|
|
|
|
.ucmd()
|
|
|
|
.env(TMPDIR, &pathname)
|
|
|
|
.arg("--suffix")
|
|
|
|
.arg("suf")
|
|
|
|
.arg(TEST_TEMPLATE3)
|
|
|
|
.fails();
|
|
|
|
scene
|
|
|
|
.ucmd()
|
|
|
|
.env(TMPDIR, &pathname)
|
|
|
|
.arg("--suffix")
|
|
|
|
.arg("suf")
|
|
|
|
.arg(TEST_TEMPLATE4)
|
|
|
|
.fails();
|
|
|
|
scene
|
|
|
|
.ucmd()
|
|
|
|
.env(TMPDIR, &pathname)
|
|
|
|
.arg("--suffix")
|
|
|
|
.arg("suf")
|
|
|
|
.arg(TEST_TEMPLATE5)
|
|
|
|
.succeeds();
|
|
|
|
scene
|
|
|
|
.ucmd()
|
|
|
|
.env(TMPDIR, &pathname)
|
|
|
|
.arg("--suffix")
|
|
|
|
.arg("suf")
|
|
|
|
.arg(TEST_TEMPLATE6)
|
|
|
|
.fails();
|
|
|
|
scene
|
|
|
|
.ucmd()
|
|
|
|
.env(TMPDIR, &pathname)
|
|
|
|
.arg("--suffix")
|
|
|
|
.arg("suf")
|
|
|
|
.arg(TEST_TEMPLATE7)
|
|
|
|
.fails();
|
|
|
|
scene
|
|
|
|
.ucmd()
|
|
|
|
.env(TMPDIR, &pathname)
|
|
|
|
.arg("--suffix")
|
|
|
|
.arg("suf")
|
|
|
|
.arg(TEST_TEMPLATE8)
|
|
|
|
.fails();
|
2016-01-03 10:10:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_mktemp_tmpdir() {
|
2016-08-23 11:52:43 +00:00
|
|
|
let scene = TestScenario::new(util_name!());
|
2016-01-03 10:10:47 +00:00
|
|
|
|
2016-08-23 11:52:43 +00:00
|
|
|
let path = TempDir::new_in(scene.fixtures.as_string(), util_name!()).unwrap();
|
2016-08-13 21:59:21 +00:00
|
|
|
let pathname = path.path().as_os_str();
|
|
|
|
|
2020-04-13 18:36:03 +00:00
|
|
|
scene
|
|
|
|
.ucmd()
|
|
|
|
.arg("-p")
|
|
|
|
.arg(pathname)
|
|
|
|
.arg(TEST_TEMPLATE1)
|
|
|
|
.succeeds();
|
|
|
|
scene
|
|
|
|
.ucmd()
|
|
|
|
.arg("-p")
|
|
|
|
.arg(pathname)
|
|
|
|
.arg(TEST_TEMPLATE2)
|
|
|
|
.fails();
|
|
|
|
scene
|
|
|
|
.ucmd()
|
|
|
|
.arg("-p")
|
|
|
|
.arg(pathname)
|
|
|
|
.arg(TEST_TEMPLATE3)
|
|
|
|
.fails();
|
|
|
|
scene
|
|
|
|
.ucmd()
|
|
|
|
.arg("-p")
|
|
|
|
.arg(pathname)
|
|
|
|
.arg(TEST_TEMPLATE4)
|
|
|
|
.fails();
|
|
|
|
scene
|
|
|
|
.ucmd()
|
|
|
|
.arg("-p")
|
|
|
|
.arg(pathname)
|
|
|
|
.arg(TEST_TEMPLATE5)
|
|
|
|
.succeeds();
|
|
|
|
scene
|
|
|
|
.ucmd()
|
|
|
|
.arg("-p")
|
|
|
|
.arg(pathname)
|
|
|
|
.arg(TEST_TEMPLATE6)
|
|
|
|
.succeeds();
|
|
|
|
scene
|
|
|
|
.ucmd()
|
|
|
|
.arg("-p")
|
|
|
|
.arg(pathname)
|
|
|
|
.arg(TEST_TEMPLATE7)
|
|
|
|
.succeeds();
|
|
|
|
scene
|
|
|
|
.ucmd()
|
|
|
|
.arg("-p")
|
|
|
|
.arg(pathname)
|
|
|
|
.arg(TEST_TEMPLATE8)
|
|
|
|
.fails();
|
2016-01-03 10:10:47 +00:00
|
|
|
}
|