From 8c4e3ff0a6f056345196dffc81795927e947b3f9 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Wed, 19 Nov 2025 14:20:00 -0600 Subject: [PATCH 1/3] fs: Update skipped file lock tests to match flock support The list of platforms for which file locks are tested is smaller than the list of platforms that support it. Synchronize these here. Link: https://github.com/rust-lang/rust/blob/07bdbaedc63094281483c40a88a1a8f2f8ffadc5/library/std/src/sys/fs/unix.rs#L1291-L1308 --- library/std/src/fs/tests.rs | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/library/std/src/fs/tests.rs b/library/std/src/fs/tests.rs index 9fd87e119906e..294de60f7d43e 100644 --- a/library/std/src/fs/tests.rs +++ b/library/std/src/fs/tests.rs @@ -224,11 +224,15 @@ fn file_test_io_seek_and_write() { #[test] #[cfg(any( windows, + target_os = "aix", + target_os = "cygwin", target_os = "freebsd", + target_os = "fuchsia", + target_os = "illumos", target_os = "linux", target_os = "netbsd", + target_os = "openbsd", target_os = "solaris", - target_os = "illumos", target_vendor = "apple", ))] fn file_lock_multiple_shared() { @@ -249,11 +253,15 @@ fn file_lock_multiple_shared() { #[test] #[cfg(any( windows, + target_os = "aix", + target_os = "cygwin", target_os = "freebsd", + target_os = "fuchsia", + target_os = "illumos", target_os = "linux", target_os = "netbsd", + target_os = "openbsd", target_os = "solaris", - target_os = "illumos", target_vendor = "apple", ))] fn file_lock_blocking() { @@ -275,11 +283,15 @@ fn file_lock_blocking() { #[test] #[cfg(any( windows, + target_os = "aix", + target_os = "cygwin", target_os = "freebsd", + target_os = "fuchsia", + target_os = "illumos", target_os = "linux", target_os = "netbsd", + target_os = "openbsd", target_os = "solaris", - target_os = "illumos", target_vendor = "apple", ))] fn file_lock_drop() { @@ -298,11 +310,15 @@ fn file_lock_drop() { #[test] #[cfg(any( windows, + target_os = "aix", + target_os = "cygwin", target_os = "freebsd", + target_os = "fuchsia", + target_os = "illumos", target_os = "linux", target_os = "netbsd", + target_os = "openbsd", target_os = "solaris", - target_os = "illumos", target_vendor = "apple", ))] fn file_lock_dup() { From 4bf24d2b54c23dd00c7eb48dd6b9a82bead687ec Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Wed, 19 Nov 2025 14:20:00 -0600 Subject: [PATCH 2/3] fs: Expect a test failure if file locks aren't supported Rather than skipping the tests, make sure that they fail. This ensures that if file locking support is added for more platforms in the future, the tests don't wind up quietly skipped. --- library/std/src/fs/tests.rs | 135 +++++++++++++++++------------------- 1 file changed, 65 insertions(+), 70 deletions(-) diff --git a/library/std/src/fs/tests.rs b/library/std/src/fs/tests.rs index 294de60f7d43e..a9195f09425c8 100644 --- a/library/std/src/fs/tests.rs +++ b/library/std/src/fs/tests.rs @@ -1,24 +1,7 @@ use rand::RngCore; -#[cfg(any( - windows, - target_os = "freebsd", - target_os = "linux", - target_os = "netbsd", - target_os = "illumos", - target_vendor = "apple", -))] use crate::assert_matches::assert_matches; -#[cfg(any( - windows, - target_os = "freebsd", - target_os = "linux", - target_os = "netbsd", - target_os = "illumos", - target_vendor = "apple", -))] -use crate::fs::TryLockError; -use crate::fs::{self, File, FileTimes, OpenOptions}; +use crate::fs::{self, File, FileTimes, OpenOptions, TryLockError}; use crate::io::prelude::*; use crate::io::{BorrowedBuf, ErrorKind, SeekFrom}; use crate::mem::MaybeUninit; @@ -222,19 +205,22 @@ fn file_test_io_seek_and_write() { } #[test] -#[cfg(any( - windows, - target_os = "aix", - target_os = "cygwin", - target_os = "freebsd", - target_os = "fuchsia", - target_os = "illumos", - target_os = "linux", - target_os = "netbsd", - target_os = "openbsd", - target_os = "solaris", - target_vendor = "apple", -))] +#[cfg_attr( + not(any( + windows, + target_os = "aix", + target_os = "cygwin", + target_os = "freebsd", + target_os = "fuchsia", + target_os = "illumos", + target_os = "linux", + target_os = "netbsd", + target_os = "openbsd", + target_os = "solaris", + target_vendor = "apple", + )), + should_panic +)] fn file_lock_multiple_shared() { let tmpdir = tmpdir(); let filename = &tmpdir.join("file_lock_multiple_shared_test.txt"); @@ -251,19 +237,22 @@ fn file_lock_multiple_shared() { } #[test] -#[cfg(any( - windows, - target_os = "aix", - target_os = "cygwin", - target_os = "freebsd", - target_os = "fuchsia", - target_os = "illumos", - target_os = "linux", - target_os = "netbsd", - target_os = "openbsd", - target_os = "solaris", - target_vendor = "apple", -))] +#[cfg_attr( + not(any( + windows, + target_os = "aix", + target_os = "cygwin", + target_os = "freebsd", + target_os = "fuchsia", + target_os = "illumos", + target_os = "linux", + target_os = "netbsd", + target_os = "openbsd", + target_os = "solaris", + target_vendor = "apple", + )), + should_panic +)] fn file_lock_blocking() { let tmpdir = tmpdir(); let filename = &tmpdir.join("file_lock_blocking_test.txt"); @@ -281,19 +270,22 @@ fn file_lock_blocking() { } #[test] -#[cfg(any( - windows, - target_os = "aix", - target_os = "cygwin", - target_os = "freebsd", - target_os = "fuchsia", - target_os = "illumos", - target_os = "linux", - target_os = "netbsd", - target_os = "openbsd", - target_os = "solaris", - target_vendor = "apple", -))] +#[cfg_attr( + not(any( + windows, + target_os = "aix", + target_os = "cygwin", + target_os = "freebsd", + target_os = "fuchsia", + target_os = "illumos", + target_os = "linux", + target_os = "netbsd", + target_os = "openbsd", + target_os = "solaris", + target_vendor = "apple", + )), + should_panic +)] fn file_lock_drop() { let tmpdir = tmpdir(); let filename = &tmpdir.join("file_lock_dup_test.txt"); @@ -308,19 +300,22 @@ fn file_lock_drop() { } #[test] -#[cfg(any( - windows, - target_os = "aix", - target_os = "cygwin", - target_os = "freebsd", - target_os = "fuchsia", - target_os = "illumos", - target_os = "linux", - target_os = "netbsd", - target_os = "openbsd", - target_os = "solaris", - target_vendor = "apple", -))] +#[cfg_attr( + not(any( + windows, + target_os = "aix", + target_os = "cygwin", + target_os = "freebsd", + target_os = "fuchsia", + target_os = "illumos", + target_os = "linux", + target_os = "netbsd", + target_os = "openbsd", + target_os = "solaris", + target_vendor = "apple", + )), + should_panic +)] fn file_lock_dup() { let tmpdir = tmpdir(); let filename = &tmpdir.join("file_lock_dup_test.txt"); From cea9dd8dc8cddd9ecbdf1308418b63dfa047aca4 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Wed, 19 Nov 2025 14:20:00 -0600 Subject: [PATCH 3/3] test: Use an ignore message for fs Android skips --- library/std/src/fs/tests.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/std/src/fs/tests.rs b/library/std/src/fs/tests.rs index a9195f09425c8..0a5d1153d860c 100644 --- a/library/std/src/fs/tests.rs +++ b/library/std/src/fs/tests.rs @@ -1263,7 +1263,7 @@ fn readlink_not_symlink() { } #[test] -#[cfg_attr(target_os = "android", ignore)] // Android SELinux rules prevent creating hardlinks +#[cfg_attr(target_os = "android", ignore = "Android SELinux rules prevent creating hardlinks")] fn links_work() { let tmpdir = tmpdir(); let input = tmpdir.join("in.txt"); @@ -1759,7 +1759,7 @@ fn metadata_access_times() { /// Test creating hard links to symlinks. #[test] -#[cfg_attr(target_os = "android", ignore)] // Android SELinux rules prevent creating hardlinks +#[cfg_attr(target_os = "android", ignore = "Android SELinux rules prevent creating hardlinks")] fn symlink_hard_link() { let tmpdir = tmpdir(); if !got_symlink_permission(&tmpdir) {