Skip to content

Lint on should_panic tests without reasons #10956

Closed
@workingjubilee

Description

@workingjubilee

What it does

For a #[test] that has #[should_panic], this lint would fire unless given a reason, e.g. #[should_panic = "No such file or directory"].

Advantage

This prevents a should-panic test from accepting another reason when it fires, and there are many reasons such a test could panic.

Drawbacks

It could fire on tests that are genuinely expecting many possible panic reasons and don't care which one fires. These are probably very few in practice, but it could justify making it a "pedantic" lint.

Example

    #[should_panic]
    fn test_can_panic() {
        panic!("yup")
    }

Could be written as:

    #[should_panic = "yup"]
    fn test_can_panic() {
        panic!("yup")
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintArea: New lints

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions