Closed
Description
CURRENT STATUS:
Awaiting someone to write the stabilization PR! Mentoring instructions here.
This is a sub-issue of the larger tracking issue devoted to the ?
in main RFC. This issue corresponds to stabilizing the use of unit tests whose return type is something other than ()
-- it basically an extension of #48453, which was discussing the same thing but for the main
function.
What would be stabilized
As before, unit tests that return ()
:
- Succeed unless they panic
- Can be annotated with
#[should_panic]
However, unit tests can now have other return types:
- The return type must implement the
Termination
trait- Test and expected error
- The test passes if the return value is considered a "success" (e.g., an
Ok
fromResult
) - If the type is not
()
, then#[should_panic]
is disallowed- Test and expected error
Unknowns
- Question: what's up with
#[should_panic]
and#[bench]
anyway? (Example) - Can we use this with rustdoc yet?
Older proposal
Possible changes needed before stabilizing
- Adjust libtest runner to distinguish
#[should_panic]
from#[should_error]
, as suggested by @scottmcm? - Successful examples of using with rustdoc
What would be stabilized
Unit tests (and #[bench]
functions) would join the main
function in being allowed to return any value that implements the Termination
trait.
This commits us to the following (each link is to a test):
- tests that return
Result
and otherTermination
types. In the case ofResult
:Ok
means test passesErr
causes test failure- more generally, success or failure is determined by invoking
report()
, although that detail is not being stabilized
- benchmarks work the same way (Ok, Err)
- note that
#[bench]
is still effectively unstable though in general
- note that
What remains unstable
- The library details: where the trait is and its methods
- Which methods the test runner invokes on the trait -- this is unstable as the trait itself is unstable
Metadata
Metadata
Assignees
Labels
Category: An issue tracking the progress of sth. like the implementation of an RFCCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.Relevant to the dev-tools subteam, which will review and decide on the PR/issue.Relevant to the language teamThe final comment period is finished for this PR / Issue.