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)+);
}
};
}
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
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
This requires at least Rust version 1.45 (released in July 2020).
This project dual-licensed under the Apache 2 and MIT licenses. You may choose to use either.
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.