Skip to content

Proposal: Expected panic in tests #7039

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
DutchGhost opened this issue Nov 9, 2020 · 2 comments
Closed

Proposal: Expected panic in tests #7039

DutchGhost opened this issue Nov 9, 2020 · 2 comments
Milestone

Comments

@DutchGhost
Copy link

DutchGhost commented Nov 9, 2020

When writing tests, you sometimes want to assert that the entire test itself panics. Currently we have no way of doing so.

Im proposing some way of notating that a test must panic in order to succeed. If the test does not panic when it should, the test does not succeed.

A simple syntax that is inline with calling conventions could be something along the lines of:

test "name" conv(.ShouldPanic) {
    std.testing.expectEqual(true, false);
}

The test above is considered succesfull, the convention says it expects a panic, which happens.

The default convention of tests would become conv(.NoPanic) or something along those lines.

Some other languages also provide similar facilities in their tests, Rust for example has #[should_panic].

@data-man
Copy link
Contributor

data-man commented Nov 9, 2020

@DutchGhost There is accepted #6621.

@LemonBoy
Copy link
Contributor

See #513 and #1356.

@Vexu Vexu closed this as completed Nov 10, 2020
@andrewrk andrewrk added this to the 0.8.0 milestone Jan 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants