Open davidv1992 opened 2 months ago
Note, workaround for the time being is to add
std::alloc::set_alloc_error_hook(|layout| panic!("memory allocation of {} bytes failed", layout.size()));
to the start of each test case. Not ideal, but workable.
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.
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
: