Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 1f97da3

Browse files
committedMar 10, 2025
Mark some std tests as requiring panic = "unwind"
This allows these test modules to pass on builds/targets without unwinding support, where `panic = "abort"` - the ignored tests are for functionality that's not supported on those targets.
1 parent 2b4694a commit 1f97da3

File tree

5 files changed

+40
-2
lines changed

5 files changed

+40
-2
lines changed
 

‎library/std/src/thread/tests.rs

+6
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ fn test_named_thread_truncation() {
6363
}
6464

6565
#[test]
66+
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
6667
#[should_panic]
6768
fn test_invalid_named_thread() {
6869
let _ = Builder::new().name("ada l\0velace".to_string()).spawn(|| {});
@@ -108,6 +109,7 @@ fn test_is_finished() {
108109
}
109110

110111
#[test]
112+
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
111113
fn test_join_panic() {
112114
match thread::spawn(move || panic!()).join() {
113115
result::Result::Err(_) => (),
@@ -210,6 +212,7 @@ fn test_simple_newsched_spawn() {
210212
}
211213

212214
#[test]
215+
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
213216
fn test_try_panic_message_string_literal() {
214217
match thread::spawn(move || {
215218
panic!("static string");
@@ -226,6 +229,7 @@ fn test_try_panic_message_string_literal() {
226229
}
227230

228231
#[test]
232+
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
229233
fn test_try_panic_any_message_owned_str() {
230234
match thread::spawn(move || {
231235
panic_any("owned string".to_string());
@@ -242,6 +246,7 @@ fn test_try_panic_any_message_owned_str() {
242246
}
243247

244248
#[test]
249+
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
245250
fn test_try_panic_any_message_any() {
246251
match thread::spawn(move || {
247252
panic_any(Box::new(413u16) as Box<dyn Any + Send>);
@@ -260,6 +265,7 @@ fn test_try_panic_any_message_any() {
260265
}
261266

262267
#[test]
268+
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
263269
fn test_try_panic_any_message_unit_struct() {
264270
struct Juju;
265271

‎library/std/tests/sync/mutex.rs

+10
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ fn test_into_inner_drop() {
118118
}
119119

120120
#[test]
121+
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
121122
fn test_into_inner_poison() {
122123
let m = new_poisoned_mutex(NonCopy(10));
123124

@@ -135,6 +136,7 @@ fn test_get_cloned() {
135136
}
136137

137138
#[test]
139+
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
138140
fn test_get_cloned_poison() {
139141
let m = new_poisoned_mutex(Cloneable(10));
140142

@@ -152,6 +154,7 @@ fn test_get_mut() {
152154
}
153155

154156
#[test]
157+
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
155158
fn test_get_mut_poison() {
156159
let mut m = new_poisoned_mutex(NonCopy(10));
157160

@@ -179,6 +182,7 @@ fn test_set() {
179182
}
180183

181184
#[test]
185+
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
182186
fn test_set_poison() {
183187
fn inner<T>(mut init: impl FnMut() -> T, mut value: impl FnMut() -> T)
184188
where
@@ -217,6 +221,7 @@ fn test_replace() {
217221
}
218222

219223
#[test]
224+
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
220225
fn test_replace_poison() {
221226
fn inner<T>(mut init: impl FnMut() -> T, mut value: impl FnMut() -> T)
222227
where
@@ -261,6 +266,7 @@ fn test_mutex_arc_condvar() {
261266
}
262267

263268
#[test]
269+
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
264270
fn test_arc_condvar_poison() {
265271
let packet = Packet(Arc::new((Mutex::new(1), Condvar::new())));
266272
let packet2 = Packet(packet.0.clone());
@@ -290,6 +296,7 @@ fn test_arc_condvar_poison() {
290296
}
291297

292298
#[test]
299+
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
293300
fn test_mutex_arc_poison() {
294301
let arc = Arc::new(Mutex::new(1));
295302
assert!(!arc.is_poisoned());
@@ -304,6 +311,7 @@ fn test_mutex_arc_poison() {
304311
}
305312

306313
#[test]
314+
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
307315
fn test_mutex_arc_poison_mapped() {
308316
let arc = Arc::new(Mutex::new(1));
309317
assert!(!arc.is_poisoned());
@@ -335,6 +343,7 @@ fn test_mutex_arc_nested() {
335343
}
336344

337345
#[test]
346+
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
338347
fn test_mutex_arc_access_in_unwind() {
339348
let arc = Arc::new(Mutex::new(1));
340349
let arc2 = arc.clone();
@@ -381,6 +390,7 @@ fn test_mapping_mapped_guard() {
381390
}
382391

383392
#[test]
393+
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
384394
fn panic_while_mapping_unlocked_poison() {
385395
let lock = Mutex::new(());
386396

‎library/std/tests/sync/once.rs

+4
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ fn stampede_once() {
5252
}
5353

5454
#[test]
55+
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
5556
fn poison_bad() {
5657
static O: Once = Once::new();
5758

@@ -80,6 +81,7 @@ fn poison_bad() {
8081
}
8182

8283
#[test]
84+
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
8385
fn wait_for_force_to_finish() {
8486
static O: Once = Once::new();
8587

@@ -137,6 +139,7 @@ fn wait() {
137139
}
138140

139141
#[test]
142+
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
140143
fn wait_on_poisoned() {
141144
let once = Once::new();
142145

@@ -145,6 +148,7 @@ fn wait_on_poisoned() {
145148
}
146149

147150
#[test]
151+
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
148152
fn wait_force_on_poisoned() {
149153
let once = Once::new();
150154

‎library/std/tests/sync/once_lock.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,10 @@ fn get_or_try_init() {
7777
let cell: OnceLock<String> = OnceLock::new();
7878
assert!(cell.get().is_none());
7979

80-
let res = panic::catch_unwind(|| cell.get_or_try_init(|| -> Result<_, ()> { panic!() }));
81-
assert!(res.is_err());
80+
if cfg!(panic = "unwind") {
81+
let res = panic::catch_unwind(|| cell.get_or_try_init(|| -> Result<_, ()> { panic!() }));
82+
assert!(res.is_err());
83+
}
8284
assert!(cell.get().is_none());
8385

8486
assert_eq!(cell.get_or_try_init(|| Err(())), Err(()));

‎library/std/tests/sync/rwlock.rs

+16
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ fn frob() {
7373
}
7474

7575
#[test]
76+
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
7677
fn test_rw_arc_poison_wr() {
7778
let arc = Arc::new(RwLock::new(1));
7879
let arc2 = arc.clone();
@@ -85,6 +86,7 @@ fn test_rw_arc_poison_wr() {
8586
}
8687

8788
#[test]
89+
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
8890
fn test_rw_arc_poison_mapped_w_r() {
8991
let arc = Arc::new(RwLock::new(1));
9092
let arc2 = arc.clone();
@@ -98,6 +100,7 @@ fn test_rw_arc_poison_mapped_w_r() {
98100
}
99101

100102
#[test]
103+
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
101104
fn test_rw_arc_poison_ww() {
102105
let arc = Arc::new(RwLock::new(1));
103106
assert!(!arc.is_poisoned());
@@ -112,6 +115,7 @@ fn test_rw_arc_poison_ww() {
112115
}
113116

114117
#[test]
118+
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
115119
fn test_rw_arc_poison_mapped_w_w() {
116120
let arc = Arc::new(RwLock::new(1));
117121
let arc2 = arc.clone();
@@ -126,6 +130,7 @@ fn test_rw_arc_poison_mapped_w_w() {
126130
}
127131

128132
#[test]
133+
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
129134
fn test_rw_arc_no_poison_rr() {
130135
let arc = Arc::new(RwLock::new(1));
131136
let arc2 = arc.clone();
@@ -139,6 +144,7 @@ fn test_rw_arc_no_poison_rr() {
139144
}
140145

141146
#[test]
147+
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
142148
fn test_rw_arc_no_poison_mapped_r_r() {
143149
let arc = Arc::new(RwLock::new(1));
144150
let arc2 = arc.clone();
@@ -153,6 +159,7 @@ fn test_rw_arc_no_poison_mapped_r_r() {
153159
}
154160

155161
#[test]
162+
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
156163
fn test_rw_arc_no_poison_rw() {
157164
let arc = Arc::new(RwLock::new(1));
158165
let arc2 = arc.clone();
@@ -166,6 +173,7 @@ fn test_rw_arc_no_poison_rw() {
166173
}
167174

168175
#[test]
176+
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
169177
fn test_rw_arc_no_poison_mapped_r_w() {
170178
let arc = Arc::new(RwLock::new(1));
171179
let arc2 = arc.clone();
@@ -218,6 +226,7 @@ fn test_rw_arc() {
218226
}
219227

220228
#[test]
229+
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
221230
fn test_rw_arc_access_in_unwind() {
222231
let arc = Arc::new(RwLock::new(1));
223232
let arc2 = arc.clone();
@@ -316,6 +325,7 @@ fn test_into_inner_drop() {
316325
}
317326

318327
#[test]
328+
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
319329
fn test_into_inner_poison() {
320330
let m = new_poisoned_rwlock(NonCopy(10));
321331

@@ -333,6 +343,7 @@ fn test_get_cloned() {
333343
}
334344

335345
#[test]
346+
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
336347
fn test_get_cloned_poison() {
337348
let m = new_poisoned_rwlock(Cloneable(10));
338349

@@ -350,6 +361,7 @@ fn test_get_mut() {
350361
}
351362

352363
#[test]
364+
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
353365
fn test_get_mut_poison() {
354366
let mut m = new_poisoned_rwlock(NonCopy(10));
355367

@@ -377,6 +389,7 @@ fn test_set() {
377389
}
378390

379391
#[test]
392+
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
380393
fn test_set_poison() {
381394
fn inner<T>(mut init: impl FnMut() -> T, mut value: impl FnMut() -> T)
382395
where
@@ -415,6 +428,7 @@ fn test_replace() {
415428
}
416429

417430
#[test]
431+
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
418432
fn test_replace_poison() {
419433
fn inner<T>(mut init: impl FnMut() -> T, mut value: impl FnMut() -> T)
420434
where
@@ -482,6 +496,7 @@ fn test_mapping_mapped_guard() {
482496
}
483497

484498
#[test]
499+
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
485500
fn panic_while_mapping_read_unlocked_no_poison() {
486501
let lock = RwLock::new(());
487502

@@ -551,6 +566,7 @@ fn panic_while_mapping_read_unlocked_no_poison() {
551566
}
552567

553568
#[test]
569+
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
554570
fn panic_while_mapping_write_unlocked_poison() {
555571
let lock = RwLock::new(());
556572

0 commit comments

Comments
 (0)
Failed to load comments.