3 unstable releases
0.2.1 | Sep 26, 2024 |
---|---|
0.2.0 | May 23, 2019 |
0.1.0 | Nov 7, 2018 |
#247 in Testing
101 downloads per month
5KB
58 lines
Soft-Test-Failures
Multiple test failures, any one of which will result in a failed test. Like gtest's EXPECT_*
rather than ASSERT_*
.
#[test]
fn expect_failures() {
let x = 4;
let y = "is not";
let z = 5;
expect!(2 + 2 == 5, "{} surely {} {}", x, y, z);
expect!(1 + 1 == 2);
expect!(3 - 7 == -4);
expect!(3 - 7 == -3);
let_fail!();
}
running 1 test
test expect_failures ... FAILED
failures:
---- expect_failures stdout ----
thread 'expect_failures' panicked at '`expect` test failed with 2 failed assertions:
1: 4 surely is not 5
2: Expected 3 - 7 == -3
', src/lib.rs:48:5
note: Run with `RUST_BACKTRACE=1` for a backtrace.
lib.rs
:
This crate trackes assertions during the execution of a test, delaying panicks until the end of execution. This ensures that if two assertions were to fail, the first does not clobber the second. This is most useful when writing large tests with many assertions that may begin to fail simultaneously, as you can pinpoint exactly which ones failed.
Usage
Replace your normal assert!()
assertions with expect!()
from this crate. At the end of your test, call let_fail!()
#[test]
fn expect_failures() {
let x = 4;
let y = "is not";
let z = 5;
expect!(2 + 2 == 5, "{} surely {} {}", x, y, z);
expect!(1 + 1 == 2);
expect!(3 - 7 == -4);
expect!(3 - 7 == -3);
let_fail!();
}