-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Rename #[should_fail] to #[should_panic] #21824
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
Conversation
r? @gankro (rust_highfive has picked a reviewer for you, use r? to override) |
This is intentional. Tests pass or fail. That the test fails because of a panic is an implementation detail. |
Inflating "not panicing" with the test failing seems wrong, for exactly this case where you're expecting a panic for the test to succeed. |
Sorry, it's late. My point is just this: the panic aspect is implementation. Semanticly, tests pass or fail, they don't pass or panic. Hence |
But #[test]
#[should_panic(expected = "out of bounds")]
fn test_oob() {
vec![][10]
} I'm saying "I expect a panic to occur when running this test, and the string associated with the panic to contain "out of bounds". The test should succeed if and only if that happens." The attribute is explicitly tied to the panic system. The equivalent in JUnit is To me, |
I don't think |
Only as paradoxial as |
So I was under the impression that this was just a missed rename from the |
The fail -> panic RFC mentioned nothing about the attribute at all, and we had a momentary discussion of "should this attribute change too?" and didn't do it, basically for the reason I cited. So yeah, maybe this should sit on an RFC instead. |
I would personally agree with @sfackler here because we have precisely one method of determining whether a test has passed or failed, which is a panic. I agree with @steveklabnik that if we had multiple methods to fail a test then @steveklabnik, knowing that there's only one method of "failing a test", aka panicking, does that sway your thoughts one way or the other? |
Basically my thoughts are this:
|
In my opinion, the semantic vs implementation detail descriptions are actually the other way around. If I have a function that documents that it panics if some condition happens, I want to tell the test framework to expect specifically a panic, maybe with some string attached. Keep in mind that On the other hand, it may not necessarily be true in the future that panicking is the only way to cause a test to fail. Go's test infrastructure provides functions to indicate that the test will fail, without stopping execution (this is a bit like the difference between |
More like #[test]
#[should_pass]
fn test_oob() {
assert_panic!("out of bounds", {
vec![][10]
}); // if the block executed successfully, we panic
} |
@bombless panics can't be caught, so that test would end up panicking and therefore failing in all cases. |
@sfackler Need some compiler magic for the |
Ah, I see, the real problem is the lack of should_panic, we'll need it anyway. |
I'm inclined to agree with @alexcrichton that given that (And it makes the tests easier to talk about: "This test failed because it is marked (The only other way I can imagine a test failing is via a segmentation fault, but I assume that |
What's the status on this? Are we going for an RFC? |
We talked about this in today's meeting (minutes to be posted soon) and would like to move forward with this. r=me with a rebase, and thanks again @sfackler! (sorry about the delay) |
Cool, will update tonight. |
d175e32
to
a84a5ea
Compare
This needs to make it into the snapshot before #21824 can land. r? @alexcrichton
@bors r=alexcrichton a84a |
⌛ Testing commit a84a5ea with merge f649c3b... |
💔 Test failed - auto-linux-64-nopt-t |
|
IIRC this did not make it into the snap. @flaper87 could you make another snapshot? |
Needed so that rust-lang#21824 can land
@bors: retry |
⌛ Testing commit a84a5ea with merge 85d602f... |
💔 Test failed - auto-mac-32-opt |
Was that test perhaps removed? |
Yes, in commit 2c9d81b |
Update documentation to reflect rust-lang#21824. r? @steveklabnik
No description provided.