6 个版本
0.3.1 | 2024年1月14日 |
---|---|
0.3.0 | 2023年10月30日 |
0.2.2 | 2023年7月30日 |
0.1.0 | 2023年6月30日 |
#220 在 测试
用于 2 crates
8KB
83 行
test_panic
用于具有panic的测试用例的工具。
该crate的作者英语不太好。
如果文档难以阅读,请见谅。
这是什么?
提供用于panic测试的函数。为了同样的目的,Rust标准中也提供了shoud_panic
属性,但它并不那么有用,因此我们创建了此crate。
示例
使用此crate的示例。
#[test]
fn test() {
let result = test_panic(|| panic!("message."));
assert!(result.is_panic());
assert!(result.message().contains("message."));
}
使用should_panic
的示例。
#[test]
#[should_panic(expected = "message.")]
fn test() {
// Suppresses standard error output.
panic::set_hook(Box::new(|_| {}));
panic!("message.");
}
更新内容
v0.3.1
- 进行了一些小的重构。
v0.3.0
- 在
TestPanicResult
中添加了must_use
注解。
v0.2.0
- 对一些文档进行了润色。
TestPanicResult
在未发生panic的情况下保存值。