Read about our upcoming Code of Conduct on this issue

Commit c93b701b authored by Pacien TRAN-GIRARD's avatar Pacien TRAN-GIRARD
Browse files

tests: run the whole hg-core/path_auditor test in a clean temp dir

This makes the whole test happen in a clean temporary directory in
`$TMPDIR/$random`, and simplifies the test a bit by eliminating unnecessarily
dynamic path elements computations.

Before this patch, the first part of the test was happening in `/tmp` itself.
This allowed coincidentally named files placed in that directory to impact the
outcome of the test. Additionally, this made the second part of the test fail
on systems on which `$TMPDIR != /tmp`, because the inspected directory was
different from the one in which the mock files were being written. This fully
fixes the issue only partially solved in db2bc9e667a1.

Differential Revision:

branch : stable
parent 809e780c72e5
......@@ -180,12 +180,14 @@ impl PathAuditor {
mod tests {
use super::*;
use crate::utils::files::get_path_from_bytes;
use crate::utils::hg_path::path_to_hg_path_buf;
use std::fs::{create_dir, File};
use tempfile::tempdir;
fn test_path_auditor() {
let auditor = PathAuditor::new(get_path_from_bytes(b"/tmp"));
let base_dir = tempdir().unwrap();
let base_dir_path = base_dir.path();
let auditor = PathAuditor::new(base_dir_path);
let path = HgPath::new(b".hg/00changelog.i");
......@@ -201,32 +203,20 @@ mod tests {
use std::fs::{create_dir, File};
use tempfile::tempdir;
let base_dir = tempdir().unwrap();
let base_dir_path = base_dir.path();
let skip = base_dir_path.components().count() - 1;
let a = base_dir_path.join("a");
let b = base_dir_path.join("b");
let in_a_path = a.join("in_a");
// TODO make portable
std::os::unix::fs::symlink(&a, &b).unwrap();
let buf = b.join("in_a").components().skip(skip).collect::<PathBuf>();
eprintln!("buf: {}", buf.display());
let path = path_to_hg_path_buf(buf).unwrap();
let path = HgPath::new(b"symlink/realfile");
Err(HgPathError::TraversesSymbolicLink {
path: path,
symlink: path_to_hg_path_buf(
path: path.to_owned(),
symlink: HgPathBuf::from_bytes(b"symlink"),
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment