{"action":"created","issue":{"url":"https://api.github.com/repos/rust-lang/rust/issues/48854","repository_url":"https://api.github.com/repos/rust-lang/rust","labels_url":"https://api.github.com/repos/rust-lang/rust/issues/48854/labels{/name}","comments_url":"https://api.github.com/repos/rust-lang/rust/issues/48854/comments","events_url":"https://api.github.com/repos/rust-lang/rust/issues/48854/events","html_url":"https://github.com/rust-lang/rust/issues/48854","id":303662637,"number":48854,"title":"Stabilize unit tests with non-`()` return type","user":{"login":"nikomatsakis","id":155238,"avatar_url":"https://avatars0.githubusercontent.com/u/155238?v=4","gravatar_id":"","url":"https://api.github.com/users/nikomatsakis","html_url":"https://github.com/nikomatsakis","followers_url":"https://api.github.com/users/nikomatsakis/followers","following_url":"https://api.github.com/users/nikomatsakis/following{/other_user}","gists_url":"https://api.github.com/users/nikomatsakis/gists{/gist_id}","starred_url":"https://api.github.com/users/nikomatsakis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nikomatsakis/subscriptions","organizations_url":"https://api.github.com/users/nikomatsakis/orgs","repos_url":"https://api.github.com/users/nikomatsakis/repos","events_url":"https://api.github.com/users/nikomatsakis/events{/privacy}","received_events_url":"https://api.github.com/users/nikomatsakis/received_events","type":"User","site_admin":false},"labels":[{"id":650846969,"url":"https://api.github.com/repos/rust-lang/rust/labels/C-tracking-issue","name":"C-tracking-issue","color":"f5f1fd","default":false},{"id":602425123,"url":"https://api.github.com/repos/rust-lang/rust/labels/T-dev-tools","name":"T-dev-tools","color":"bfd4f2","default":false},{"id":211668019,"url":"https://api.github.com/repos/rust-lang/rust/labels/T-lang","name":"T-lang","color":"bfd4f2","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":15,"created_at":"2018-03-08T22:54:55Z","updated_at":"2018-03-13T15:28:06Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"This is a sub-issue of the [larger tracking issue](https://github.com/rust-lang/rust/issues/43301) 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 https://github.com/rust-lang/rust/issues/48453, which was discussing the same thing but for the `main` function.\r\n\r\n### Possible changes needed before stabilizing\r\n\r\n- [ ] Adjust libtest runner to distinguish `#[should_panic]` from `#[should_error]`, as [suggested by @scottmcm](https://github.com/rust-lang/rust/issues/48854#issuecomment-371660072)?\r\n- [ ] Successful examples of using with rustdoc\r\n\r\n### What would be stabilized \r\n\r\nUnit tests (and `#[bench]` functions) would join the `main` function in being allowed to return any value that implements the `Termination` trait. \r\n\r\nThis commits us to the following (each link is to a test):\r\n\r\n- tests that return `Result` and other `Termination` types. In the case of `Result`:\r\n    - [`Ok` means test passes](https://github.com/rust-lang/rust/blob/c90f68224b069f5bb2a80e30e2737e4bb17c1466/src/test/run-pass/rfc-1937-termination-trait/termination-trait-in-test.rs#L20-L24)\r\n    - [`Err` causes test failure](https://github.com/rust-lang/rust/blob/c90f68224b069f5bb2a80e30e2737e4bb17c1466/src/test/run-pass/rfc-1937-termination-trait/termination-trait-in-test.rs#L26-L31)\r\n    - more generally, success or failure is determined by [invoking `report()`](https://github.com/rust-lang/rust/blob/c90f68224b069f5bb2a80e30e2737e4bb17c1466/src/libtest/lib.rs#L327-L332), although that detail is not being stabilized\r\n- benchmarks work the same way ([Ok](https://github.com/rust-lang/rust/blob/c90f68224b069f5bb2a80e30e2737e4bb17c1466/src/test/run-pass/rfc-1937-termination-trait/termination-trait-in-test.rs#L33-L36), [Err](https://github.com/rust-lang/rust/blob/c90f68224b069f5bb2a80e30e2737e4bb17c1466/src/test/run-pass/rfc-1937-termination-trait/termination-trait-in-test.rs#L38-L43))\r\n    - note that `#[bench]` is still effectively unstable though in general\r\n\r\n### What remains unstable\r\n\r\n- The library details: where the trait is and its methods\r\n  - Which methods the test runner invokes on the trait -- this is unstable as the trait itself is unstable\r\n"},"comment":{"url":"https://api.github.com/repos/rust-lang/rust/issues/comments/372706004","html_url":"https://github.com/rust-lang/rust/issues/48854#issuecomment-372706004","issue_url":"https://api.github.com/repos/rust-lang/rust/issues/48854","id":372706004,"user":{"login":"nikomatsakis","id":155238,"avatar_url":"https://avatars0.githubusercontent.com/u/155238?v=4","gravatar_id":"","url":"https://api.github.com/users/nikomatsakis","html_url":"https://github.com/nikomatsakis","followers_url":"https://api.github.com/users/nikomatsakis/followers","following_url":"https://api.github.com/users/nikomatsakis/following{/other_user}","gists_url":"https://api.github.com/users/nikomatsakis/gists{/gist_id}","starred_url":"https://api.github.com/users/nikomatsakis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nikomatsakis/subscriptions","organizations_url":"https://api.github.com/users/nikomatsakis/orgs","repos_url":"https://api.github.com/users/nikomatsakis/repos","events_url":"https://api.github.com/users/nikomatsakis/events{/privacy}","received_events_url":"https://api.github.com/users/nikomatsakis/received_events","type":"User","site_admin":false},"created_at":"2018-03-13T15:28:06Z","updated_at":"2018-03-13T15:28:06Z","author_association":"CONTRIBUTOR","body":"> IMO, returning a Result::Err from a test should always cause the test to fail. If it's expected that the operation fails, that should be part of the test:\r\n\r\nHmm. Plausible. Maybe that's how we should refactor the test runner's internal workings, actually. That is, we could refactor `#[should_panic]` tests so that they catch the panic (and make the test runner consider any uncaught panic as a failure)."}}
{"actor":{"display_login":"nikomatsakis"}}