Crates.io | assert-panic |
lib.rs | assert-panic |
version | 1.0.1 |
source | src |
created_at | 2020-05-23 23:16:21.012303 |
updated_at | 2020-06-10 21:54:11.076093 |
description | Assert that a panic happens, and optionally what (kind of) panic happens |
homepage | |
repository | https://github.com/Tamschi/assert-panic |
max_upload_size | |
id | 245016 |
size | 22,952 |
This library provides a macro that asserts that a panic happens, and optionally what (kind of) panic happens.
The simplest version gives you the panic as boxed Any
.
# 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
strictly follows Semantic Versioning 2.0.0 with the following exceptions:
assert-panic
are considered an implementation detail.