##// END OF EJS Templates
tests: run the whole hg-core/path_auditor test in a clean temp dir...
pacien -
r49128:ab2dfc99 stable
parent child Browse files
Show More
@@ -180,12 +180,14 b' impl PathAuditor {'
180 #[cfg(test)]
180 #[cfg(test)]
181 mod tests {
181 mod tests {
182 use super::*;
182 use super::*;
183 use crate::utils::files::get_path_from_bytes;
183 use std::fs::{create_dir, File};
184 use crate::utils::hg_path::path_to_hg_path_buf;
184 use tempfile::tempdir;
185
185
186 #[test]
186 #[test]
187 fn test_path_auditor() {
187 fn test_path_auditor() {
188 let auditor = PathAuditor::new(get_path_from_bytes(b"/tmp"));
188 let base_dir = tempdir().unwrap();
189 let base_dir_path = base_dir.path();
190 let auditor = PathAuditor::new(base_dir_path);
189
191
190 let path = HgPath::new(b".hg/00changelog.i");
192 let path = HgPath::new(b".hg/00changelog.i");
191 assert_eq!(
193 assert_eq!(
@@ -201,32 +203,20 b' mod tests {'
201 })
203 })
202 );
204 );
203
205
204 use std::fs::{create_dir, File};
206 create_dir(&base_dir_path.join("realdir")).unwrap();
205 use tempfile::tempdir;
207 File::create(&base_dir_path.join("realdir/realfile")).unwrap();
206
207 let base_dir = tempdir().unwrap();
208 let base_dir_path = base_dir.path();
209 let skip = base_dir_path.components().count() - 1;
210 let a = base_dir_path.join("a");
211 let b = base_dir_path.join("b");
212 create_dir(&a).unwrap();
213 let in_a_path = a.join("in_a");
214 File::create(in_a_path).unwrap();
215
216 // TODO make portable
208 // TODO make portable
217 std::os::unix::fs::symlink(&a, &b).unwrap();
209 std::os::unix::fs::symlink(
218
210 &base_dir_path.join("realdir"),
219 let buf = b.join("in_a").components().skip(skip).collect::<PathBuf>();
211 &base_dir_path.join("symlink"),
220 eprintln!("buf: {}", buf.display());
212 )
221 let path = path_to_hg_path_buf(buf).unwrap();
213 .unwrap();
214 let path = HgPath::new(b"symlink/realfile");
222 assert_eq!(
215 assert_eq!(
223 auditor.audit_path(&path),
216 auditor.audit_path(path),
224 Err(HgPathError::TraversesSymbolicLink {
217 Err(HgPathError::TraversesSymbolicLink {
225 path: path,
218 path: path.to_owned(),
226 symlink: path_to_hg_path_buf(
219 symlink: HgPathBuf::from_bytes(b"symlink"),
227 b.components().skip(2).collect::<PathBuf>()
228 )
229 .unwrap()
230 })
220 })
231 );
221 );
232 }
222 }
General Comments 0
You need to be logged in to leave comments. Login now