Skip to content
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

improve diagnostics for tests with custom return values #52453

Merged
merged 1 commit into from
Aug 15, 2018

Conversation

srijs
Copy link
Contributor

@srijs srijs commented Jul 17, 2018

This is an attempt at getting the ball rolling to improve the diagnostics for test functions that return custom impl Termination values (see #52436).

An alternative could be to use eprintln!, but including this in the panic message felt nicely consistent with how failing test assertions would be reported.

Let me know what you think!

@rust-highfive
Copy link
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @TimNN (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 17, 2018
@stokhos
Copy link

stokhos commented Jul 21, 2018

Ping from triage @TimNN will you have time to review this PR?

Copy link
Contributor

@TimNN TimNN left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your PR @srijs and sorry for the delay in reviewing this.

I have two minor comments (see inline review), but otherwise this looks good.

@@ -326,7 +326,9 @@ pub fn test_main_static(tests: &[TestDescAndFn]) {
/// test is considered a failure. By default, invokes `report()`
/// and checks for a `0` result.
pub fn assert_test_result<T: Termination>(result: T) {
assert_eq!(result.report(), 0);
if result.report() != 0 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: This can be written as assert_eq!(result.report(), 0, "some custom message")

I would also mention the actual and expected status codes in the message.

@TimNN TimNN added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 21, 2018
@pietroalbini
Copy link
Member

Ping from triage @srijs! It's been a while since we heard from you, will you have time to work on this again?

@srijs
Copy link
Contributor Author

srijs commented Aug 2, 2018

Apologies for the delay here, have addressed @TimNN's feedback now!

Copy link
Contributor

@TimNN TimNN left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot! Two more style nits, otherwise this is good to go!

assert_eq!(result.report(), 0);
let code = result.report();
assert_eq!(code, 0,
"the test returned a termination value with a non-zero status code ({})\
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: missing space before the \

@@ -326,7 +326,10 @@ pub fn test_main_static(tests: &[TestDescAndFn]) {
/// test is considered a failure. By default, invokes `report()`
/// and checks for a `0` result.
pub fn assert_test_result<T: Termination>(result: T) {
assert_eq!(result.report(), 0);
let code = result.report();
assert_eq!(code, 0,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit (formatting): I believe the official style recommendation would be this:

assert_eq!(
    code, 0,
    "msg \
     ....",
    code
);

@TimNN TimNN added A-allocators Area: Custom and system allocators and removed A-allocators Area: Custom and system allocators labels Aug 7, 2018
@srijs
Copy link
Contributor Author

srijs commented Aug 11, 2018

Feedback addressed!

@TimNN
Copy link
Contributor

TimNN commented Aug 14, 2018

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Aug 14, 2018

📌 Commit 6411aef has been approved by TimNN

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Aug 14, 2018
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Aug 15, 2018
improve diagnostics for tests with custom return values

This is an attempt at getting the ball rolling to improve the diagnostics for test functions that return custom `impl Termination` values (see rust-lang#52436).

An alternative could be to use `eprintln!`, but including this in the panic message felt nicely consistent with how failing test assertions would be reported.

Let me know what you think!
bors added a commit that referenced this pull request Aug 15, 2018
Rollup of 8 pull requests

Successful merges:

 - #52453 (improve diagnostics for tests with custom return values)
 - #53271 (use ? to simplify `TransitiveRelation.maybe_map`)
 - #53279 (Extend documentation of `rustc_on_unimplemented`)
 - #53342 (fix error for unsized packed struct field)
 - #53344 (Add doc examples for std::alloc::{alloc,alloc_zeroed}.)
 - #53368 (Ignore test that fails on stage1)
 - #53388 (Fix links' color)
 - #53396 (Fix since of Iterator::flatten to be a proper semver)

Failed merges:

r? @ghost
@bors bors merged commit 6411aef into rust-lang:master Aug 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants