Crates.io | arsert |
lib.rs | arsert |
version | 0.0.2 |
source | src |
created_at | 2019-01-12 22:11:55.118082 |
updated_at | 2019-01-12 22:11:55.118082 |
description | Assertions that provide more sophisticated failure messages |
homepage | |
repository | https://github.com/antifuchs/arsert |
max_upload_size | |
id | 108225 |
size | 19,786 |
This crate allows you to write assertions like you would with a
builtin [assert
][assert], but when the assertion fails, it outputs
diagnostic information about the parameters to the assertion.
Here's a failing assertion:
use arsert::arsert;
let x = 1;
let y: i32 = 2;
arsert!(x >= y.pow(3));
This outputs:
thread 'main' panicked at 'x >= y . pow ( 3 )
x = 1
y . pow ( 3 ) = 8', arsert_failure/src/lib.rs:23:5
Here's a successful one:
use arsert::arsert;
let x = 20 as i64;
arsert!(x <= x.pow(3));
Right now, arsert supports "simple" assertions (very much like
assert does), unary assertions (e.g. *foo
and !foo
), and
assertions on binary operations, like ==
, >
, &&
and so on.
I'm working on more supported expressions (and maybe, once proc_macros as statements get stabilized, an extension mechanism).
Sorry for the toilet humor (everybody poops, y'all). Name improvement suggestions gladly accepted, provided the resulting name is terse and meaningful.
License: MIT