You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
davidv1992 opened this issue
Sep 6, 2024
· 2 comments
Labels
A-libtestArea: `#[test]` / the `test` libraryC-bugCategory: This is a bug.T-libsRelevant to the library team, which will review and decide on the PR/issue.
When writing tests for custom allocators, I ran into the problem that an allocation-induced panic is not captured properly by should_panic. This is in my opinion a bug, as the behaviour the test shows is still very much like a panic.
Example code to trigger the issue:
use core::alloc::Layout;
use alloc::alloc::handle_alloc_error
#[test]
#[should_panic]
fn sample_test() {
let layout = Layout::new::<u64>();
handle_alloc_error(layout);
}
this uses an explicit call to handle_alloc_error, but the actual test cases I am writing create Vectors with a custom allocator that limits the amount of memory that can be allocated, which is a more realistic use case.
The default alloc error handler creates a non-unwinding panic, which breaks #[should_panic], because that feature, like all of libtest, is based on catching unwinds.
saethlin
added
A-libtest
Area: `#[test]` / the `test` library
T-libs
Relevant to the library team, which will review and decide on the PR/issue.
and removed
needs-triage
This issue may need triage. Remove it if it has been sufficiently triaged.
labels
Sep 6, 2024
A-libtestArea: `#[test]` / the `test` libraryC-bugCategory: This is a bug.T-libsRelevant to the library team, which will review and decide on the PR/issue.
When writing tests for custom allocators, I ran into the problem that an allocation-induced panic is not captured properly by should_panic. This is in my opinion a bug, as the behaviour the test shows is still very much like a panic.
Example code to trigger the issue:
this uses an explicit call to handle_alloc_error, but the actual test cases I am writing create Vectors with a custom allocator that limits the amount of memory that can be allocated, which is a more realistic use case.
Meta
rustc --version --verbose
:The text was updated successfully, but these errors were encountered: