-
Notifications
You must be signed in to change notification settings - Fork 13.9k
Closed
Labels
C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCE-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.T-dev-toolsRelevant to the dev-tools subteam, which will review and decide on the PR/issue.Relevant to the dev-tools subteam, which will review and decide on the PR/issue.T-langRelevant to the language teamRelevant to the language teamfinished-final-comment-periodThe final comment period is finished for this PR / Issue.The final comment period is finished for this PR / Issue.
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
Terminationtrait- Test and expected error
- The test passes if the return value is considered a "success" (e.g., an
OkfromResult) - 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
Resultand otherTerminationtypes. In the case ofResult:Okmeans test passesErrcauses 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
briansmith and schneiderfelipestepanchegyrashk and schneiderfelipe
Metadata
Metadata
Assignees
Labels
C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCE-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.T-dev-toolsRelevant to the dev-tools subteam, which will review and decide on the PR/issue.Relevant to the dev-tools subteam, which will review and decide on the PR/issue.T-langRelevant to the language teamRelevant to the language teamfinished-final-comment-periodThe final comment period is finished for this PR / Issue.The final comment period is finished for this PR / Issue.