Skip to content

Commit 4bf24d2

Browse files
committed
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.
1 parent 8c4e3ff commit 4bf24d2

File tree

1 file changed

+65
-70
lines changed

1 file changed

+65
-70
lines changed

library/std/src/fs/tests.rs

Lines changed: 65 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,7 @@
11
use rand::RngCore;
22

3-
#[cfg(any(
4-
windows,
5-
target_os = "freebsd",
6-
target_os = "linux",
7-
target_os = "netbsd",
8-
target_os = "illumos",
9-
target_vendor = "apple",
10-
))]
113
use crate::assert_matches::assert_matches;
12-
#[cfg(any(
13-
windows,
14-
target_os = "freebsd",
15-
target_os = "linux",
16-
target_os = "netbsd",
17-
target_os = "illumos",
18-
target_vendor = "apple",
19-
))]
20-
use crate::fs::TryLockError;
21-
use crate::fs::{self, File, FileTimes, OpenOptions};
4+
use crate::fs::{self, File, FileTimes, OpenOptions, TryLockError};
225
use crate::io::prelude::*;
236
use crate::io::{BorrowedBuf, ErrorKind, SeekFrom};
247
use crate::mem::MaybeUninit;
@@ -222,19 +205,22 @@ fn file_test_io_seek_and_write() {
222205
}
223206

224207
#[test]
225-
#[cfg(any(
226-
windows,
227-
target_os = "aix",
228-
target_os = "cygwin",
229-
target_os = "freebsd",
230-
target_os = "fuchsia",
231-
target_os = "illumos",
232-
target_os = "linux",
233-
target_os = "netbsd",
234-
target_os = "openbsd",
235-
target_os = "solaris",
236-
target_vendor = "apple",
237-
))]
208+
#[cfg_attr(
209+
not(any(
210+
windows,
211+
target_os = "aix",
212+
target_os = "cygwin",
213+
target_os = "freebsd",
214+
target_os = "fuchsia",
215+
target_os = "illumos",
216+
target_os = "linux",
217+
target_os = "netbsd",
218+
target_os = "openbsd",
219+
target_os = "solaris",
220+
target_vendor = "apple",
221+
)),
222+
should_panic
223+
)]
238224
fn file_lock_multiple_shared() {
239225
let tmpdir = tmpdir();
240226
let filename = &tmpdir.join("file_lock_multiple_shared_test.txt");
@@ -251,19 +237,22 @@ fn file_lock_multiple_shared() {
251237
}
252238

253239
#[test]
254-
#[cfg(any(
255-
windows,
256-
target_os = "aix",
257-
target_os = "cygwin",
258-
target_os = "freebsd",
259-
target_os = "fuchsia",
260-
target_os = "illumos",
261-
target_os = "linux",
262-
target_os = "netbsd",
263-
target_os = "openbsd",
264-
target_os = "solaris",
265-
target_vendor = "apple",
266-
))]
240+
#[cfg_attr(
241+
not(any(
242+
windows,
243+
target_os = "aix",
244+
target_os = "cygwin",
245+
target_os = "freebsd",
246+
target_os = "fuchsia",
247+
target_os = "illumos",
248+
target_os = "linux",
249+
target_os = "netbsd",
250+
target_os = "openbsd",
251+
target_os = "solaris",
252+
target_vendor = "apple",
253+
)),
254+
should_panic
255+
)]
267256
fn file_lock_blocking() {
268257
let tmpdir = tmpdir();
269258
let filename = &tmpdir.join("file_lock_blocking_test.txt");
@@ -281,19 +270,22 @@ fn file_lock_blocking() {
281270
}
282271

283272
#[test]
284-
#[cfg(any(
285-
windows,
286-
target_os = "aix",
287-
target_os = "cygwin",
288-
target_os = "freebsd",
289-
target_os = "fuchsia",
290-
target_os = "illumos",
291-
target_os = "linux",
292-
target_os = "netbsd",
293-
target_os = "openbsd",
294-
target_os = "solaris",
295-
target_vendor = "apple",
296-
))]
273+
#[cfg_attr(
274+
not(any(
275+
windows,
276+
target_os = "aix",
277+
target_os = "cygwin",
278+
target_os = "freebsd",
279+
target_os = "fuchsia",
280+
target_os = "illumos",
281+
target_os = "linux",
282+
target_os = "netbsd",
283+
target_os = "openbsd",
284+
target_os = "solaris",
285+
target_vendor = "apple",
286+
)),
287+
should_panic
288+
)]
297289
fn file_lock_drop() {
298290
let tmpdir = tmpdir();
299291
let filename = &tmpdir.join("file_lock_dup_test.txt");
@@ -308,19 +300,22 @@ fn file_lock_drop() {
308300
}
309301

310302
#[test]
311-
#[cfg(any(
312-
windows,
313-
target_os = "aix",
314-
target_os = "cygwin",
315-
target_os = "freebsd",
316-
target_os = "fuchsia",
317-
target_os = "illumos",
318-
target_os = "linux",
319-
target_os = "netbsd",
320-
target_os = "openbsd",
321-
target_os = "solaris",
322-
target_vendor = "apple",
323-
))]
303+
#[cfg_attr(
304+
not(any(
305+
windows,
306+
target_os = "aix",
307+
target_os = "cygwin",
308+
target_os = "freebsd",
309+
target_os = "fuchsia",
310+
target_os = "illumos",
311+
target_os = "linux",
312+
target_os = "netbsd",
313+
target_os = "openbsd",
314+
target_os = "solaris",
315+
target_vendor = "apple",
316+
)),
317+
should_panic
318+
)]
324319
fn file_lock_dup() {
325320
let tmpdir = tmpdir();
326321
let filename = &tmpdir.join("file_lock_dup_test.txt");

0 commit comments

Comments
 (0)