rust-assert-no-alloc
rust-assert-no-alloc copied to clipboard
Support #[should_panic]
cargo test --all-targets --all-features --locked --frozen --offline
// Passes
#[test]
fn does_not_alloc() {
assert_no_alloc(|| {
let xs: Vec<i64> = Vec::with_capacity(0);
assert_eq!(0, xs.capacity());
});
}
// Crashes without even printing test name, just shows:
// memory allocation of 336 bytes failed
// Sometimes even messes up stdout's flushing.
#[test]
#[should_panic]
fn does_actually_alloc() {
assert_no_alloc(|| {
let xs: Vec<i64> = Vec::with_capacity(42);
assert_eq!(42, xs.capacity());
});
}
I was expecting at least the test name to print. But really I'd like to be able to use should_panic.
Thanks for this crate and please advise!
The problem is that this crate does really bad things such as panicking inside of an allocator. I'd rather use the warn_debug feature flag when testing and then use https://docs.rs/assert_no_alloc/latest/assert_no_alloc/fn.violation_count.html to check if there has been a violation.