Unified · Split
| @@ -1,7 +1,8 @@ | ||
| 1 | 1 | mod convert { |
| 2 | 2 | use bstr::ByteSlice; |
| 3 | 3 | use git_path::{real_path, to_unix_separators, to_windows_separators, RealPathError}; |
| 4 | − use std::fs::create_dir_all; | |
| 4 | + use std::fs::{create_dir_all, remove_dir_all}; | |
| 5 | + use std::ops::Deref; | |
| 5 | 6 | #[cfg(not(target_os = "windows"))] |
| 6 | 7 | use std::os::unix::fs; |
| 7 | 8 | #[cfg(target_os = "windows")] |
| @@ -9,6 +10,33 @@ mod convert { · 1 unmodified line | ||
| 9 | 10 | use std::path::{Path, PathBuf}; |
| 10 | 11 | use tempfile::{tempdir, tempdir_in}; |
| 11 | 12 | |
| 13 | + struct TempDirIn<'a> { | |
| 14 | + pub path: &'a Path, | |
| 15 | + } | |
| 16 | + | |
| 17 | + impl<'a> TempDirIn<'a> { | |
| 18 | + fn new(path: &'a str) -> Self { | |
| 19 | + let path = Path::new(path); | |
| 20 | + create_dir_all(path).unwrap(); | |
| 21 | + tempdir_in(path).unwrap(); | |
| 22 | + Self { path } | |
| 23 | + } | |
| 24 | + } | |
| 25 | + | |
| 26 | + impl Deref for TempDirIn<'_> { | |
| 27 | + type Target = Path; | |
| 28 | + | |
| 29 | + fn deref(&self) -> &Self::Target { | |
| 30 | + self.path | |
| 31 | + } | |
| 32 | + } | |
| 33 | + | |
| 34 | + impl Drop for TempDirIn<'_> { | |
| 35 | + fn drop(&mut self) { | |
| 36 | + remove_dir_all(&self.path).unwrap(); | |
| 37 | + } | |
| 38 | + } | |
| 39 | + | |
| 12 | 40 | #[test] |
| 13 | 41 | fn assure_unix_separators() { |
| 14 | 42 | assert_eq!(to_unix_separators(b"no-backslash".as_bstr()).as_bstr(), "no-backslash"); |
| @@ -27,12 +55,14 @@ mod convert { · 12 unmodified lines | ||
| 27 | 55 | } |
| 28 | 56 | |
| 29 | 57 | #[test] |
| 30 | − #[ignore] | |
| 31 | 58 | fn real_path_tests() { |
| 32 | 59 | let cwd = tempdir().unwrap(); |
| 33 | 60 | let cwd = cwd.path(); |
| 34 | − let tmp_dir = tempdir_in("/private/tmp").unwrap(); | |
| 35 | − let tmp_dir = tmp_dir.path(); | |
| 61 | + | |
| 62 | + #[cfg(not(target_os = "windows"))] | |
| 63 | + let tmp_dir = TempDirIn::new("/private/tmp/t"); | |
| 64 | + #[cfg(target_os = "windows")] | |
| 65 | + let tmp_dir = TempDirIn::new("%localappdata%\\Temp\\t"); | |
| 36 | 66 | |
| 37 | 67 | let empty_path = Path::new(""); |
| 38 | 68 | assert!( |
| @@ -124,15 +154,12 @@ mod convert { · 85 unmodified lines | ||
| 124 | 154 | |
| 125 | 155 | // enum Component.Prefix |
| 126 | 156 | |
| 127 | − let a = PathBuf::from("a"); | |
| 128 | − let mut a = a.components(); | |
| 129 | − let _ = a.next(); | |
| 130 | − | |
| 131 | − let mut pb = PathBuf::new(); | |
| 132 | − pb.push(a.collect::<PathBuf>()); | |
| 133 | − | |
| 134 | − assert_eq!(pb, PathBuf::new()); | |
| 135 | − assert_eq!(pb.components().next(), None); | |
| 157 | + let tmp_dir_in = TempDirIn::new("/tmp/a/b/s"); | |
| 158 | + let p = tmp_dir_in.path; | |
| 159 | + assert!(p.exists()); | |
| 160 | + assert_eq!(p, Path::new("/tmp/a/b/s")); | |
| 161 | + drop(tmp_dir_in); | |
| 162 | + assert!(!p.exists()); | |
| 136 | 163 | |
| 137 | 164 | // pass iterator input_path.components() instead of input_path |
| 138 | 165 | // have real_path mut and not return it |