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

assert_eq failure message easier to read #42541

Merged
merged 10 commits into from
Jun 24, 2017
Merged

Conversation

gilescope
Copy link
Contributor

@gilescope gilescope commented Jun 8, 2017

By having the left and right strings aligned with one another it helps spot the difference between the two far quicker than if they are on the same line.

E.g.
Before:

thread 'tests::test_safe_filename' panicked at 'assertion failed: `(left == right)` left:  `"-aandb--S123.html"` right: `"-aandb-S123.html"`',

After:

thread 'tests::test_safe_filename' panicked at 'assertion failed: `(left == right)`
left:  `"-aandb--S123.html"`
right: `"-aandb-S123.html"`',

When the strings are both on the same line it take a lot longer to spot the difference. It is a small change but the small time savings add up with repetition. This would help Rust be an excellent language to write tests in out of the box.

Closes #41615

By having the left and right strings above and below on the same line it helps spot the difference between the two. E.g.

thread 'tests::test_safe_filename' panicked at 'assertion failed: `(left == right)`
left:  `"-aandb--S123.html"`
right: `"-aandb-S123.html"`',

When the strings are both on the same line it take a lot longer to spot the difference. It is a small change but the small time savings add up with repetition. This helps Rust be an excellent language to write tests in.
@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 @alexcrichton (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.

@kennytm
Copy link
Member

kennytm commented Jun 8, 2017

The test case for assert_eq needs to be updated as well.

[00:52:03] failures:
[00:52:03] 
[00:52:03] ---- [run-fail] run-fail/assert-eq-macro-panic.rs stdout ----
[00:52:03] 	
[00:52:03] error: error pattern 'assertion failed: `(left == right)` (left: `14`, right: `15`)' not found!
[00:52:03] status: exit code: 101
[00:52:03] command: /checkout/obj/build/x86_64-unknown-linux-gnu/test/run-fail/assert-eq-macro-panic.stage2-x86_64-unknown-linux-gnu 
[00:52:03] stdout:
[00:52:03] ------------------------------------------
[00:52:03] 
[00:52:03] ------------------------------------------
[00:52:03] stderr:
[00:52:03] ------------------------------------------
[00:52:03] thread 'main' panicked at 'assertion failed: `(left == right)`
[00:52:03] left:  `14`
[00:52:03] right: `15`', /checkout/src/test/run-fail/assert-eq-macro-panic.rs:14
[00:52:03] note: Run with `RUST_BACKTRACE=1` for a backtrace.
[00:52:03] 
[00:52:03] ------------------------------------------
[00:52:03] 
[00:52:03] thread '[run-fail] run-fail/assert-eq-macro-panic.rs' panicked at 'explicit panic', /checkout/src/tools/compiletest/src/runtest.rs:2480
[00:52:03] note: Run with `RUST_BACKTRACE=1` for a backtrace.
[00:52:03] 
[00:52:03] 
[00:52:03] failures:
[00:52:03]     [run-fail] run-fail/assert-eq-macro-panic.rs
[00:52:03] 
[00:52:03] test result: FAILED. 125 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out

But the error-pattern header doesn't support multi-line expectation AFAIK...

@frewsxcv
Copy link
Member

frewsxcv commented Jun 8, 2017

Might also be good to change the assert_ne! macro to match this formatting directly below the assert_eq! definition

@shepmaster shepmaster added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Jun 9, 2017
@gilescope
Copy link
Contributor Author

multiple error-pattern seems to work nicely 👍 .
I noticed assert_eq printed left == right as well as assert_ne. I've changed assert_ne to print left != right and added a test to prove it works as expected.

Ready for review.

@gilescope
Copy link
Contributor Author

@alexcrichton is it looking ok now?

@alexcrichton
Copy link
Member

Oops thanks for the ping @gilescope, turns out you're not the first to have this idea! Looks like this closes that issue so I'll update the PR description as well. Otherwise looks great to me, thanks!

@bors: r+

@bors
Copy link
Contributor

bors commented Jun 14, 2017

📌 Commit 02969a7 has been approved by alexcrichton

@bors
Copy link
Contributor

bors commented Jun 14, 2017

⌛ Testing commit 02969a7 with merge 2add77b...

@bors
Copy link
Contributor

bors commented Jun 14, 2017

💔 Test failed - status-travis

@Mark-Simulacrum
Copy link
Member

Legitimate failure.

[01:04:38] ---- cargo_bench_failing_test stdout ----

[01:04:38] 	running `/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/release/cargo build`

[01:04:38] running `/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/cit/t11/foo/target/debug/foo`

[01:04:38] running `/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/release/cargo bench`

[01:04:38] thread 'cargo_bench_failing_test' panicked at '

[01:04:38] Expected: execs

[01:04:38]     but: expected to find:

[01:04:38] [COMPILING] foo v0.5.0 (file:///checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/cit/t11/foo)

[01:04:38] [FINISHED] release [optimized] target(s) in [..]

[01:04:38] [RUNNING] target[/]release[/]deps[/]foo-[..][EXE]

[01:04:38] thread '[..]' panicked at 'assertion failed: `(left == right)` (left: `"hello"`, right: `"nope"`)', src[/]foo.rs:14

[01:04:38] [..]

[01:04:38] 

[01:04:38] 

[01:04:38] did not find in output:

[01:04:38]    Compiling foo v0.5.0 (file:///checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/cit/t11/foo)

[01:04:38]     Finished release [optimized] target(s) in 0.63 secs

[01:04:38]      Running target/release/deps/foo-dfc15783c07e4d52

[01:04:38] thread 'main' panicked at 'assertion failed: `(left == right)`

[01:04:38]   left: `"hello"`

[01:04:38]  right: `"nope"`', src/foo.rs:14

[01:04:38] note: Run with `RUST_BACKTRACE=1` for a backtrace.

[01:04:38] error: bench failed

[01:04:38] ', /cargo/registry/src/git.luolix.top-1ecc6299db9ec823/hamcrest-0.1.1/src/core.rs:31

[01:04:38] note: Run with `RUST_BACKTRACE=1` for a backtrace.

[01:04:38] 

[01:04:38] 

[01:04:38] failures:

[01:04:38]     cargo_bench_failing_test

@kennytm
Copy link
Member

kennytm commented Jun 14, 2017

Cargo strikes again 😆

@gilescope
Copy link
Contributor Author

The fix for the cargo/tests/bench.rs is on gilescope/cargo revision 65ea42e8a847171e4f93fef6df5154aba7f832e3 (master branch). I'm unclear as to whether I should be creating a separate pull request for Cargo? Apologies - my git-foo seems to be lacking on submodules. Apologies for being a newbie in this respect.

@kennytm
Copy link
Member

kennytm commented Jun 16, 2017

@gilescope Yes you need to submit a PR to cargo, wait for cargo to merge it, and then update the submodule here. You may see how this is handled in #41910 and rust-lang/cargo#4055.

@bors
Copy link
Contributor

bors commented Jun 18, 2017

☔ The latest upstream changes (presumably #42676) made this pull request unmergeable. Please resolve the merge conflicts.

bors added a commit to rust-lang/cargo that referenced this pull request Jun 19, 2017
Make test less brittle prior to assert_eq failure message format change

PR required for rust-lang/rust#42541 to make assert_eq error message be multi-line. Before implementing this we need to make the current test less brittle.
Not 100% clear on if I need the final [...] or not.
@gilescope
Copy link
Contributor Author

@alexcrichton good morning, hopefully second time luck with cargo!

@alexcrichton
Copy link
Member

@bors: r+

@bors
Copy link
Contributor

bors commented Jun 20, 2017

📌 Commit 7acaf18 has been approved by alexcrichton

@alexcrichton
Copy link
Member

@gilescope ah sorry there's no way to restart a travis build other than with a new commit, but I think this is ready to go, right? Want to remove the noop commits and I'll r+?

@gilescope
Copy link
Contributor Author

My git-fu has certainly improved a bit! Ok, I think I've managed to scrub those two no-op commits. Please feel free to r+

@alexcrichton
Copy link
Member

@bors: r+

Thanks!

@bors
Copy link
Contributor

bors commented Jun 23, 2017

📌 Commit 940d5ca has been approved by alexcrichton

@bors
Copy link
Contributor

bors commented Jun 23, 2017

⌛ Testing commit 940d5ca with merge 5e696959cd5a3b42e58705aa5079a442c1f441d3...

@bors
Copy link
Contributor

bors commented Jun 23, 2017

💔 Test failed - status-travis

@Mark-Simulacrum
Copy link
Member

@bors retry

network failure, I hope: [00:03:14] curl: (6) Could not resolve host: codeload.github.com

@Mark-Simulacrum
Copy link
Member

@bors r=alexcrichton retry

Didn't mean to close...

@bors
Copy link
Contributor

bors commented Jun 23, 2017

💡 This pull request was already approved, no need to approve it again.

@bors
Copy link
Contributor

bors commented Jun 23, 2017

📌 Commit 940d5ca has been approved by alexcrichton

@bors
Copy link
Contributor

bors commented Jun 24, 2017

⌛ Testing commit 940d5ca with merge 22c905e1f145cbf7cbc188ad308a7bfc8d2a8d6e...

@bors
Copy link
Contributor

bors commented Jun 24, 2017

💔 Test failed - status-travis

@kennytm
Copy link
Member

kennytm commented Jun 24, 2017

macOS timed out, spurious.

@gilescope
Copy link
Contributor Author

Hmm, Travis timed out at 3h but it was happily chugging away running the tests. Maybe it hit a slow / heavily loaded server? I guess at some point we need to split the build from running the tests so that we can parallelise the tests further. Then again speeding up the rust compiler would help these build times and might have some side benefits. Not sure I'm quite ready to take that on as my second PR.

@kennytm
Copy link
Member

kennytm commented Jun 24, 2017

@gilescope no need to worry about that, some rust team member will just retry in these cases

@Mark-Simulacrum
Copy link
Member

@bors retry

OS X timed out

@bors
Copy link
Contributor

bors commented Jun 24, 2017

⌛ Testing commit 940d5ca with merge 3cf9f5d...

bors added a commit that referenced this pull request Jun 24, 2017
assert_eq failure message easier to read

By having the left and right strings aligned with one another it helps spot the difference between the two far quicker than if they are on the same line.

E.g.
Before:

```
thread 'tests::test_safe_filename' panicked at 'assertion failed: `(left == right)` left:  `"-aandb--S123.html"` right: `"-aandb-S123.html"`',
```

After:

```
thread 'tests::test_safe_filename' panicked at 'assertion failed: `(left == right)`
left:  `"-aandb--S123.html"`
right: `"-aandb-S123.html"`',
```

When the strings are both on the same line it take a lot longer to spot the difference. It is a small change but the small time savings add up with repetition. This would help Rust be an excellent language to write tests in out of the box.

Closes #41615
@bors
Copy link
Contributor

bors commented Jun 24, 2017

☀️ Test successful - status-appveyor, status-travis
Approved by: alexcrichton
Pushing 3cf9f5d to master...

@lpil
Copy link

lpil commented Dec 25, 2017

Late to the game here, just wanted to say thanks for this. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants