diff options
| author | Edvard Thörnros <edvard.thornros@gmail.com> | 2021-02-19 17:25:12 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-02-19 17:25:12 +0100 |
| commit | 5241e1243f285742a76289e53982587f2b9cb603 (patch) | |
| tree | ef07406501befd029002c820427c8254996195d1 | |
| parent | 66aa179230b759a57ad7db0a6b70c4d9930acb80 (diff) | |
| parent | 33e87da47b0d7dedc0b88d7e732f398fc602deca (diff) | |
| download | sylt-5241e1243f285742a76289e53982587f2b9cb603.tar.gz | |
Merge pull request #71 from FredTheDino/better-test-fails
better test fails
| -rw-r--r-- | src/lib.rs | 29 |
1 files changed, 23 insertions, 6 deletions
@@ -748,9 +748,14 @@ mod tests { #[macro_export] macro_rules! assert_errs { ($result:expr, [ $( $kind:pat ),* ]) => { - eprintln!("{} => {:?}", stringify!($result), $result); - assert!(matches!( - $result.unwrap_err().as_slice(), + let errs = if let Err(errs) = $result { + errs + } else { + eprintln!(" Program succeeded when it should've failed"); + unreachable!(); + }; + if !matches!( + errs.as_slice(), &[$($crate::error::Error { kind: $kind, file: _, @@ -758,7 +763,19 @@ mod tests { message: _, }, )*] - )) + ) { + eprintln!("Unexpected errors"); + eprint!(" Got: ["); + for err in errs { + eprint!(" ErrorKind::{:?} ", err.kind); + } + eprint!("]\n Want: ["); + $( + eprint!(" {} ", stringify!($kind)); + )* + eprintln!("]"); + assert!(false); + } }; } @@ -808,8 +825,8 @@ mod tests { for e in errs.iter() { println!("{}", e); } - println!(" {} - FAILED\n", stringify!($fn)); - panic!(); + eprintln!(" {} - failed\n", stringify!($fn)); + unreachable!(); } } }); |
