Skip to content

Commit 3fb9294

Browse files
bonziniBennoLossin
authored andcommitted
tests: dead code warnings are fine when tests are disabled
Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 7a02909 commit 3fb9294

File tree

2 files changed

+34
-36
lines changed

2 files changed

+34
-36
lines changed

tests/alloc_fail.rs

Lines changed: 6 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,5 @@
11
#![cfg_attr(feature = "alloc", feature(allocator_api))]
22

3-
#[cfg(feature = "alloc")]
4-
use core::alloc::AllocError;
5-
6-
use pinned_init::*;
7-
use std::sync::Arc;
8-
9-
#[expect(unused_attributes)]
10-
#[path = "./ring_buf.rs"]
11-
mod ring_buf;
12-
use ring_buf::*;
13-
14-
#[cfg(all(
15-
feature = "alloc",
16-
not(miri),
17-
not(NO_ALLOC_FAIL_TESTS),
18-
not(target_os = "macos")
19-
))]
20-
#[test]
21-
fn too_big_pinned() {
22-
// should be too big with current hardware.
23-
assert!(matches!(
24-
Box::pin_init(RingBuffer::<u8, { 1024 * 1024 * 1024 * 1024 }>::new()),
25-
Err(AllocError)
26-
));
27-
// should be too big with current hardware.
28-
assert!(matches!(
29-
Arc::pin_init(RingBuffer::<u8, { 1024 * 1024 * 1024 * 1024 }>::new()),
30-
Err(AllocError)
31-
));
32-
}
33-
343
#[cfg(all(
354
feature = "alloc",
365
not(miri),
@@ -39,6 +8,12 @@ fn too_big_pinned() {
398
))]
409
#[test]
4110
fn too_big_in_place() {
11+
#[cfg(feature = "alloc")]
12+
use core::alloc::AllocError;
13+
14+
use pinned_init::*;
15+
use std::sync::Arc;
16+
4217
// should be too big with current hardware.
4318
assert!(matches!(
4419
Box::init(zeroed::<[u8; 1024 * 1024 * 1024 * 1024]>()),

tests/ring_buf.rs

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,6 @@ use core::{
1111
use pinned_init::*;
1212
use std::sync::Arc;
1313

14-
#[expect(unused_attributes)]
15-
#[path = "../examples/mutex.rs"]
16-
mod mutex;
17-
use mutex::*;
18-
1914
#[expect(unused_attributes)]
2015
#[path = "../examples/error.rs"]
2116
mod error;
@@ -244,6 +239,7 @@ fn with_failing_inner() {
244239
assert_eq!(buf.as_mut().pop(), None);
245240
}
246241

242+
#[cfg_attr(miri, allow(dead_code))]
247243
#[derive(Debug)]
248244
struct BigStruct {
249245
buf: [u8; 1024 * 1024],
@@ -268,6 +264,11 @@ fn big_struct() {
268264
#[cfg(all(any(feature = "std", feature = "alloc"), not(miri)))]
269265
#[test]
270266
fn with_big_struct() {
267+
#[expect(unused_attributes)]
268+
#[path = "../examples/mutex.rs"]
269+
mod mutex;
270+
use mutex::*;
271+
271272
let buf = Arc::pin_init(CMutex::new(RingBuffer::<BigStruct, 64>::new())).unwrap();
272273
let mut buf = buf.lock();
273274
for _ in 0..63 {
@@ -290,3 +291,25 @@ fn with_big_struct() {
290291
assert!(buf.as_mut().pop_no_stack().is_some());
291292
}
292293
}
294+
295+
#[cfg(all(
296+
feature = "alloc",
297+
not(miri),
298+
not(NO_ALLOC_FAIL_TESTS),
299+
not(target_os = "macos")
300+
))]
301+
#[test]
302+
fn too_big_pinned() {
303+
use core::alloc::AllocError;
304+
305+
// should be too big with current hardware.
306+
assert!(matches!(
307+
Box::pin_init(RingBuffer::<u8, { 1024 * 1024 * 1024 * 1024 }>::new()),
308+
Err(AllocError)
309+
));
310+
// should be too big with current hardware.
311+
assert!(matches!(
312+
Arc::pin_init(RingBuffer::<u8, { 1024 * 1024 * 1024 * 1024 }>::new()),
313+
Err(AllocError)
314+
));
315+
}

0 commit comments

Comments
 (0)