summaryrefslogtreecommitdiffstats
path: root/vendor/tempfile/tests
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/tempfile/tests')
-rw-r--r--vendor/tempfile/tests/namedtempfile.rs7
-rw-r--r--vendor/tempfile/tests/spooled.rs32
-rw-r--r--vendor/tempfile/tests/tempdir.rs139
3 files changed, 50 insertions, 128 deletions
diff --git a/vendor/tempfile/tests/namedtempfile.rs b/vendor/tempfile/tests/namedtempfile.rs
index 54396c3ac..4b940b6b8 100644
--- a/vendor/tempfile/tests/namedtempfile.rs
+++ b/vendor/tempfile/tests/namedtempfile.rs
@@ -12,6 +12,13 @@ fn exists<P: AsRef<Path>>(path: P) -> bool {
}
#[test]
+fn test_prefix() {
+ let tmpfile = NamedTempFile::with_prefix("prefix").unwrap();
+ let name = tmpfile.path().file_name().unwrap().to_str().unwrap();
+ assert!(name.starts_with("prefix"));
+}
+
+#[test]
fn test_basic() {
let mut tmpfile = NamedTempFile::new().unwrap();
write!(tmpfile, "abcde").unwrap();
diff --git a/vendor/tempfile/tests/spooled.rs b/vendor/tempfile/tests/spooled.rs
index 288d1e6ee..a3bcc03d8 100644
--- a/vendor/tempfile/tests/spooled.rs
+++ b/vendor/tempfile/tests/spooled.rs
@@ -10,7 +10,7 @@ fn test_automatic_rollover() {
let mut buf = Vec::new();
assert!(!t.is_rolled());
- assert_eq!(t.seek(SeekFrom::Current(0)).unwrap(), 0);
+ assert_eq!(t.stream_position().unwrap(), 0);
assert_eq!(t.read_to_end(&mut buf).unwrap(), 0);
assert_eq!(buf.as_slice(), b"");
buf.clear();
@@ -24,7 +24,7 @@ fn test_automatic_rollover() {
assert_eq!(t.write(b"fghijklmno").unwrap(), 10);
- assert_eq!(t.seek(SeekFrom::Current(0)).unwrap(), 15);
+ assert_eq!(t.stream_position().unwrap(), 15);
assert!(t.is_rolled());
}
@@ -32,13 +32,13 @@ fn test_automatic_rollover() {
fn test_explicit_rollover() {
let mut t = SpooledTempFile::new(100);
assert_eq!(t.write(b"abcdefghijklmnopqrstuvwxyz").unwrap(), 26);
- assert_eq!(t.seek(SeekFrom::Current(0)).unwrap(), 26);
+ assert_eq!(t.stream_position().unwrap(), 26);
assert!(!t.is_rolled());
// roll over explicitly
assert!(t.roll().is_ok());
assert!(t.is_rolled());
- assert_eq!(t.seek(SeekFrom::Current(0)).unwrap(), 26);
+ assert_eq!(t.stream_position().unwrap(), 26);
let mut buf = Vec::new();
assert_eq!(t.read_to_end(&mut buf).unwrap(), 0);
@@ -48,7 +48,7 @@ fn test_explicit_rollover() {
assert_eq!(t.seek(SeekFrom::Start(0)).unwrap(), 0);
assert_eq!(t.read_to_end(&mut buf).unwrap(), 26);
assert_eq!(buf.as_slice(), b"abcdefghijklmnopqrstuvwxyz");
- assert_eq!(t.seek(SeekFrom::Current(0)).unwrap(), 26);
+ assert_eq!(t.stream_position().unwrap(), 26);
}
// called by test_seek_{buffer, file}
@@ -56,7 +56,7 @@ fn test_explicit_rollover() {
fn test_seek(t: &mut SpooledTempFile) {
assert_eq!(t.write(b"abcdefghijklmnopqrstuvwxyz").unwrap(), 26);
- assert_eq!(t.seek(SeekFrom::Current(0)).unwrap(), 26); // tell()
+ assert_eq!(t.stream_position().unwrap(), 26); // tell()
assert_eq!(t.seek(SeekFrom::Current(-1)).unwrap(), 25);
assert_eq!(t.seek(SeekFrom::Current(1)).unwrap(), 26);
assert_eq!(t.seek(SeekFrom::Current(1)).unwrap(), 27);
@@ -110,7 +110,7 @@ fn test_seek_read(t: &mut SpooledTempFile) {
buf.clear();
// now we're at the end again
- assert_eq!(t.seek(SeekFrom::Current(0)).unwrap(), 26); // tell()
+ assert_eq!(t.stream_position().unwrap(), 26); // tell()
assert_eq!(t.read_to_end(&mut buf).unwrap(), 0);
assert_eq!(buf.as_slice(), b"");
buf.clear();
@@ -122,7 +122,7 @@ fn test_seek_read(t: &mut SpooledTempFile) {
assert_eq!(buf, *b"fghij");
// read again from current spot
- assert_eq!(t.seek(SeekFrom::Current(0)).unwrap(), 10); // tell()
+ assert_eq!(t.stream_position().unwrap(), 10); // tell()
assert!(t.read_exact(&mut buf).is_ok());
assert_eq!(buf, *b"klmno");
@@ -190,11 +190,11 @@ fn test_overwrite_and_extend_rollover() {
assert_eq!(t.write(b"abcdefghijklmno").unwrap(), 15);
assert!(!t.is_rolled());
assert_eq!(t.seek(SeekFrom::End(-5)).unwrap(), 10);
- assert_eq!(t.seek(SeekFrom::Current(0)).unwrap(), 10); // tell()
+ assert_eq!(t.stream_position().unwrap(), 10); // tell()
assert!(!t.is_rolled());
assert_eq!(t.write(b"0123456789)!@#$%^&*(").unwrap(), 20);
assert!(t.is_rolled());
- assert_eq!(t.seek(SeekFrom::Current(0)).unwrap(), 30); // tell()
+ assert_eq!(t.stream_position().unwrap(), 30); // tell()
let mut buf = Vec::new();
assert_eq!(t.seek(SeekFrom::Start(0)).unwrap(), 0);
assert_eq!(t.read_to_end(&mut buf).unwrap(), 30);
@@ -247,11 +247,11 @@ fn test_set_len(t: &mut SpooledTempFile) {
assert!(t.set_len(10).is_ok());
// position should not have moved
- assert_eq!(t.seek(SeekFrom::Current(0)).unwrap(), 26); // tell()
+ assert_eq!(t.stream_position().unwrap(), 26); // tell()
assert_eq!(t.read_to_end(&mut buf).unwrap(), 0);
assert_eq!(buf.as_slice(), b"");
- assert_eq!(t.seek(SeekFrom::Current(0)).unwrap(), 26); // tell()
+ assert_eq!(t.stream_position().unwrap(), 26); // tell()
buf.clear();
// read whole thing
@@ -262,7 +262,7 @@ fn test_set_len(t: &mut SpooledTempFile) {
// set_len to expand beyond the end
assert!(t.set_len(40).is_ok());
- assert_eq!(t.seek(SeekFrom::Current(0)).unwrap(), 10); // tell()
+ assert_eq!(t.stream_position().unwrap(), 10); // tell()
assert_eq!(t.seek(SeekFrom::Start(0)).unwrap(), 0);
assert_eq!(t.read_to_end(&mut buf).unwrap(), 40);
assert_eq!(
@@ -290,17 +290,17 @@ fn test_set_len_rollover() {
let mut t = spooled_tempfile(10);
assert_eq!(t.write(b"abcde").unwrap(), 5);
assert!(!t.is_rolled());
- assert_eq!(t.seek(SeekFrom::Current(0)).unwrap(), 5); // tell()
+ assert_eq!(t.stream_position().unwrap(), 5); // tell()
assert_eq!(t.seek(SeekFrom::Start(0)).unwrap(), 0);
assert_eq!(t.read_to_end(&mut buf).unwrap(), 5);
assert_eq!(buf.as_slice(), b"abcde");
- assert_eq!(t.seek(SeekFrom::Current(0)).unwrap(), 5); // tell()
+ assert_eq!(t.stream_position().unwrap(), 5); // tell()
buf.clear();
assert!(t.set_len(20).is_ok());
assert!(t.is_rolled());
- assert_eq!(t.seek(SeekFrom::Current(0)).unwrap(), 5); // tell()
+ assert_eq!(t.stream_position().unwrap(), 5); // tell()
assert_eq!(t.seek(SeekFrom::Start(0)).unwrap(), 0);
assert_eq!(t.read_to_end(&mut buf).unwrap(), 20);
assert_eq!(buf.as_slice(), b"abcde\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0");
diff --git a/vendor/tempfile/tests/tempdir.rs b/vendor/tempfile/tests/tempdir.rs
index de9723328..8ca7984ac 100644
--- a/vendor/tempfile/tests/tempdir.rs
+++ b/vendor/tempfile/tests/tempdir.rs
@@ -18,32 +18,9 @@ use std::thread;
use tempfile::{Builder, TempDir};
-macro_rules! t {
- ($e:expr) => {
- match $e {
- Ok(n) => n,
- Err(e) => panic!("error: {}", e),
- }
- };
-}
-
-trait PathExt {
- fn exists(&self) -> bool;
- fn is_dir(&self) -> bool;
-}
-
-impl PathExt for Path {
- fn exists(&self) -> bool {
- fs::metadata(self).is_ok()
- }
- fn is_dir(&self) -> bool {
- fs::metadata(self).map(|m| m.is_dir()).unwrap_or(false)
- }
-}
-
fn test_tempdir() {
let path = {
- let p = t!(Builder::new().prefix("foobar").tempdir_in(&Path::new(".")));
+ let p = Builder::new().prefix("foobar").tempdir_in(".").unwrap();
let p = p.path();
assert!(p.to_str().unwrap().contains("foobar"));
p.to_path_buf()
@@ -51,7 +28,12 @@ fn test_tempdir() {
assert!(!path.exists());
}
-#[test]
+fn test_prefix() {
+ let tmpfile = TempDir::with_prefix_in("prefix", ".").unwrap();
+ let name = tmpfile.path().file_name().unwrap().to_str().unwrap();
+ assert!(name.starts_with("prefix"));
+}
+
fn test_customnamed() {
let tmpfile = Builder::new()
.prefix("prefix")
@@ -68,7 +50,7 @@ fn test_customnamed() {
fn test_rm_tempdir() {
let (tx, rx) = channel();
let f = move || {
- let tmp = t!(TempDir::new());
+ let tmp = TempDir::new().unwrap();
tx.send(tmp.path().to_path_buf()).unwrap();
panic!("panic to unwind past `tmp`");
};
@@ -76,7 +58,7 @@ fn test_rm_tempdir() {
let path = rx.recv().unwrap();
assert!(!path.exists());
- let tmp = t!(TempDir::new());
+ let tmp = TempDir::new().unwrap();
let path = tmp.path().to_path_buf();
let f = move || {
let _tmp = tmp;
@@ -87,7 +69,7 @@ fn test_rm_tempdir() {
let path;
{
- let f = move || t!(TempDir::new());
+ let f = move || TempDir::new().unwrap();
let tmp = thread::spawn(f).join().unwrap();
path = tmp.path().to_path_buf();
@@ -97,31 +79,31 @@ fn test_rm_tempdir() {
let path;
{
- let tmp = t!(TempDir::new());
+ let tmp = TempDir::new().unwrap();
path = tmp.into_path();
}
assert!(path.exists());
- t!(fs::remove_dir_all(&path));
+ fs::remove_dir_all(&path).unwrap();
assert!(!path.exists());
}
fn test_rm_tempdir_close() {
let (tx, rx) = channel();
let f = move || {
- let tmp = t!(TempDir::new());
+ let tmp = TempDir::new().unwrap();
tx.send(tmp.path().to_path_buf()).unwrap();
- t!(tmp.close());
+ tmp.close().unwrap();
panic!("panic when unwinding past `tmp`");
};
let _ = thread::spawn(f).join();
let path = rx.recv().unwrap();
assert!(!path.exists());
- let tmp = t!(TempDir::new());
+ let tmp = TempDir::new().unwrap();
let path = tmp.path().to_path_buf();
let f = move || {
let tmp = tmp;
- t!(tmp.close());
+ tmp.close().unwrap();
panic!("panic when unwinding past `tmp`");
};
let _ = thread::spawn(f).join();
@@ -129,96 +111,31 @@ fn test_rm_tempdir_close() {
let path;
{
- let f = move || t!(TempDir::new());
+ let f = move || TempDir::new().unwrap();
let tmp = thread::spawn(f).join().unwrap();
path = tmp.path().to_path_buf();
assert!(path.exists());
- t!(tmp.close());
+ tmp.close().unwrap();
}
assert!(!path.exists());
let path;
{
- let tmp = t!(TempDir::new());
+ let tmp = TempDir::new().unwrap();
path = tmp.into_path();
}
assert!(path.exists());
- t!(fs::remove_dir_all(&path));
+ fs::remove_dir_all(&path).unwrap();
assert!(!path.exists());
}
-// Ideally these would be in std::os but then core would need
-// to depend on std
-fn recursive_mkdir_rel() {
- let path = Path::new("frob");
- let cwd = env::current_dir().unwrap();
- println!(
- "recursive_mkdir_rel: Making: {} in cwd {} [{}]",
- path.display(),
- cwd.display(),
- path.exists()
- );
- t!(fs::create_dir(&path));
- assert!(path.is_dir());
- t!(fs::create_dir_all(&path));
- assert!(path.is_dir());
-}
-
-fn recursive_mkdir_dot() {
- let dot = Path::new(".");
- t!(fs::create_dir_all(&dot));
- let dotdot = Path::new("..");
- t!(fs::create_dir_all(&dotdot));
-}
-
-fn recursive_mkdir_rel_2() {
- let path = Path::new("./frob/baz");
- let cwd = env::current_dir().unwrap();
- println!(
- "recursive_mkdir_rel_2: Making: {} in cwd {} [{}]",
- path.display(),
- cwd.display(),
- path.exists()
- );
- t!(fs::create_dir_all(&path));
- assert!(path.is_dir());
- assert!(path.parent().unwrap().is_dir());
- let path2 = Path::new("quux/blat");
- println!(
- "recursive_mkdir_rel_2: Making: {} in cwd {}",
- path2.display(),
- cwd.display()
- );
- t!(fs::create_dir("quux"));
- t!(fs::create_dir_all(&path2));
- assert!(path2.is_dir());
- assert!(path2.parent().unwrap().is_dir());
-}
-
-// Ideally this would be in core, but needs TempFile
-pub fn test_remove_dir_all_ok() {
- let tmpdir = t!(TempDir::new());
- let tmpdir = tmpdir.path();
- let root = tmpdir.join("foo");
-
- println!("making {}", root.display());
- t!(fs::create_dir(&root));
- t!(fs::create_dir(&root.join("foo")));
- t!(fs::create_dir(&root.join("foo").join("bar")));
- t!(fs::create_dir(&root.join("foo").join("bar").join("blat")));
- t!(fs::remove_dir_all(&root));
- assert!(!root.exists());
- assert!(!root.join("bar").exists());
- assert!(!root.join("bar").join("blat").exists());
-}
-
-pub fn dont_double_panic() {
+fn dont_double_panic() {
let r: Result<(), _> = thread::spawn(move || {
let tmpdir = TempDir::new().unwrap();
// Remove the temporary directory so that TempDir sees
// an error on drop
- t!(fs::remove_dir(tmpdir.path()));
+ fs::remove_dir(tmpdir.path()).unwrap();
// Panic. If TempDir panics *again* due to the rmdir
// error then the process will abort.
panic!();
@@ -231,14 +148,14 @@ fn in_tmpdir<F>(f: F)
where
F: FnOnce(),
{
- let tmpdir = t!(TempDir::new());
+ let tmpdir = TempDir::new().unwrap();
assert!(env::set_current_dir(tmpdir.path()).is_ok());
f();
}
-pub fn pass_as_asref_path() {
- let tempdir = t!(TempDir::new());
+fn pass_as_asref_path() {
+ let tempdir = TempDir::new().unwrap();
takes_asref_path(&tempdir);
fn takes_asref_path<T: AsRef<Path>>(path: T) {
@@ -250,12 +167,10 @@ pub fn pass_as_asref_path() {
#[test]
fn main() {
in_tmpdir(test_tempdir);
+ in_tmpdir(test_prefix);
+ in_tmpdir(test_customnamed);
in_tmpdir(test_rm_tempdir);
in_tmpdir(test_rm_tempdir_close);
- in_tmpdir(recursive_mkdir_rel);
- in_tmpdir(recursive_mkdir_dot);
- in_tmpdir(recursive_mkdir_rel_2);
- in_tmpdir(test_remove_dir_all_ok);
in_tmpdir(dont_double_panic);
in_tmpdir(pass_as_asref_path);
}