test_panic

Crates.iotest_panic
lib.rstest_panic
version0.4.1
created_at2023-06-30 05:42:23.373536+00
updated_at2025-07-14 11:57:35.309895+00
descriptionUtility for test cases with panic.
homepage
repositoryhttps://github.com/nossie531/test_panic
max_upload_size
id904130
size23,877
(nossie531)

documentation

README

test_panic

Utility for test cases with panic.

The author of this crate is not good at English.
Forgive me if the document is hard to read.

What is this?

Provides functions for test with panic. For the same purpose, the shoud_panic attribute is provided in the Rust standard, but it is not so useful, hence we created this crate.

Examples

Example with this crate.

use test_panic::prelude::*;

#[test]
fn test() {
    let result = test_panic(|| panic!("message."));
    assert!(result.is_panic());
    assert!(result.message().contains("message."));
}

Example with should_panic.

#[test]
#[should_panic(expected = "message.")]
fn test() {
    // Suppresses standard error output.
    panic::set_hook(Box::new(|_| {}));
    panic!("message.");
}

Versions

See CHANGELOG.

Commit count: 6

cargo fmt