Skip to main content

test_panic/
lib.rs

1//! Utility for test cases with panic.
2//!
3//! _The author of this crate is not good at English._  
4//! _Forgive me if the document is hard to read._
5//!
6//! For the same purpose, `shoud_panic` attribute is provided in the
7//! Rust standard, but it is not so useful, hence we created this crate.
8//!
9//! # Examples
10//!
11//! Example with always panic.
12//!
13//! ```no_run
14//! use test_panic::prelude::*;
15//!
16//! #[test]
17//! fn test() {
18//!     let result = test_panic(|| panic!("message."));
19//!     assert!(result.is_panic());
20//!     assert!(result.message().contains("message"));
21//! }
22//! ```
23//!
24//! Example with multiple tests.
25//!
26//! ```no_run
27//! use test_panic::prelude::*;
28//!
29//! #[test]
30//! fn with_multi_tests() {
31//!     let datas = [
32//!         ((10, 3), ok(3)),
33//!         ((10, 0), ng()),
34//!         ((10, 15), msg("Result is too small")),
35//!     ];
36//!
37//!     for ((x, y), tobe) in datas {
38//!         let asis = test_panic(|| divide(x, y));
39//!         assert_eqa!(asis, tobe);
40//!     }
41//! }
42//!
43//! fn divide(x: i32, y: i32) -> i32 {
44//!     assert!(y > 0);
45//!     assert!(x / y >= 1, "Result is too small");
46//!     x / y
47//! }
48//! ```
49
50#![warn(missing_docs)]
51#![forbid(unsafe_code)]
52
53pub mod msg;
54pub mod prelude;
55pub use funcs::*;
56pub use test_panic_result::*;
57
58mod funcs;
59mod macros;
60mod test_panic_result;
61mod util;