|
1 | 1 | use super::*; |
2 | 2 | use crate::boxed::Box; |
| 3 | +use crate::testing::crash_test::{CrashTestDummy, Panic}; |
3 | 4 | use std::iter::TrustedLen; |
4 | 5 | use std::panic::{catch_unwind, AssertUnwindSafe}; |
5 | | -use std::sync::atomic::{AtomicU32, Ordering}; |
6 | 6 |
|
7 | 7 | #[test] |
8 | 8 | fn test_iterator() { |
@@ -291,33 +291,30 @@ fn test_drain_sorted() { |
291 | 291 |
|
292 | 292 | #[test] |
293 | 293 | fn test_drain_sorted_leak() { |
294 | | - static DROPS: AtomicU32 = AtomicU32::new(0); |
295 | | - |
296 | | - #[derive(Clone, PartialEq, Eq, PartialOrd, Ord)] |
297 | | - struct D(u32, bool); |
298 | | - |
299 | | - impl Drop for D { |
300 | | - fn drop(&mut self) { |
301 | | - DROPS.fetch_add(1, Ordering::SeqCst); |
302 | | - |
303 | | - if self.1 { |
304 | | - panic!("panic in `drop`"); |
305 | | - } |
306 | | - } |
307 | | - } |
308 | | - |
| 294 | + let d0 = CrashTestDummy::new(0); |
| 295 | + let d1 = CrashTestDummy::new(1); |
| 296 | + let d2 = CrashTestDummy::new(2); |
| 297 | + let d3 = CrashTestDummy::new(3); |
| 298 | + let d4 = CrashTestDummy::new(4); |
| 299 | + let d5 = CrashTestDummy::new(5); |
309 | 300 | let mut q = BinaryHeap::from(vec![ |
310 | | - D(0, false), |
311 | | - D(1, false), |
312 | | - D(2, false), |
313 | | - D(3, true), |
314 | | - D(4, false), |
315 | | - D(5, false), |
| 301 | + d0.spawn(Panic::Never), |
| 302 | + d1.spawn(Panic::Never), |
| 303 | + d2.spawn(Panic::Never), |
| 304 | + d3.spawn(Panic::InDrop), |
| 305 | + d4.spawn(Panic::Never), |
| 306 | + d5.spawn(Panic::Never), |
316 | 307 | ]); |
317 | 308 |
|
318 | | - catch_unwind(AssertUnwindSafe(|| drop(q.drain_sorted()))).ok(); |
| 309 | + catch_unwind(AssertUnwindSafe(|| drop(q.drain_sorted()))).unwrap_err(); |
319 | 310 |
|
320 | | - assert_eq!(DROPS.load(Ordering::SeqCst), 6); |
| 311 | + assert_eq!(d0.dropped(), 1); |
| 312 | + assert_eq!(d1.dropped(), 1); |
| 313 | + assert_eq!(d2.dropped(), 1); |
| 314 | + assert_eq!(d3.dropped(), 1); |
| 315 | + assert_eq!(d4.dropped(), 1); |
| 316 | + assert_eq!(d5.dropped(), 1); |
| 317 | + assert!(q.is_empty()); |
321 | 318 | } |
322 | 319 |
|
323 | 320 | #[test] |
|
0 commit comments