5 unstable releases
0.7.1 | Mar 15, 2024 |
---|---|
0.7.0 | Dec 13, 2022 |
0.6.1 | Oct 22, 2022 |
0.6.0 | Dec 11, 2019 |
0.5.0 | Dec 10, 2019 |
#143 in #assert
11KB
95 lines
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.
Dependencies
~1.5MB
~36K SLoC