Giter Site home page Giter Site logo

power-assert-rs's Introduction

power-assert-rs

Build Status MIT licensed crates.io

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))]

power-assert-rs's People

Contributors

gifnksm avatar ivan avatar

Stargazers

Justin Bradshaw avatar Dmitriy Ivliev avatar Thomas Bye avatar Scott Mattan avatar Donough Liu avatar dzmitry-lahoda avatar GAURAV avatar Devin Ragotzy avatar Yoshi avatar Jean Mertz avatar  avatar Matt Murahashi Kenichi avatar Jeff Muizelaar avatar Aaron Hill avatar Jeff Burdges avatar YAMAMOTO Yuji avatar Ryutaro Yamada avatar bokuweb avatar Francois-Guillaume Ribreau avatar Wataru Matsui avatar N. Shimizu avatar oreshinya avatar Frank Benkstein avatar  avatar  avatar Xavier Lange avatar Tatsuya Takamura avatar Rust avatar Volker Mische avatar Xanadu Zhang avatar Thomas Wickham avatar Adam Basfop Cavendish avatar Tatsuya Kawano avatar Nathan Ross avatar bundai223 avatar κeen avatar OKAMURA Naoki aka nyarla / kalaclista avatar SHIMIZU Taku avatar Victor Quinn avatar Angus H. avatar Livio Ribeiro avatar  avatar jigsaw avatar nacika avatar Takayuki Matsubara avatar Gio d'Amelio avatar Costantino Giuliodori avatar Kentaro Takiguchi avatar James Zhu avatar Mikhail Borisov avatar Ivan Smirnov avatar Alexander Tyaglov avatar ACCOUNT MOVED avatar Wilfred Hughes avatar Eleanor Quint avatar Hideaki Takahashi avatar Matej Ľach avatar orociic avatar Maxim Ryazanov avatar Ivan Ivashchenko avatar Jared Forsyth avatar Michael Neumann avatar Benjamin Gudehus avatar Dzmitry Misiuk avatar Zach Badgett avatar Val Markovic avatar Eliza Weisman avatar Alek Ratzloff avatar  avatar Trevor Riles avatar Nelson Chen avatar The Dude avatar Ivan Dmitrievskii avatar Ben Batha avatar  avatar Simon Paitrault avatar Konstantin V. Salikhov avatar Mikhail Trishchenkov avatar Geoffroy Couprie avatar Giuseppe Massaro avatar Keiji Matsuzaki avatar Mitsutaka Mimura avatar Noritaka Horio avatar Anna Harren avatar pocketberserker avatar Takuto Wada avatar Ryuichi Maeno avatar  avatar Tiffany Bennett avatar  avatar  avatar Hiroshi Yoshida avatar Haruka Asakura avatar Jorge Araya Navarro avatar Sebastian Thiel avatar Jòan avatar bluss avatar Tom avatar Frank Denis avatar Justinas Stankevičius avatar

Watchers

 avatar  avatar

power-assert-rs's Issues

power_assert! does not behave like assert! with deref coercion

This program:

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

pub fn check(s: &str) -> Result<(), ()> {
    Ok(())
}

#[test]
fn test() {
    let s = "hello".to_owned();
    //assert!(check(&s) == Ok(()));
    power_assert!(check(&s) == Ok(()));
}

outputs:

# cargo test
   Compiling power-assert-deref v0.1.0 (file:///x/power-assert-deref)
src/lib.rs:12:23: 12:24 error: mismatched types:
 expected `str`,
    found `collections::string::String`
(expected str,
    found struct `collections::string::String`) [E0308]
src/lib.rs:12   power_assert!(check(&s) == Ok(()));
                                     ^
src/lib.rs:12:2: 12:37 note: in this expansion of power_assert! (defined in src/lib.rs)
src/lib.rs:12:23: 12:24 help: run `rustc --explain E0308` to see a detailed explanation
error: aborting due to previous error
Could not compile `power-assert-deref`.

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

while the assert! works as expected.

I have put this in the repo https://github.com/ivan/power-assert-deref which can be tested with cargo test.

# rustc --version
rustc 1.6.0-nightly (2e07996a9 2015-10-29)

expand.rs: error: mismatched types

With a recent Rust nightly:

# rustc --version
rustc 1.7.0-dev (64a8ffeff 2016-01-07)

I see:

/home/rustdev/.cargo/registry/src/github.com-88ac128001ac3a9a/power-assert-0.3.7/src/expand.rs:22:13: 22:18 error: mismatched types:
 expected `bool`,
    found `core::result::Result<_, _>`
(expected bool,
    found enum `core::result::Result`) [E0308]
/home/rustdev/.cargo/registry/src/github.com-88ac128001ac3a9a/power-assert-0.3.7/src/expand.rs:22             Ok(e) => e,
                                                                                                              ^~~~~
/home/rustdev/.cargo/registry/src/github.com-88ac128001ac3a9a/power-assert-0.3.7/src/expand.rs:134:22: 134:65 note: in this expansion of panictry! (defined in /home/rustdev/.cargo/registry/src/github.com-88ac128001ac3a9a/power-assert-0.3.7/src/expand.rs)
/home/rustdev/.cargo/registry/src/github.com-88ac128001ac3a9a/power-assert-0.3.7/src/expand.rs:22:13: 22:18 help: run `rustc --explain E0308` to see a detailed explanation
/home/rustdev/.cargo/registry/src/github.com-88ac128001ac3a9a/power-assert-0.3.7/src/expand.rs:23:13: 23:23 error: mismatched types:
 expected `bool`,
    found `core::result::Result<_, _>`
(expected bool,
    found enum `core::result::Result`) [E0308]
/home/rustdev/.cargo/registry/src/github.com-88ac128001ac3a9a/power-assert-0.3.7/src/expand.rs:23             Err(mut e) => {
                                                                                                              ^~~~~~~~~~
/home/rustdev/.cargo/registry/src/github.com-88ac128001ac3a9a/power-assert-0.3.7/src/expand.rs:134:22: 134:65 note: in this expansion of panictry! (defined in /home/rustdev/.cargo/registry/src/github.com-88ac128001ac3a9a/power-assert-0.3.7/src/expand.rs)
/home/rustdev/.cargo/registry/src/github.com-88ac128001ac3a9a/power-assert-0.3.7/src/expand.rs:23:13: 23:23 help: run `rustc --explain E0308` to see a detailed explanation
/home/rustdev/.cargo/registry/src/github.com-88ac128001ac3a9a/power-assert-0.3.7/src/expand.rs:24:17: 24:25 error: the type of this value must be known in this context
/home/rustdev/.cargo/registry/src/github.com-88ac128001ac3a9a/power-assert-0.3.7/src/expand.rs:24                 e.emit();
                                                                                                                  ^~~~~~~~
/home/rustdev/.cargo/registry/src/github.com-88ac128001ac3a9a/power-assert-0.3.7/src/expand.rs:134:22: 134:65 note: in this expansion of panictry! (defined in /home/rustdev/.cargo/registry/src/github.com-88ac128001ac3a9a/power-assert-0.3.7/src/expand.rs)
error: aborting due to 3 previous errors

Build fails on Rust nightly

# cargo run
    Updating registry `https://github.com/rust-lang/crates.io-index`
 Downloading power-assert v0.3.0
   Compiling power-assert v0.3.0
/home/at/.cargo/registry/src/github.com-0a35038f75765ae4/power-assert-0.3.0/src/convert.rs:104:17: 104:35 error: this pattern has 3 fields, but the corresponding variant has 2 fields [E0023]
/home/at/.cargo/registry/src/github.com-0a35038f75765ae4/power-assert-0.3.0/src/convert.rs:104                 ExprMatch(_, _, _) => {
                                                                                                               ^~~~~~~~~~~~~~~~~~
/home/at/.cargo/registry/src/github.com-0a35038f75765ae4/power-assert-0.3.0/src/convert.rs:104:17: 104:35 help: run `rustc --explain E0023` to see a detailed explanation
error: aborting due to previous error
Could not compile `power-assert`.

To learn more, run the command again with --verbose.
# rustc --version
rustc 1.6.0-nightly (2e07996a9 2015-10-29)

Typo in readme

The readme suggests adding #![plugin(power-assert)]rather than #![plugin(power_assert)].

power_assert_eq! causes internal compiler error: unexpected panic

Building this program:

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

#[test]
fn test_get_concealment_size() {
        power_assert_eq!(2*2, 4);
}

Results in:

# cargo build
   Compiling power-assert-crash v0.1.0 (file:///x/power-assert-crash)
error: internal compiler error: unexpected panic
note: the compiler unexpectedly panicked. this is a bug.
note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports
note: run with `RUST_BACKTRACE=1` for a backtrace
thread 'rustc' panicked at 'assertion failed: `(left == right)` (left: `1`, right: `2`)', /home/at/.cargo/registry/src/github.com-0a35038f75765ae4/power-assert-0.3.1/src/convert.rs:15

Could not compile `power-assert-crash`.

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

That assert_eq! panic is coming from

assert_eq!(e.get(), &pp_pos);

# rustc --version
rustc 1.6.0-nightly (2e07996a9 2015-10-29)

Broken on the latest nightly

The latest nightly(rustc 1.13.0-nightly (e07dd59ea 2016-08-25)) seems to break power-assert pretty badly. It looks like there has been some changes in syntax::ast.

Full error message:

    Updating registry `https://github.com/rust-lang/crates.io-index`
   Compiling power-assert v0.3.9
error[E0432]: unresolved import `syntax::ast::TokenTree`
 --> /home/giodamelio//.cargo/registry/src/github.com-1ecc6299db9ec823/power-assert-0.3.9/src/expand.rs:3:32
  |
3 | use syntax::ast::{Expr, Ident, TokenTree, Stmt};
  |                                ^^^^^^^^^ no `TokenTree` in `syntax::ast`

error[E0432]: unresolved import `syntax::ast::TokenTree`
 --> /home/giodamelio//.cargo/registry/src/github.com-1ecc6299db9ec823/power-assert-0.3.9/src/convert.rs:3:32
  |
3 | use syntax::ast::{Expr, Ident, TokenTree};
  |                                ^^^^^^^^^ no `TokenTree` in `syntax::ast`

error: the type of this value must be known in this context
  --> /home/giodamelio//.cargo/registry/src/github.com-1ecc6299db9ec823/power-assert-0.3.9/src/expand.rs:33:32
   |
33 |        .filter(|tt| span.lo <= tt.get_span().lo && tt.get_span().hi <= span.hi)
   |                                ^^^^^^^^^^^^^

error: the type of this value must be known in this context
   --> /home/giodamelio//.cargo/registry/src/github.com-1ecc6299db9ec823/power-assert-0.3.9/src/expand.rs:132:31
    |
132 |     let cond_expr = panictry!(parser.parse_expr());
    |                     ----------^^^^^^^^^^^^^^^^^^^-
    |                     |
    |                     in this macro invocation

error: the type of this value must be known in this context
   --> /home/giodamelio//.cargo/registry/src/github.com-1ecc6299db9ec823/power-assert-0.3.9/src/expand.rs:177:25
    |
177 |     let lhs = panictry!(parser.parse_expr());
    |               ----------^^^^^^^^^^^^^^^^^^^-
    |               |
    |               in this macro invocation

error: the type of this value must be known in this context
  --> /home/giodamelio//.cargo/registry/src/github.com-1ecc6299db9ec823/power-assert-0.3.9/src/convert.rs:28:41
   |
28 |     register_pos(map, tt.get_span().lo, line.lines[0].start_col.0 as i32);
   |                                         ^^^^^^^^^^

error[E0061]: this function takes 3 parameters but 2 parameters were supplied
  --> /home/giodamelio//.cargo/registry/src/github.com-1ecc6299db9ec823/power-assert-0.3.9/src/convert.rs:41:27
   |
41 |     let filemap = codemap.new_filemap("".to_string(), ppstr);
   |                           ^^^^^^^^^^^ expected 3 parameters
   |
   = note: the following parameter types were expected: std::string::String, std::option::Option<std::string::String>, std::string::String

error[E0495]: cannot infer an appropriate lifetime due to conflicting requirements
   --> /home/giodamelio//.cargo/registry/src/github.com-1ecc6299db9ec823/power-assert-0.3.9/src/convert.rs:247:22
    |
247 |     let mut folder = AssertFolder {
    |                      ^^^^^^^^^^^^
    |
help: consider using an explicit lifetime parameter as shown: fn convert_expr<'a>(cx: &'a mut ExtCtxt<'a>, expr: P<Expr>, ident: Ident,
                    tts: &[TokenTree]) -> (P<Expr>, bool)
   --> /home/giodamelio//.cargo/registry/src/github.com-1ecc6299db9ec823/power-assert-0.3.9/src/convert.rs:234:1
    |
234 | pub fn convert_expr(cx: &mut ExtCtxt,
    | ^

error: aborting due to 6 previous errors

error: Could not compile `power-assert`.

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.