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

Don't allow #[should_panic] with non-() tests #49911

Merged
merged 1 commit into from
Apr 24, 2018
Merged

Conversation

rcoh
Copy link
Contributor

@rcoh rcoh commented Apr 12, 2018

Adds (removes) support for #[should_panic] when the test is non-()

@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 @petrochenkov (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 Apr 12, 2018
@rcoh rcoh changed the title WIP for #49909 WIP for Unit tests with non-() type Apr 12, 2018
@rust-highfive
Copy link
Collaborator

Your PR failed on Travis (raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
[00:00:46] configure: rust.quiet-tests     := True
---
[00:04:51] tidy error: /checkout/src/test/run-pass/rfc-1937-termination-trait/termination-trait-in-test.rs:29: line longer than 100 chars
[00:04:51] tidy error: /checkout/src/libsyntax/test.rs:378: line longer than 100 chars
[00:04:51] tidy error: /checkout/src/libsyntax/test.rs:382: line longer than 100 chars

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

@petrochenkov
Copy link
Contributor

r? @nikomatsakis

Copy link
Contributor

@nikomatsakis nikomatsakis left a comment

Choose a reason for hiding this comment

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

Looks pretty good at first glance!

@@ -26,6 +26,7 @@ fn is_a_num() -> Result<(), ParseIntError> {
#[test]
#[should_panic]
fn not_a_num() -> Result<(), ParseIntError> {
//~^ ERROR test functions returning Result<_, _> must not use #[should_panic]
Copy link
Contributor

Choose a reason for hiding this comment

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

This test livs in the run-pass directory -- that means it must compile. Can you copy the test into ui/rfc-1937-termination-trait/, and break it into two files? One of them can include the is_a_num test (and the comment // run-pass). The other includes the not_a_num test (with the //~ ERROR). That way, we test that the first test compiles and runs, and that the second fails to compile. There is discussion about ui tests in the rustc-guide: https://rust-lang-nursery.github.io/rustc-guide/tests/adding.html#ui

@nikomatsakis
Copy link
Contributor

Oh, I see that travis is also upset about some overly long lines.

@nikomatsakis nikomatsakis 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 Apr 12, 2018
@rust-highfive
Copy link
Collaborator

Your PR failed on Travis (raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
[00:00:44] configure: rust.quiet-tests     := True
---
[00:56:25] ...............................................................................i....................
[00:56:32] ......................i.............................................................................
---
[00:57:23] ..i...........................................................................i.....................
---
[00:58:37] .............................................i......................................................
---
[01:03:42] .............................i......................................................................
[01:03:59] ..............................................................i.....................................
[01:04:19] ................................................i...................................................
[01:04:44] ....................................................................................................
[01:05:11] ....................................................................................................
[01:05:38] ....................................................................................................
[01:06:09] ......i.............................................................................................
[01:06:29] ..i...........................................test [run-pass] run-pass/mir_heavy_promoted.rs has been running for over 60 seconds
[01:06:55] ......................................................
[01:07:35] ....................................................................................................
[01:08:18] ....................................................F...............ii..............................
[01:09:03] ...............................i.........................test [run-pass] run-pass/saturating-float-casts.rs has been running for over 60 seconds
[01:09:24] ...........................i.ii............
[01:10:15] ............................................................................................iiiiiii.
---
[01:13:13] command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/src/test/run-pass/rfc-1937-termination-trait/termination-trait-in-test.rs" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/run-pass" "--target=x86_64-unknown-linux-gnu" "-C" "prefer-dynamic" "-o" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/run-pass/rfc-1937-termination-trait/termination-trait-in-test.stage2-x86_64-unknown-linux-gnu" "-Crpath" "-O" "-Zmiri" "-Zunstable-options" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "--test" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/run-pass/rfc-1937-termination-trait/termination-trait-in-test.stage2-x86_64-unknown-linux-gnu.aux"
---
[01:13:13] error: functions used as tests returning Result<_, _> must not use #[should_panic]
[01:13:13]   --> /checkout/src/test/run-pass/rfc-1937-termination-trait/termination-trait-in-test.rs:28:1
[01:13:13]    |
[01:13:13] 28 | / fn not_a_num() -> Result<(), ParseIntError> {
[01:13:13] thread 'main' panicked at 'Some tests failed', tools/compiletest/src/main.rs:486:22
[01:13:13] 29 | |     //~^ ERROR test functions returning Result<_, _> must not use #[should_panic]
[01:13:13] 30 | |     let _: u32 = "abc".parse()?;
[01:13:13] 31 | |     Ok(())
---
[01:13:13] command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-tools-bin/compiletest" "--compile-lib-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib" "--run-lib-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/x86_64-unknown-linux-gnu/lib" "--rustc-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "--src-base" "/checkout/src/test/run-pass" "--build-base" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/run-pass" "--stage-id" "stage2-x86_64-unknown-linux-gnu" "--mode" "run-pass" "--target" "x86_64-unknown-linux-gnu" "--host" "x86_64-unknown-linux-gnu" "--llvm-filecheck" "/usr/lib/llvm-3.9/bin/FileCheck" "--host-rustcflags" "-Crpath -O -Zmiri -Zunstable-options " "--target-rustcflags" "-Crpath -O -Zmiri -Zunstable-options  -Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "--docck-python" "/usr/bin/python2.7" "--lldb-python" "/usr/bin/python2.7" "--gdb" "/usr/bin/gdb" "--quiet" "--llvm-version" "3.9.1\n" "--system-llvm" "--cc" "" "--cxx" "" "--cflags" "" "--llvm-components" "" "--llvm-cxxflags" "" "--adb-path" "adb" "--adb-test-dir" "/data/tmp/work" "--android-cross-path" "" "--color" "always"
[01:13:13] expected success, got: exit code: 101
[01:13:13]
[01:13:13]
[01:13:13] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test
[01:13:13] Build completed unsuccessfully in 0:18:22
[01:13:13] Makefile:58: recipe for target 'check' failed
[01:13:13] make: *** [check] Error 1
---
$ ls -lat $HOME/Library/Logs/DiagnosticReports/
ls: cannot access /home/travis/Library/Logs/DiagnosticReports/: No such file or directory
travis_time:end:02b1e9e6:start=1523567133345765549,finish=1523567133351418619,duration=5653070
travis_fold:end:after_failure.2
travis_fold:start:after_failure.3
travis_time:start:1b3d3a5c
$ find $HOME/Library/Logs/DiagnosticReports -type f -name '*.crash' -not -name '*.stage2-*.crash' -not -name 'com.apple.CoreSimulator.CoreSimulatorService-*.crash' -exec printf travis_fold":start:crashlog\n\033[31;1m%s\033[0m\n" {} \; -exec head -750 {} \; -exec echo travis_fold":"end:crashlog \; || true
find: `/home/travis/Library/Logs/DiagnosticReports': No such file or directory
travis_time:end:1b3d3a5c:start=1523567133356503736,finish=1523567133361696381,duration=5192645
travis_fold:end:after_failure.3
travis_fold:start:after_failure.4
travis_time:start:073f3a70
$ dmesg | grep -i kill
[   10.488973] init: failsafe main process (1093) killed by TERM signal

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

@rcoh
Copy link
Contributor Author

rcoh commented Apr 12, 2018

Cool. On the plus side the build failed because my change actually worked :-) Once my local rust install finally compiles enough to run the tests I'll finish it up.

What's the plan re: #[bench]? I assume it will get the same treatment, but perhaps in a different issue / PR

@rcoh rcoh changed the title WIP for Unit tests with non-() type Support Unit tests with non-() type Apr 12, 2018
@rcoh rcoh changed the title Support Unit tests with non-() type Don't allow #[should_panic] with non-() tests Apr 12, 2018
@rcoh
Copy link
Contributor Author

rcoh commented Apr 12, 2018

@nikomatsakis updated with feedback and build passing

@rcoh
Copy link
Contributor Author

rcoh commented Apr 13, 2018

r? @nikomatsakis

Copy link
Contributor

@nikomatsakis nikomatsakis left a comment

Choose a reason for hiding this comment

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

Looks great, one nit

diag.span_err(i.span, "functions used as tests can not have any arguments"),
BadTestSignature::ShouldPanicOnlyWithNoArgs =>
diag.span_err(i.span,
"functions used as tests returning Result<_, _> must \
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's phrase this differently; the test may not actually be returning Result, but rather any Termination type. How about:

functions using `#[should_panic]` must return `()`

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I like that better, changing.

@rcoh
Copy link
Contributor Author

rcoh commented Apr 13, 2018

Updated @nikomatsakis (btw, please let me know if this is the desired way of indicating that it's ready for review again. I'm not sure if there is an incantation to swap the label back to waiting-on-review

@scottmcm scottmcm added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Apr 14, 2018
@pietroalbini pietroalbini added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Apr 23, 2018
@pietroalbini
Copy link
Member

Ping from triage! Can @nikomatsakis (or someone else from @rust-lang/compiler) review this?

@oli-obk
Copy link
Contributor

oli-obk commented Apr 23, 2018

@rcoh can you squash all the commits into one (and give that commit a meaningful message like the PR topic?)

@rcoh
Copy link
Contributor Author

rcoh commented Apr 24, 2018

@oli-obk squashed

@oli-obk
Copy link
Contributor

oli-obk commented Apr 24, 2018

@bors r=nikomatsakis

@bors
Copy link
Contributor

bors commented Apr 24, 2018

📌 Commit 14e5e0e has been approved by nikomatsakis

@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-review Status: Awaiting review from the assignee but also interested parties. labels Apr 24, 2018
@bors
Copy link
Contributor

bors commented Apr 24, 2018

⌛ Testing commit 14e5e0e with merge 2a6200a...

bors added a commit that referenced this pull request Apr 24, 2018
Don't allow #[should_panic] with non-() tests

Adds (removes) support for `#[should_panic]` when the test is non-`()`
@bors
Copy link
Contributor

bors commented Apr 24, 2018

☀️ Test successful - status-appveyor, status-travis
Approved by: nikomatsakis
Pushing 2a6200a to master...

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. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants