rust-assert-no-alloc icon indicating copy to clipboard operation
rust-assert-no-alloc copied to clipboard

Support #[should_panic]

Open fenollp opened this issue 3 years ago • 1 comments

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!

fenollp avatar Sep 08 '22 15:09 fenollp

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.

Windfisch avatar Oct 06 '22 15:10 Windfisch