summaryrefslogtreecommitdiffstats
path: root/vendor/tempfile/tests
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:18:32 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:18:32 +0000
commit4547b622d8d29df964fa2914213088b148c498fc (patch)
tree9fc6b25f3c3add6b745be9a2400a6e96140046e9 /vendor/tempfile/tests
parentReleasing progress-linux version 1.66.0+dfsg1-1~progress7.99u1. (diff)
downloadrustc-4547b622d8d29df964fa2914213088b148c498fc.tar.xz
rustc-4547b622d8d29df964fa2914213088b148c498fc.zip
Merging upstream version 1.67.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/tempfile/tests')
-rw-r--r--vendor/tempfile/tests/namedtempfile.rs49
-rw-r--r--vendor/tempfile/tests/tempfile.rs2
2 files changed, 49 insertions, 2 deletions
diff --git a/vendor/tempfile/tests/namedtempfile.rs b/vendor/tempfile/tests/namedtempfile.rs
index a489d56db..d2c7da22b 100644
--- a/vendor/tempfile/tests/namedtempfile.rs
+++ b/vendor/tempfile/tests/namedtempfile.rs
@@ -1,10 +1,11 @@
#![deny(rust_2018_idioms)]
use std::env;
+use std::ffi::{OsStr, OsString};
use std::fs::File;
use std::io::{Read, Seek, SeekFrom, Write};
-use std::path::Path;
-use tempfile::{Builder, NamedTempFile};
+use std::path::{Path, PathBuf};
+use tempfile::{tempdir, Builder, NamedTempFile, TempPath};
fn exists<P: AsRef<Path>>(path: P) -> bool {
std::fs::metadata(path.as_ref()).is_ok()
@@ -217,6 +218,50 @@ fn test_temppath_persist_noclobber() {
}
#[test]
+fn temp_path_from_existing() {
+ let tmp_dir = tempdir().unwrap();
+ let tmp_file_path_1 = tmp_dir.path().join("testfile1");
+ let tmp_file_path_2 = tmp_dir.path().join("testfile2");
+
+ File::create(&tmp_file_path_1).unwrap();
+ assert!(tmp_file_path_1.exists(), "Test file 1 hasn't been created");
+
+ File::create(&tmp_file_path_2).unwrap();
+ assert!(tmp_file_path_2.exists(), "Test file 2 hasn't been created");
+
+ let tmp_path = TempPath::from_path(&tmp_file_path_1);
+ assert!(
+ tmp_file_path_1.exists(),
+ "Test file has been deleted before dropping TempPath"
+ );
+
+ drop(tmp_path);
+ assert!(
+ !tmp_file_path_1.exists(),
+ "Test file exists after dropping TempPath"
+ );
+ assert!(
+ tmp_file_path_2.exists(),
+ "Test file 2 has been deleted before dropping TempDir"
+ );
+}
+
+#[test]
+#[allow(unreachable_code)]
+fn temp_path_from_argument_types() {
+ // This just has to compile
+ return;
+
+ TempPath::from_path("");
+ TempPath::from_path(String::new());
+ TempPath::from_path(OsStr::new(""));
+ TempPath::from_path(OsString::new());
+ TempPath::from_path(Path::new(""));
+ TempPath::from_path(PathBuf::new());
+ TempPath::from_path(PathBuf::new().into_boxed_path());
+}
+
+#[test]
fn test_write_after_close() {
let path = NamedTempFile::new().unwrap().into_temp_path();
File::create(path).unwrap().write_all(b"test").unwrap();
diff --git a/vendor/tempfile/tests/tempfile.rs b/vendor/tempfile/tests/tempfile.rs
index 065dccbe1..f4dddb290 100644
--- a/vendor/tempfile/tests/tempfile.rs
+++ b/vendor/tempfile/tests/tempfile.rs
@@ -26,6 +26,8 @@ fn test_cleanup() {
assert!(num_files == 0);
}
+// Only run this test on Linux. MacOS doesn't like us creating so many files, apparently.
+#[cfg(target_os = "linux")]
#[test]
fn test_pathological_cleaner() {
let tmpdir = tempfile::tempdir().unwrap();