Skip to content

Commit 8a3e9f2

Browse files
Ignore tests that require unwinding on targets that don't support it
1 parent aec8bbd commit 8a3e9f2

File tree

114 files changed

+121
-124
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

114 files changed

+121
-124
lines changed

library/alloc/src/collections/binary_heap/tests.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ fn test_drain_sorted() {
290290
}
291291

292292
#[test]
293+
#[cfg_attr(not(panic = "unwind"), should_panic)]
293294
fn test_drain_sorted_leak() {
294295
static DROPS: AtomicU32 = AtomicU32::new(0);
295296

@@ -411,9 +412,8 @@ fn test_retain() {
411412
// even if the order might not be correct.
412413
//
413414
// Destructors must be called exactly once per element.
414-
// FIXME: re-enable emscripten once it can unwind again
415415
#[test]
416-
#[cfg(not(target_os = "emscripten"))]
416+
#[cfg_attr(not(panic = "unwind"), should_panic)]
417417
fn panic_safe() {
418418
use rand::{seq::SliceRandom, thread_rng};
419419
use std::cmp;

library/alloc/src/collections/btree/map/tests.rs

+9
Original file line numberDiff line numberDiff line change
@@ -1122,6 +1122,7 @@ mod test_drain_filter {
11221122
}
11231123

11241124
#[test]
1125+
#[cfg_attr(not(panic = "unwind"), should_panic)]
11251126
fn drop_panic_leak() {
11261127
let a = CrashTestDummy::new(0);
11271128
let b = CrashTestDummy::new(1);
@@ -1142,6 +1143,7 @@ mod test_drain_filter {
11421143
}
11431144

11441145
#[test]
1146+
#[cfg_attr(not(panic = "unwind"), should_panic)]
11451147
fn pred_panic_leak() {
11461148
let a = CrashTestDummy::new(0);
11471149
let b = CrashTestDummy::new(1);
@@ -1168,6 +1170,7 @@ mod test_drain_filter {
11681170

11691171
// Same as above, but attempt to use the iterator again after the panic in the predicate
11701172
#[test]
1173+
#[cfg_attr(not(panic = "unwind"), should_panic)]
11711174
fn pred_panic_reuse() {
11721175
let a = CrashTestDummy::new(0);
11731176
let b = CrashTestDummy::new(1);
@@ -1416,6 +1419,7 @@ fn test_clear() {
14161419
}
14171420

14181421
#[test]
1422+
#[cfg_attr(not(panic = "unwind"), should_panic)]
14191423
fn test_clear_drop_panic_leak() {
14201424
let a = CrashTestDummy::new(0);
14211425
let b = CrashTestDummy::new(1);
@@ -1507,11 +1511,13 @@ fn test_clone_panic_leak(size: usize) {
15071511
}
15081512

15091513
#[test]
1514+
#[cfg_attr(not(panic = "unwind"), should_panic)]
15101515
fn test_clone_panic_leak_height_0() {
15111516
test_clone_panic_leak(3)
15121517
}
15131518

15141519
#[test]
1520+
#[cfg_attr(not(panic = "unwind"), should_panic)]
15151521
fn test_clone_panic_leak_height_1() {
15161522
test_clone_panic_leak(MIN_INSERTS_HEIGHT_1)
15171523
}
@@ -2066,6 +2072,7 @@ create_append_test!(test_append_239, 239);
20662072
create_append_test!(test_append_1700, 1700);
20672073

20682074
#[test]
2075+
#[cfg_attr(not(panic = "unwind"), should_panic)]
20692076
fn test_append_drop_leak() {
20702077
let a = CrashTestDummy::new(0);
20712078
let b = CrashTestDummy::new(1);
@@ -2207,6 +2214,7 @@ fn test_split_off_large_random_sorted() {
22072214
}
22082215

22092216
#[test]
2217+
#[cfg_attr(not(panic = "unwind"), should_panic)]
22102218
fn test_into_iter_drop_leak_height_0() {
22112219
let a = CrashTestDummy::new(0);
22122220
let b = CrashTestDummy::new(1);
@@ -2230,6 +2238,7 @@ fn test_into_iter_drop_leak_height_0() {
22302238
}
22312239

22322240
#[test]
2241+
#[cfg_attr(not(panic = "unwind"), should_panic)]
22332242
fn test_into_iter_drop_leak_height_1() {
22342243
let size = MIN_INSERTS_HEIGHT_1;
22352244
for panic_point in vec![0, 1, size - 2, size - 1] {

library/alloc/src/collections/btree/set/tests.rs

+2
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,7 @@ fn test_drain_filter() {
377377
}
378378

379379
#[test]
380+
#[cfg_attr(not(panic = "unwind"), should_panic)]
380381
fn test_drain_filter_drop_panic_leak() {
381382
let a = CrashTestDummy::new(0);
382383
let b = CrashTestDummy::new(1);
@@ -397,6 +398,7 @@ fn test_drain_filter_drop_panic_leak() {
397398
}
398399

399400
#[test]
401+
#[cfg_attr(not(panic = "unwind"), should_panic)]
400402
fn test_drain_filter_pred_panic_leak() {
401403
let a = CrashTestDummy::new(0);
402404
let b = CrashTestDummy::new(1);

library/alloc/src/collections/linked_list/tests.rs

+3
Original file line numberDiff line numberDiff line change
@@ -983,6 +983,7 @@ fn drain_filter_complex() {
983983
}
984984

985985
#[test]
986+
#[cfg_attr(not(panic = "unwind"), should_panic)]
986987
fn drain_filter_drop_panic_leak() {
987988
static mut DROPS: i32 = 0;
988989

@@ -1017,6 +1018,7 @@ fn drain_filter_drop_panic_leak() {
10171018
}
10181019

10191020
#[test]
1021+
#[cfg_attr(not(panic = "unwind"), should_panic)]
10201022
fn drain_filter_pred_panic_leak() {
10211023
static mut DROPS: i32 = 0;
10221024

@@ -1123,6 +1125,7 @@ fn test_drop_clear() {
11231125
}
11241126

11251127
#[test]
1128+
#[cfg_attr(not(panic = "unwind"), should_panic)]
11261129
fn test_drop_panic() {
11271130
static mut DROPS: i32 = 0;
11281131

library/alloc/tests/slice.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1539,8 +1539,8 @@ fn test_box_slice_clone() {
15391539
}
15401540

15411541
#[test]
1542+
#[cfg_attr(not(panic = "unwind"), should_panic)]
15421543
#[allow(unused_must_use)] // here, we care about the side effects of `.clone()`
1543-
#[cfg_attr(target_os = "emscripten", ignore)]
15441544
fn test_box_slice_clone_panics() {
15451545
use std::sync::atomic::{AtomicUsize, Ordering};
15461546
use std::sync::Arc;
@@ -1782,6 +1782,7 @@ thread_local!(static SILENCE_PANIC: Cell<bool> = Cell::new(false));
17821782

17831783
#[test]
17841784
#[cfg_attr(target_os = "emscripten", ignore)] // no threads
1785+
#[cfg_attr(not(panic = "unwind"), should_panic)]
17851786
fn panic_safe() {
17861787
panic::update_hook(move |prev, info| {
17871788
if !SILENCE_PANIC.with(|s| s.get()) {

library/alloc/tests/string.rs

+4
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,11 @@ fn test_retain() {
411411

412412
s.retain(|_| false);
413413
assert_eq!(s, "");
414+
}
414415

416+
#[test]
417+
#[cfg_attr(not(panic = "unwind"), should_panic)]
418+
fn test_retain_panic() {
415419
let mut s = String::from("0è0");
416420
let _ = panic::catch_unwind(panic::AssertUnwindSafe(|| {
417421
let mut count = 0;

library/alloc/tests/vec.rs

+11-4
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@ fn test_retain() {
293293
}
294294

295295
#[test]
296+
#[cfg_attr(not(panic = "unwind"), should_panic)]
296297
fn test_retain_pred_panic_with_hole() {
297298
let v = (0..5).map(Rc::new).collect::<Vec<_>>();
298299
catch_unwind(AssertUnwindSafe(|| {
@@ -310,6 +311,7 @@ fn test_retain_pred_panic_with_hole() {
310311
}
311312

312313
#[test]
314+
#[cfg_attr(not(panic = "unwind"), should_panic)]
313315
fn test_retain_pred_panic_no_hole() {
314316
let v = (0..5).map(Rc::new).collect::<Vec<_>>();
315317
catch_unwind(AssertUnwindSafe(|| {
@@ -325,6 +327,7 @@ fn test_retain_pred_panic_no_hole() {
325327
}
326328

327329
#[test]
330+
#[cfg_attr(not(panic = "unwind"), should_panic)]
328331
fn test_retain_drop_panic() {
329332
struct Wrap(Rc<i32>);
330333

@@ -756,6 +759,7 @@ fn test_drain_end_overflow() {
756759
}
757760

758761
#[test]
762+
#[cfg_attr(not(panic = "unwind"), should_panic)]
759763
fn test_drain_leak() {
760764
static mut DROPS: i32 = 0;
761765

@@ -949,6 +953,7 @@ fn test_into_iter_clone() {
949953
}
950954

951955
#[test]
956+
#[cfg_attr(not(panic = "unwind"), should_panic)]
952957
fn test_into_iter_leak() {
953958
static mut DROPS: i32 = 0;
954959

@@ -1076,6 +1081,7 @@ fn test_from_iter_specialization_head_tail_drop() {
10761081
}
10771082

10781083
#[test]
1084+
#[cfg_attr(not(panic = "unwind"), should_panic)]
10791085
fn test_from_iter_specialization_panic_during_iteration_drops() {
10801086
let drop_count: Vec<_> = (0..=2).map(|_| Rc::new(())).collect();
10811087
let src: Vec<_> = drop_count.iter().cloned().collect();
@@ -1100,6 +1106,7 @@ fn test_from_iter_specialization_panic_during_iteration_drops() {
11001106
}
11011107

11021108
#[test]
1109+
#[cfg_attr(not(panic = "unwind"), should_panic)]
11031110
fn test_from_iter_specialization_panic_during_drop_leaks() {
11041111
static mut DROP_COUNTER: usize = 0;
11051112

@@ -1367,9 +1374,8 @@ fn drain_filter_complex() {
13671374
}
13681375
}
13691376

1370-
// FIXME: re-enable emscripten once it can unwind again
13711377
#[test]
1372-
#[cfg(not(target_os = "emscripten"))]
1378+
#[cfg_attr(not(panic = "unwind"), should_panic)]
13731379
fn drain_filter_consumed_panic() {
13741380
use std::rc::Rc;
13751381
use std::sync::Mutex;
@@ -1419,9 +1425,8 @@ fn drain_filter_consumed_panic() {
14191425
}
14201426
}
14211427

1422-
// FIXME: Re-enable emscripten once it can catch panics
14231428
#[test]
1424-
#[cfg(not(target_os = "emscripten"))]
1429+
#[cfg_attr(not(panic = "unwind"), should_panic)]
14251430
fn drain_filter_unconsumed_panic() {
14261431
use std::rc::Rc;
14271432
use std::sync::Mutex;
@@ -2314,6 +2319,7 @@ fn test_vec_dedup() {
23142319
}
23152320

23162321
#[test]
2322+
#[cfg_attr(not(panic = "unwind"), should_panic)]
23172323
fn test_vec_dedup_panicking() {
23182324
#[derive(Debug)]
23192325
struct Panic<'a> {
@@ -2370,6 +2376,7 @@ fn test_vec_dedup_panicking() {
23702376

23712377
// Regression test for issue #82533
23722378
#[test]
2379+
#[cfg_attr(not(panic = "unwind"), should_panic)]
23732380
fn test_extend_from_within_panicing_clone() {
23742381
struct Panic<'dc> {
23752382
drop_count: &'dc AtomicU32,

library/alloc/tests/vec_deque.rs

+3
Original file line numberDiff line numberDiff line change
@@ -726,6 +726,7 @@ fn test_drop_clear() {
726726
}
727727

728728
#[test]
729+
#[cfg_attr(not(panic = "unwind"), should_panic)]
729730
fn test_drop_panic() {
730731
static mut DROPS: i32 = 0;
731732

@@ -1620,6 +1621,7 @@ fn test_try_rfold_moves_iter() {
16201621
}
16211622

16221623
#[test]
1624+
#[cfg_attr(not(panic = "unwind"), should_panic)]
16231625
fn truncate_leak() {
16241626
static mut DROPS: i32 = 0;
16251627

@@ -1653,6 +1655,7 @@ fn truncate_leak() {
16531655
}
16541656

16551657
#[test]
1658+
#[cfg_attr(not(panic = "unwind"), should_panic)]
16561659
fn test_drain_leak() {
16571660
static mut DROPS: i32 = 0;
16581661

library/core/tests/array.rs

+5-15
Original file line numberDiff line numberDiff line change
@@ -256,14 +256,8 @@ fn iterator_drops() {
256256
assert_eq!(i.get(), 5);
257257
}
258258

259-
// This test does not work on targets without panic=unwind support.
260-
// To work around this problem, test is marked is should_panic, so it will
261-
// be automagically skipped on unsuitable targets, such as
262-
// wasm32-unknown-unknown.
263-
//
264-
// It means that we use panic for indicating success.
265-
#[test]
266-
#[should_panic(expected = "test succeeded")]
259+
#[test]
260+
#[cfg_attr(not(panic = "unwind"), should_panic)]
267261
fn array_default_impl_avoids_leaks_on_panic() {
268262
use core::sync::atomic::{AtomicUsize, Ordering::Relaxed};
269263
static COUNTER: AtomicUsize = AtomicUsize::new(0);
@@ -295,7 +289,6 @@ fn array_default_impl_avoids_leaks_on_panic() {
295289
assert_eq!(*panic_msg, "bomb limit exceeded");
296290
// check that all bombs are successfully dropped
297291
assert_eq!(COUNTER.load(Relaxed), 0);
298-
panic!("test succeeded")
299292
}
300293

301294
#[test]
@@ -316,9 +309,8 @@ fn array_map() {
316309
assert_eq!(b, [1, 2, 3]);
317310
}
318311

319-
// See note on above test for why `should_panic` is used.
320312
#[test]
321-
#[should_panic(expected = "test succeeded")]
313+
#[cfg_attr(not(panic = "unwind"), should_panic)]
322314
fn array_map_drop_safety() {
323315
static DROPPED: AtomicUsize = AtomicUsize::new(0);
324316
struct DropCounter;
@@ -340,7 +332,6 @@ fn array_map_drop_safety() {
340332
});
341333
assert!(success.is_err());
342334
assert_eq!(DROPPED.load(Ordering::SeqCst), num_to_create);
343-
panic!("test succeeded")
344335
}
345336

346337
#[test]
@@ -392,8 +383,8 @@ fn array_try_from_fn() {
392383
assert_eq!(another_array, Err(SomeError::Foo));
393384
}
394385

395-
#[cfg(not(panic = "abort"))]
396386
#[test]
387+
#[cfg_attr(not(panic = "unwind"), should_panic)]
397388
fn array_try_from_fn_drops_inserted_elements_on_err() {
398389
static DROP_COUNTER: AtomicUsize = AtomicUsize::new(0);
399390

@@ -416,8 +407,8 @@ fn array_try_from_fn_drops_inserted_elements_on_err() {
416407
assert_eq!(DROP_COUNTER.load(Ordering::SeqCst), 2);
417408
}
418409

419-
#[cfg(not(panic = "abort"))]
420410
#[test]
411+
#[cfg_attr(not(panic = "unwind"), should_panic)]
421412
fn array_try_from_fn_drops_inserted_elements_on_panic() {
422413
static DROP_COUNTER: AtomicUsize = AtomicUsize::new(0);
423414

@@ -440,7 +431,6 @@ fn array_try_from_fn_drops_inserted_elements_on_panic() {
440431
assert_eq!(DROP_COUNTER.load(Ordering::SeqCst), 2);
441432
}
442433

443-
#[cfg(not(panic = "abort"))]
444434
// https://stackoverflow.com/a/59211505
445435
fn catch_unwind_silent<F, R>(f: F) -> std::thread::Result<R>
446436
where

library/core/tests/iter/adapters/zip.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ fn test_zip_trusted_random_access_composition() {
233233
}
234234

235235
#[test]
236-
#[cfg(panic = "unwind")]
236+
#[cfg_attr(not(panic = "unwind"), should_panic)]
237237
fn test_zip_trusted_random_access_next_back_drop() {
238238
use std::panic::catch_unwind;
239239
use std::panic::AssertUnwindSafe;

library/core/tests/mem.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use core::mem::*;
22

3-
#[cfg(panic = "unwind")]
43
use std::rc::Rc;
54

65
#[test]
@@ -190,7 +189,7 @@ fn uninit_write_slice_cloned_panic_gt() {
190189
}
191190

192191
#[test]
193-
#[cfg(panic = "unwind")]
192+
#[cfg_attr(not(panic = "unwind"), should_panic)]
194193
fn uninit_write_slice_cloned_mid_panic() {
195194
use std::panic;
196195

library/std/src/collections/hash/map/tests.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1013,6 +1013,7 @@ mod test_drain_filter {
10131013
}
10141014

10151015
#[test]
1016+
#[cfg_attr(not(panic = "unwind"), should_panic)]
10161017
fn drop_panic_leak() {
10171018
static PREDS: AtomicUsize = AtomicUsize::new(0);
10181019
static DROPS: AtomicUsize = AtomicUsize::new(0);
@@ -1041,6 +1042,7 @@ mod test_drain_filter {
10411042
}
10421043

10431044
#[test]
1045+
#[cfg_attr(not(panic = "unwind"), should_panic)]
10441046
fn pred_panic_leak() {
10451047
static PREDS: AtomicUsize = AtomicUsize::new(0);
10461048
static DROPS: AtomicUsize = AtomicUsize::new(0);
@@ -1069,6 +1071,7 @@ mod test_drain_filter {
10691071

10701072
// Same as above, but attempt to use the iterator again after the panic in the predicate
10711073
#[test]
1074+
#[cfg_attr(not(panic = "unwind"), should_panic)]
10721075
fn pred_panic_reuse() {
10731076
static PREDS: AtomicUsize = AtomicUsize::new(0);
10741077
static DROPS: AtomicUsize = AtomicUsize::new(0);

0 commit comments

Comments
 (0)