#panic #assert #happen #kind #macro

assert-panic

断言发生 panic,并可选择地断言发生的 panic 类型

4 个版本 (2 个稳定版本)

1.0.1 2020年6月10日
1.0.0-preview12020年5月23日
1.0.0-preview.12020年5月24日

测试 中排名第 580

Download history 2156/week @ 2024-03-13 1298/week @ 2024-03-20 1033/week @ 2024-03-27 500/week @ 2024-04-03 141/week @ 2024-04-10 205/week @ 2024-04-17 111/week @ 2024-04-24 238/week @ 2024-05-01 154/week @ 2024-05-08 150/week @ 2024-05-15 85/week @ 2024-05-22 375/week @ 2024-05-29 108/week @ 2024-06-05 140/week @ 2024-06-12 105/week @ 2024-06-19 266/week @ 2024-06-26

每月下载量 707
5 crate 中使用

MIT/Apache

9KB
86

assert-panic

Latest Version docs.rs

该库提供了一个宏,用于断言发生 panic,并可选择地断言发生的 panic 类型。

最简单的版本会给你一个包装的 Any panic。

示例

# use std::any::Any;
use assert_panic::assert_panic;

let _: Box<dyn Any + Send + 'static> =
    assert_panic!(panic!("at the Disco"));

assert_panic!(panic!("at the Disco"), &str);

assert_panic!(
    { assert_panic!({}); },
    String,
    starts with "assert_panic! argument did not panic:",
);

assert_panic!(
    assert_panic!(panic!("at the Disco"), String),
    String,
    starts with "Expected a `String` panic but found one with TypeId { t: ",
);

assert_panic!(
    assert_panic!(panic!("found"), &str, contains "expected"),
    String,
    "Expected a panic containing \"expected\" but found \"found\"",
);

assert_panic!(
    assert_panic!(panic!("found"), &str, starts with "expected"),
    String,
    "Expected a panic starting with \"expected\" but found \"found\"",
);

assert_panic!(
    assert_panic!(panic!(1_usize), usize, 2_usize),
    String,
    "Expected a panic equal to 2 but found 1",
);

版本控制

assert-panic 严格遵循 语义化版本 2.0.0,但有以下例外

  • 在主版本变更时,次版本号不会重置为 0。
    将其视为全局功能级别。
  • 在主版本或次版本变更时,补丁版本号不会重置为 0。
    将其视为全局补丁级别。
  • 来自 assert-panic 的 panic 消息被视为实现细节。
    请只评估您直接控制的 panic 值。

无运行时依赖