diff options
| author | David Tolnay <dtolnay@gmail.com> | 2023-01-15 13:08:20 -0800 |
|---|---|---|
| committer | David Tolnay <dtolnay@gmail.com> | 2023-01-15 13:12:28 -0800 |
| commit | 0d3eaa848ce6b44a83502174eae16524c893dd28 (patch) | |
| tree | b83e2a577cf1922a83051304f0146d4e946af733 /library/alloc/src/collections/binary_heap | |
| parent | ae4d89dfb51535c1c43052ef848564bd2323c9ca (diff) | |
Add test showing broken behavior of BinaryHeap::retain
Diffstat (limited to 'library/alloc/src/collections/binary_heap')
| -rw-r--r-- | library/alloc/src/collections/binary_heap/tests.rs | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/library/alloc/src/collections/binary_heap/tests.rs b/library/alloc/src/collections/binary_heap/tests.rs index ffbb6c80ac0..835b2e5b7e9 100644 --- a/library/alloc/src/collections/binary_heap/tests.rs +++ b/library/alloc/src/collections/binary_heap/tests.rs @@ -474,6 +474,23 @@ fn test_retain() { assert!(a.is_empty()); } +#[test] +fn test_retain_catch_unwind() { + let mut heap = BinaryHeap::from(vec![3, 1, 2]); + + // Removes the 3, then unwinds out of retain. + let _ = catch_unwind(AssertUnwindSafe(|| { + heap.retain(|e| { + if *e == 1 { + panic!(); + } + false + }); + })); + + assert_eq!(heap.into_vec(), [1, 2]); // BAD!! +} + // old binaryheap failed this test // // Integrity means that all elements are present after a comparison panics, |
