| Crates.io | cleanass |
| lib.rs | cleanass |
| version | 0.0.1 |
| created_at | 2024-11-28 04:45:04.6297+00 |
| updated_at | 2024-11-28 04:45:04.6297+00 |
| description | Enhances assert, assert_eq and assert_ne with cleanup statement which runs on failure |
| homepage | |
| repository | https://github.com/thlorenz/cleanass |
| max_upload_size | |
| id | 1463919 |
| size | 95,062 |

Enhances assert, assert_eq and assert_ne with cleanup statement which runs on failure.
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"
);
}
}
strictMIT