#![cfg(feature = "panic_on_next_alloc")]
use alloc_tracker::{Allocator, panic_on_next_alloc};
use serial_test::serial;
#[global_allocator]
static ALLOCATOR: Allocator<std::alloc::System> = Allocator::system();
#[test]
#[cfg_attr(miri, ignore)] #[serial]
fn panic_on_next_alloc_can_be_controlled() {
panic_on_next_alloc(false);
#[expect(
clippy::useless_vec,
reason = "we need actual allocation to test the feature"
)]
let _allowed_allocation = vec![1, 2, 3];
panic_on_next_alloc(true);
panic_on_next_alloc(false);
#[expect(
clippy::useless_vec,
reason = "we need actual allocation to test the feature"
)]
let _another_allowed_allocation = vec![4, 5, 6];
}
#[test]
#[cfg_attr(miri, ignore)] #[serial]
fn panic_on_next_alloc_resets_automatically() {
use std::panic;
panic_on_next_alloc(true);
let result = panic::catch_unwind(|| {
#[expect(
clippy::useless_vec,
reason = "we need actual allocation to test the feature"
)]
let _vec = vec![1, 2, 3];
});
assert!(result.is_err());
#[expect(
clippy::useless_vec,
reason = "we need actual allocation to test the feature"
)]
let _allowed_allocation = vec![4, 5, 6];
}