This is an archive of the discontinued Mercurial Phabricator instance.

rust: fix testing with $TMPDIR ≠ /tmp
ClosedPublic

Authored by danchr on Dec 30 2020, 7:01 AM.

Diff Detail

Repository
rHG Mercurial
Branch
default
Lint
No Linters Available
Unit
No Unit Test Coverage

Event Timeline

danchr created this revision.Dec 30 2020, 7:01 AM
baymax updated this revision to Diff 24557.Dec 31 2020, 5:07 AM

✅ refresh by Heptapod after a successful CI run (🐙 💚)

Alphare accepted this revision.Jan 5 2021, 4:11 AM
Alphare added a subscriber: Alphare.

Thanks, this is already a bit better.

What is this patch doing ? Should we add some comment in the code to explain the rationnal around the skip thingy ?

What is this patch doing ? Should we add some comment in the code to explain the rationnal around the skip thingy ?

Thinking about it some more, this should just use https://doc.rust-lang.org/std/path/struct.Path.html#method.strip_prefix

What is this patch doing ? Should we add some comment in the code to explain the rationnal around the skip thingy ?

Thinking about it some more, this should just use https://doc.rust-lang.org/std/path/struct.Path.html#method.strip_prefix

It took me long enough to realise what that magic “2” meant and why the test was failing; I'm not comfortable with the logic there to do that refactoring.

It took me long enough to realise what that magic “2” meant and why the test was failing; I'm not comfortable with the logic there to do that refactoring.

rust
-        let buf = b.join("in_a").components().skip(2).collect::<PathBuf>();
+        let buf = b.join("in_a");
+        let buf = buf.strip_prefix(&base_dir_path.parent().unwrap()).unwrap();
         eprintln!("buf: {}", buf.display());
         let path = path_to_hg_path_buf(buf).unwrap();
         assert_eq!(
             auditor.audit_path(&path),
             Err(HgPathError::TraversesSymbolicLink {
-                path: path,
+                path,
                 symlink: path_to_hg_path_buf(
-                    b.components().skip(2).collect::<PathBuf>()
+                    b.strip_prefix(&base_dir_path.parent().unwrap()).unwrap()
                 )
                 .unwrap()
})

This does the trick. Do you want me to send the patch instead?

This revision was not accepted when it landed; it landed in state Needs Review.
This revision was automatically updated to reflect the committed changes.