Skip to content

Commit

Permalink
Ignore tests that require unwinding on targets that don't support it
Browse files Browse the repository at this point in the history
  • Loading branch information
Jules-Bertholet committed Jun 11, 2022
1 parent aec8bbd commit 8a3e9f2
Show file tree
Hide file tree
Showing 114 changed files with 121 additions and 124 deletions.
4 changes: 2 additions & 2 deletions library/alloc/src/collections/binary_heap/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ fn test_drain_sorted() {
}

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

Expand Down Expand Up @@ -411,9 +412,8 @@ fn test_retain() {
// even if the order might not be correct.
//
// Destructors must be called exactly once per element.
// FIXME: re-enable emscripten once it can unwind again
#[test]
#[cfg(not(target_os = "emscripten"))]
#[cfg_attr(not(panic = "unwind"), should_panic)]
fn panic_safe() {
use rand::{seq::SliceRandom, thread_rng};
use std::cmp;
Expand Down
9 changes: 9 additions & 0 deletions library/alloc/src/collections/btree/map/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1122,6 +1122,7 @@ mod test_drain_filter {
}

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

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

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

#[test]
#[cfg_attr(not(panic = "unwind"), should_panic)]
fn test_clear_drop_panic_leak() {
let a = CrashTestDummy::new(0);
let b = CrashTestDummy::new(1);
Expand Down Expand Up @@ -1507,11 +1511,13 @@ fn test_clone_panic_leak(size: usize) {
}

#[test]
#[cfg_attr(not(panic = "unwind"), should_panic)]
fn test_clone_panic_leak_height_0() {
test_clone_panic_leak(3)
}

#[test]
#[cfg_attr(not(panic = "unwind"), should_panic)]
fn test_clone_panic_leak_height_1() {
test_clone_panic_leak(MIN_INSERTS_HEIGHT_1)
}
Expand Down Expand Up @@ -2066,6 +2072,7 @@ create_append_test!(test_append_239, 239);
create_append_test!(test_append_1700, 1700);

#[test]
#[cfg_attr(not(panic = "unwind"), should_panic)]
fn test_append_drop_leak() {
let a = CrashTestDummy::new(0);
let b = CrashTestDummy::new(1);
Expand Down Expand Up @@ -2207,6 +2214,7 @@ fn test_split_off_large_random_sorted() {
}

#[test]
#[cfg_attr(not(panic = "unwind"), should_panic)]
fn test_into_iter_drop_leak_height_0() {
let a = CrashTestDummy::new(0);
let b = CrashTestDummy::new(1);
Expand All @@ -2230,6 +2238,7 @@ fn test_into_iter_drop_leak_height_0() {
}

#[test]
#[cfg_attr(not(panic = "unwind"), should_panic)]
fn test_into_iter_drop_leak_height_1() {
let size = MIN_INSERTS_HEIGHT_1;
for panic_point in vec![0, 1, size - 2, size - 1] {
Expand Down
2 changes: 2 additions & 0 deletions library/alloc/src/collections/btree/set/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@ fn test_drain_filter() {
}

#[test]
#[cfg_attr(not(panic = "unwind"), should_panic)]
fn test_drain_filter_drop_panic_leak() {
let a = CrashTestDummy::new(0);
let b = CrashTestDummy::new(1);
Expand All @@ -397,6 +398,7 @@ fn test_drain_filter_drop_panic_leak() {
}

#[test]
#[cfg_attr(not(panic = "unwind"), should_panic)]
fn test_drain_filter_pred_panic_leak() {
let a = CrashTestDummy::new(0);
let b = CrashTestDummy::new(1);
Expand Down
3 changes: 3 additions & 0 deletions library/alloc/src/collections/linked_list/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -983,6 +983,7 @@ fn drain_filter_complex() {
}

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

Expand Down Expand Up @@ -1017,6 +1018,7 @@ fn drain_filter_drop_panic_leak() {
}

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

Expand Down Expand Up @@ -1123,6 +1125,7 @@ fn test_drop_clear() {
}

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

Expand Down
3 changes: 2 additions & 1 deletion library/alloc/tests/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1539,8 +1539,8 @@ fn test_box_slice_clone() {
}

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

#[test]
#[cfg_attr(target_os = "emscripten", ignore)] // no threads
#[cfg_attr(not(panic = "unwind"), should_panic)]
fn panic_safe() {
panic::update_hook(move |prev, info| {
if !SILENCE_PANIC.with(|s| s.get()) {
Expand Down
4 changes: 4 additions & 0 deletions library/alloc/tests/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,11 @@ fn test_retain() {

s.retain(|_| false);
assert_eq!(s, "");
}

#[test]
#[cfg_attr(not(panic = "unwind"), should_panic)]
fn test_retain_panic() {
let mut s = String::from("0è0");
let _ = panic::catch_unwind(panic::AssertUnwindSafe(|| {
let mut count = 0;
Expand Down
15 changes: 11 additions & 4 deletions library/alloc/tests/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ fn test_retain() {
}

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

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

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

Expand Down Expand Up @@ -756,6 +759,7 @@ fn test_drain_end_overflow() {
}

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

Expand Down Expand Up @@ -949,6 +953,7 @@ fn test_into_iter_clone() {
}

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

Expand Down Expand Up @@ -1076,6 +1081,7 @@ fn test_from_iter_specialization_head_tail_drop() {
}

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

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

Expand Down Expand Up @@ -1367,9 +1374,8 @@ fn drain_filter_complex() {
}
}

// FIXME: re-enable emscripten once it can unwind again
#[test]
#[cfg(not(target_os = "emscripten"))]
#[cfg_attr(not(panic = "unwind"), should_panic)]
fn drain_filter_consumed_panic() {
use std::rc::Rc;
use std::sync::Mutex;
Expand Down Expand Up @@ -1419,9 +1425,8 @@ fn drain_filter_consumed_panic() {
}
}

// FIXME: Re-enable emscripten once it can catch panics
#[test]
#[cfg(not(target_os = "emscripten"))]
#[cfg_attr(not(panic = "unwind"), should_panic)]
fn drain_filter_unconsumed_panic() {
use std::rc::Rc;
use std::sync::Mutex;
Expand Down Expand Up @@ -2314,6 +2319,7 @@ fn test_vec_dedup() {
}

#[test]
#[cfg_attr(not(panic = "unwind"), should_panic)]
fn test_vec_dedup_panicking() {
#[derive(Debug)]
struct Panic<'a> {
Expand Down Expand Up @@ -2370,6 +2376,7 @@ fn test_vec_dedup_panicking() {

// Regression test for issue #82533
#[test]
#[cfg_attr(not(panic = "unwind"), should_panic)]
fn test_extend_from_within_panicing_clone() {
struct Panic<'dc> {
drop_count: &'dc AtomicU32,
Expand Down
3 changes: 3 additions & 0 deletions library/alloc/tests/vec_deque.rs
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,7 @@ fn test_drop_clear() {
}

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

Expand Down Expand Up @@ -1620,6 +1621,7 @@ fn test_try_rfold_moves_iter() {
}

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

Expand Down Expand Up @@ -1653,6 +1655,7 @@ fn truncate_leak() {
}

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

Expand Down
20 changes: 5 additions & 15 deletions library/core/tests/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,14 +256,8 @@ fn iterator_drops() {
assert_eq!(i.get(), 5);
}

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

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

// See note on above test for why `should_panic` is used.
#[test]
#[should_panic(expected = "test succeeded")]
#[cfg_attr(not(panic = "unwind"), should_panic)]
fn array_map_drop_safety() {
static DROPPED: AtomicUsize = AtomicUsize::new(0);
struct DropCounter;
Expand All @@ -340,7 +332,6 @@ fn array_map_drop_safety() {
});
assert!(success.is_err());
assert_eq!(DROPPED.load(Ordering::SeqCst), num_to_create);
panic!("test succeeded")
}

#[test]
Expand Down Expand Up @@ -392,8 +383,8 @@ fn array_try_from_fn() {
assert_eq!(another_array, Err(SomeError::Foo));
}

#[cfg(not(panic = "abort"))]
#[test]
#[cfg_attr(not(panic = "unwind"), should_panic)]
fn array_try_from_fn_drops_inserted_elements_on_err() {
static DROP_COUNTER: AtomicUsize = AtomicUsize::new(0);

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

#[cfg(not(panic = "abort"))]
#[test]
#[cfg_attr(not(panic = "unwind"), should_panic)]
fn array_try_from_fn_drops_inserted_elements_on_panic() {
static DROP_COUNTER: AtomicUsize = AtomicUsize::new(0);

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

#[cfg(not(panic = "abort"))]
// https://stackoverflow.com/a/59211505
fn catch_unwind_silent<F, R>(f: F) -> std::thread::Result<R>
where
Expand Down
2 changes: 1 addition & 1 deletion library/core/tests/iter/adapters/zip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ fn test_zip_trusted_random_access_composition() {
}

#[test]
#[cfg(panic = "unwind")]
#[cfg_attr(not(panic = "unwind"), should_panic)]
fn test_zip_trusted_random_access_next_back_drop() {
use std::panic::catch_unwind;
use std::panic::AssertUnwindSafe;
Expand Down
3 changes: 1 addition & 2 deletions library/core/tests/mem.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use core::mem::*;

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

#[test]
Expand Down Expand Up @@ -190,7 +189,7 @@ fn uninit_write_slice_cloned_panic_gt() {
}

#[test]
#[cfg(panic = "unwind")]
#[cfg_attr(not(panic = "unwind"), should_panic)]
fn uninit_write_slice_cloned_mid_panic() {
use std::panic;

Expand Down
3 changes: 3 additions & 0 deletions library/std/src/collections/hash/map/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1013,6 +1013,7 @@ mod test_drain_filter {
}

#[test]
#[cfg_attr(not(panic = "unwind"), should_panic)]
fn drop_panic_leak() {
static PREDS: AtomicUsize = AtomicUsize::new(0);
static DROPS: AtomicUsize = AtomicUsize::new(0);
Expand Down Expand Up @@ -1041,6 +1042,7 @@ mod test_drain_filter {
}

#[test]
#[cfg_attr(not(panic = "unwind"), should_panic)]
fn pred_panic_leak() {
static PREDS: AtomicUsize = AtomicUsize::new(0);
static DROPS: AtomicUsize = AtomicUsize::new(0);
Expand Down Expand Up @@ -1069,6 +1071,7 @@ mod test_drain_filter {

// Same as above, but attempt to use the iterator again after the panic in the predicate
#[test]
#[cfg_attr(not(panic = "unwind"), should_panic)]
fn pred_panic_reuse() {
static PREDS: AtomicUsize = AtomicUsize::new(0);
static DROPS: AtomicUsize = AtomicUsize::new(0);
Expand Down
Loading

0 comments on commit 8a3e9f2

Please sign in to comment.