use catch_panic instead of thread::spawn to catch panics
This commit is contained in:
parent
1e91e4e20a
commit
3277209af5
1 changed files with 5 additions and 8 deletions
|
@ -4,7 +4,6 @@ use std::mem;
|
|||
use std::panic;
|
||||
use std::rc::Rc;
|
||||
use std::sync::atomic::{Ordering::Relaxed, AtomicUsize};
|
||||
use std::thread;
|
||||
|
||||
use rand::{Rng, RngCore, thread_rng};
|
||||
use rand::seq::SliceRandom;
|
||||
|
@ -1406,11 +1405,10 @@ fn test_box_slice_clone() {
|
|||
#[test]
|
||||
#[allow(unused_must_use)] // here, we care about the side effects of `.clone()`
|
||||
#[cfg_attr(target_os = "emscripten", ignore)]
|
||||
#[cfg(not(miri))] // Miri does not support threads
|
||||
#[cfg(not(miri))] // Miri does not support catching panics
|
||||
fn test_box_slice_clone_panics() {
|
||||
use std::sync::Arc;
|
||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||
use std::thread::spawn;
|
||||
|
||||
struct Canary {
|
||||
count: Arc<AtomicUsize>,
|
||||
|
@ -1446,7 +1444,7 @@ fn test_box_slice_clone_panics() {
|
|||
panics: true,
|
||||
};
|
||||
|
||||
spawn(move || {
|
||||
std::panic::catch_unwind(move || {
|
||||
// When xs is dropped, +5.
|
||||
let xs = vec![canary.clone(), canary.clone(), canary.clone(), panic, canary]
|
||||
.into_boxed_slice();
|
||||
|
@ -1454,7 +1452,6 @@ fn test_box_slice_clone_panics() {
|
|||
// When panic is cloned, +3.
|
||||
xs.clone();
|
||||
})
|
||||
.join()
|
||||
.unwrap_err();
|
||||
|
||||
// Total = 8
|
||||
|
@ -1566,7 +1563,7 @@ macro_rules! test {
|
|||
}
|
||||
|
||||
let v = $input.to_owned();
|
||||
let _ = thread::spawn(move || {
|
||||
let _ = std::panic::catch_unwind(move || {
|
||||
let mut v = v;
|
||||
let mut panic_countdown = panic_countdown;
|
||||
v.$func(|a, b| {
|
||||
|
@ -1577,7 +1574,7 @@ macro_rules! test {
|
|||
panic_countdown -= 1;
|
||||
a.cmp(b)
|
||||
})
|
||||
}).join();
|
||||
});
|
||||
|
||||
// Check that the number of things dropped is exactly
|
||||
// what we expect (i.e., the contents of `v`).
|
||||
|
@ -1598,7 +1595,7 @@ thread_local!(static SILENCE_PANIC: Cell<bool> = Cell::new(false));
|
|||
|
||||
#[test]
|
||||
#[cfg_attr(target_os = "emscripten", ignore)] // no threads
|
||||
#[cfg(not(miri))] // Miri does not support threads
|
||||
#[cfg(not(miri))] // Miri does not support catching panics
|
||||
fn panic_safe() {
|
||||
let prev = panic::take_hook();
|
||||
panic::set_hook(Box::new(move |info| {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue