Skip to content
This repository has been archived by the owner on Mar 15, 2024. It is now read-only.
/ assertify Public archive

Deprecated: Clearer assertions and tests for Rust expressions

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
Notifications You must be signed in to change notification settings

danielparks/assertify

Repository files navigation

Deprecated — use assert2

Use assert2 instead of this crate. assertify! can be replaced by the more capable assert2::assert! everywhere, and testify! can implemented with a short macro:

macro_rules! testify {
    ($name:ident, $($test:tt)+) => {
        #[test]
        fn $name() {
            ::assert2::assert!($($test)+);
        }
    };
}

assertify!(expr)

Deprecated: use assert2::assert!.

Generates an assertion for expr with a friendly failure message. If expr is a binary expression, the actual value should be on the left and the expected value should be on the right.

#[test]
fn simple_eq() {
    assertify!(1 + 2 == 0);
}
---- tests::simple_eq stdout ----
thread 'tests::simple_eq' panicked at 'failed: 1 + 2 == 0
  actual:      3
  expected: == 0
', src/lib.rs:98:9

This is a major improvement over the message generated by assert_eq!, since the failure message shows what the failed expression was.

#[test]
fn simple_eq_traditional() {
    assert_eq!(1 + 2, 0);
}
---- tests::simple_eq_traditional stdout ----
thread 'tests::simple_eq_traditional' panicked at 'assertion failed: `(left == right)`
  left: `3`,
 right: `0`', src/lib.rs:103:9

testify!(name, expr)

Deprecated: Use the following:

macro_rules! testify {
    ($name:ident, $($test:tt)+) => {
        #[test]
        fn $name() {
            ::assert2::assert!($($test)+);
        }
    };
}

Generates a test function named name that asserts that expr is true.

testify!(concat_literals, concat("a", "b") == "ab");

Again, the failure messages are easy to understand:

---- tests::concat_literals stdout ----
thread 'tests::concat_literals' panicked at 'failed: concat("a", "b") == "aX"
  actual:      "ab"
  expected: == "aX"
', src/lib.rs:106:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Compatibility

This requires at least Rust version 1.45 (released in July 2020).

License

This project dual-licensed under the Apache 2 and MIT licenses. You may choose to use either.

Contributions

Unless you explicitly state otherwise, any contribution you submit as defined in the Apache 2.0 license shall be dual licensed as above, without any additional terms or conditions.

About

Deprecated: Clearer assertions and tests for Rust expressions

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Packages

No packages published

Languages