#assert-eq #failure #cleanup #statement #assert-ne

cleanass

Enhances assert, assert_eq and assert_ne with cleanup statement which runs on failure

1 unstable release

0.0.1 Nov 28, 2024

#27 in #statement

Download history 43/week @ 2025-06-18 13/week @ 2025-07-02 48/week @ 2025-07-09 33/week @ 2025-07-16 8/week @ 2025-07-23 10/week @ 2025-07-30 58/week @ 2025-08-06 58/week @ 2025-08-13 38/week @ 2025-08-20 39/week @ 2025-09-03 22/week @ 2025-09-10 14/week @ 2025-09-17 3/week @ 2025-09-24 18/week @ 2025-10-01

62 downloads per month

MIT license

92KB
150 lines

cleanass

Crates.io Docs.rs

Enhances assert, assert_eq and assert_ne with cleanup statement which runs on failure.

Usage

Import use cleanass::{assert_eq, assert_ne, assert}; and use them as you would the built-in versions or pass in a closure which runs whenever an assertion fails.

use cleanass::assert_ne;

pub fn main() {
    // If assert succeeds nothing is printed since cleanup function does not run
    {
        let a = 1;
        let b = 2;
        assert_ne!(a, b, eprintln!("Cleanup: {} != {} succeeded", a, b));
    }
    // If assert fails the cleanup function runs and prints the message
    {
        let a = 1;
        let b = 1;
        assert_ne!(
            a, b,
            eprintln!("Cleanup: {} != {} failed", a, b),
            "Should not be equal"
        );
    }
}

Features

strict

  • disables versions of the assertions that don't require a closure ensuring that you don't accidentally forget to add a cleanup function
  • is on by default

LICENSE

MIT

No runtime deps

Features