#assertions #assert #power #better #message #val #foo

nightly power-assert

Power Assert in Rust. Provides better assertion message.

13 releases

Uses old Rust 2015

0.3.9 Feb 27, 2016
0.3.8 Jan 16, 2016
0.3.6 Dec 28, 2015
0.3.5 Nov 28, 2015
0.1.0 Aug 30, 2015

#2591 in Rust patterns

31 downloads per month

MIT license

21KB
446 lines

power-assert-rs

Build Status MIT licensed

Power Assert in Rust. Provides better assertion message like this:

$ cargo run --example normal
     Running `target/debug/examples/normal`
thread '<main>' panicked at 'assertion failed: bar.val == bar.foo.val
power_assert!(bar.val == bar.foo.val)
              |   |   |  |   |   |
              |   3   |  |   |   2
              |       |  |   Foo { val: 2 }
              |       |  Bar { val: 3, foo: Foo { val: 2 } }
              |       false
              Bar { val: 3, foo: Foo { val: 2 } }
', examples/normal.rs:26
An unknown error occurred

To learn more, run the command again with --verbose.

How to use

Add this to your Cargo.toml:

[dependencies]
power-assert = "*"

and add this to your lib.rs or main.rs:

#![feature(plugin)]
#![plugin(power_assert)]

Now, you can use power_assert!() and power_assert_eq!().

If you want to override builtin assert!() and assert_eq!(), change your lib.rs or main.rs as follows.

#![feature(plugin)]
#![plugin(power_assert(override_builtins))]

No runtime deps