bassert

Crates.iobassert
lib.rsbassert
version0.0.4
sourcesrc
created_at2014-11-28 21:36:17.396166
updated_at2015-12-11 23:57:49.028558
descriptionA Better Assert macro This macro will print out the values of each side of an expression and also the values of function arguments.
homepage
repositoryhttps://github.com/scialex/bassert
max_upload_size
id422
size15,788
Alex Light (scialex)

documentation

README

bassert

A better assert! for Rust: bassert!

This macro eliminates the need for macros like assert_eq and friends by parsing the AST manually to determine what type of printing should be done. It also does things that no macro could ever do, like printing out the arguments of a function that is being called.

Usage

#![feature(phase)]
#[phase(plugin)] extern crate bassert;

fn main() {
    if cfg!(first) {
        bassert!((1u8 + 1) << 2 < 3, "We are {} with math.", "AMAZING");
    } else {
        bassert!(stuff(123, "hello world"), "NOOO NOT STUFF!");
    }
}

fn stuff(i: u32, j: &'static str) -> bool {
    // STUFF
    false
}

Running this with --cfg first causes it to print:

task '<main>' panicked at 'assertion failed: ( 1u8 + 1 ) << 2 < 3:
left:  `( 1u8 + 1 ) << 2` = `8`
right: `3` = `3`
We are AMAZING with math.', test.rs:6

and running it without that config causes it to print

task '<main>' panicked at 'assertion failed: stuff ( 123 , "hello world" ):
argument 0: 123
argument 1: hello world
NOOO NOT STUFF!', test.rs:8

Acknowledgments

This was originally based upon P1Start's assert_ng although I rewrote so much of it that there is basically nothing left. The tests have largely remained the same but there is little of lib.rs that is from that repository.

Commit count: 11

cargo fmt