Rust: Adjust design of unit tests with non-`()` type

Created on 12 Apr 2018  路  2Comments  路  Source: rust-lang/rust

Per this comment, we want to alter the design of unit tests with non-() type. The new design is:

  • #[should_panic] can only be applied to tests with () return type and continues to have the same meaning.
  • For non-should-panic tests, the return type T defines the error result using the Termination trait.

Achieving these changes should be relatively straight-forward. Basically the only thing we have to do is to make it an error to apply #[should_panic] unless the test has (). Currently we check that the test has the correct signature here:

https://github.com/rust-lang/rust/blob/9afed646451175e24964cc76688293cb87ed718c/src/libsyntax/test.rs#L330-L355

In any case, we just have to extend that function to also check whether there is a should_panic attribute -- if so, we can report an error, sort of like this:

https://github.com/rust-lang/rust/blob/9afed646451175e24964cc76688293cb87ed718c/src/libsyntax/test.rs#L365

E-easy E-mentor T-compiler

Most helpful comment

I'm going to try this right now :+1:

All 2 comments

I'm going to try this right now :+1:

Implemented in #49911

Was this page helpful?
0 / 5 - 0 ratings