Skip to content

Commit 01b8403

Browse files
committed
examples, tests: use ignore instead of conditionally compiling tests
Change `#[cfg(cond)]` to `#[cfg_attr(not(cond), ignore)]` on tests. Ignoring tests instead of disabling them still makes them appear in the test list, but with `ignored`. It also still compiles the code in those cases. Some tests still need to be ignore, because they use types that are not present when the condition is false. For example the condition is `feature = std` and then it uses `std::thread::Thread`. Suggested-by: Alice Ryhl <[email protected]> Link: https://lore.kernel.org/all/[email protected] Signed-off-by: Benno Lossin <[email protected]>
1 parent cfdbdc5 commit 01b8403

File tree

4 files changed

+13
-19
lines changed

4 files changed

+13
-19
lines changed

examples/pthread_mutex.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,8 @@ mod pthread_mtx {
139139
}
140140
}
141141

142-
#[cfg_attr(all(test, not(miri)), test)]
142+
#[cfg_attr(test, test)]
143+
#[cfg_attr(all(test, miri), ignore)]
143144
fn main() {
144145
#[cfg(all(any(feature = "std", feature = "alloc"), not(windows)))]
145146
{

tests/alloc_fail.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
11
#![cfg_attr(feature = "alloc", feature(allocator_api))]
22
#![cfg_attr(not(RUSTC_LINT_REASONS_IS_STABLE), feature(lint_reasons))]
33

4-
#[cfg(all(
5-
feature = "alloc",
6-
not(miri),
7-
not(NO_ALLOC_FAIL_TESTS),
8-
not(target_os = "macos")
9-
))]
104
#[test]
5+
#[cfg(feature = "alloc")]
6+
#[cfg_attr(any(miri, NO_ALLOC_FAIL_TESTS, target_os = "macos"), ignore)]
117
fn too_big_in_place() {
12-
#[cfg(feature = "alloc")]
138
use core::alloc::AllocError;
149

1510
use pin_init::*;

tests/ring_buf.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,8 @@ fn even_stack() {
200200
assert_eq!(val, Err(()));
201201
}
202202

203-
#[cfg(any(feature = "std", feature = "alloc"))]
204203
#[test]
204+
#[cfg(any(feature = "std", feature = "alloc"))]
205205
fn even_failing() {
206206
assert!(matches!(Box::try_pin_init(EvenU64::new2(3)), Err(Error)));
207207
assert!(matches!(Box::try_init(EvenU64::new2(3)), Err(Error)));
@@ -253,8 +253,9 @@ struct BigStruct {
253253
oth: MaybeUninit<u8>,
254254
}
255255

256-
#[cfg(all(any(feature = "std", feature = "alloc"), not(miri)))]
257256
#[test]
257+
#[cfg(any(feature = "std", feature = "alloc"))]
258+
#[cfg_attr(miri, ignore)]
258259
fn big_struct() {
259260
let x = Arc::init(init!(BigStruct {
260261
buf <- init_zeroed(),
@@ -268,8 +269,9 @@ fn big_struct() {
268269
println!("{x:?}");
269270
}
270271

271-
#[cfg(all(any(feature = "std", feature = "alloc"), not(miri)))]
272272
#[test]
273+
#[cfg(any(feature = "std", feature = "alloc"))]
274+
#[cfg_attr(miri, ignore)]
273275
fn with_big_struct() {
274276
#[allow(unused_attributes)]
275277
#[path = "../examples/mutex.rs"]
@@ -299,13 +301,9 @@ fn with_big_struct() {
299301
}
300302
}
301303

302-
#[cfg(all(
303-
feature = "alloc",
304-
not(miri),
305-
not(NO_ALLOC_FAIL_TESTS),
306-
not(target_os = "macos")
307-
))]
308304
#[test]
305+
#[cfg(feature = "alloc")]
306+
#[cfg_attr(any(miri, NO_ALLOC_FAIL_TESTS, target_os = "macos"), ignore)]
309307
fn too_big_pinned() {
310308
use core::alloc::AllocError;
311309

tests/ui.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#![cfg_attr(not(RUSTC_LINT_REASONS_IS_STABLE), feature(lint_reasons))]
22

3-
#[cfg(not(any(miri, NO_UI_TESTS)))]
43
#[test]
4+
#[cfg_attr(any(miri, NO_UI_TESTS), ignore)]
55
fn compile_fail() {
66
let test_cases = trybuild::TestCases::new();
77
test_cases.compile_fail("tests/ui/compile-fail/pinned_drop/*.rs");
@@ -10,8 +10,8 @@ fn compile_fail() {
1010
test_cases.compile_fail("tests/ui/compile-fail/zeroable/*.rs");
1111
}
1212

13-
#[cfg(not(any(miri, NO_UI_TESTS)))]
1413
#[test]
14+
#[cfg_attr(any(miri, NO_UI_TESTS), ignore)]
1515
fn expand() {
1616
macrotest::expand("tests/ui/expand/*.rs");
1717
}

0 commit comments

Comments
 (0)