Make tests pass on old macos

On old macos systems, `fs::hard_link()` will follow symlinks.
This changes the test `symlink_hard_link` to exit early on
these systems, so that tests can pass.
This commit is contained in:
Aris Merchant 2021-07-05 20:44:55 -07:00 committed by inquisitivecrystal
parent fd0cb0cdc2
commit 5999a5fbdc

View file

@ -19,6 +19,10 @@ use crate::os::unix::fs::symlink as symlink_junction;
use crate::os::windows::fs::{symlink_dir, symlink_file};
#[cfg(windows)]
use crate::sys::fs::symlink_junction;
#[cfg(target_os = "macos")]
use crate::sys::weak::weak;
#[cfg(target_os = "macos")]
use libc::{c_char, c_int};
macro_rules! check {
($e:expr) => {
@ -79,6 +83,17 @@ pub fn got_symlink_permission(tmpdir: &TempDir) -> bool {
}
}
#[cfg(target_os = "macos")]
fn able_to_not_follow_symlinks_while_hard_linking() -> bool {
weak!(fn linkat(c_int, *const c_char, c_int, *const c_char, c_int) -> c_int);
linkat.get().is_some()
}
#[cfg(not(target_os = "macos"))]
fn able_to_not_follow_symlinks_while_hard_linking() -> bool {
return true;
}
#[test]
fn file_test_io_smoke_test() {
let message = "it's alright. have a good time";
@ -1347,6 +1362,9 @@ fn symlink_hard_link() {
if !got_symlink_permission(&tmpdir) {
return;
};
if !able_to_not_follow_symlinks_while_hard_linking() {
return;
}
// Create "file", a file.
check!(fs::File::create(tmpdir.join("file")));