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

First step towards rustfix compiletest mode #50084

Merged
merged 7 commits into from
May 5, 2018

Conversation

killercup
Copy link
Member

@killercup killercup commented Apr 19, 2018

This is the first small step towards testing auto-fixable compiler
suggestions using compiletest. Currently, it only checks if next to a
UI test there also happens to a *.rs.fixed file, and then uses rustfix
(added as external crate) on the original file, and asserts that it
produces the fixed version.

To show that this works, I've included one such test. I picked this test
case at random (and because it was simple) -- It is not relevant to the
2018 edition. Indeed, in the near future, we want to be able to restrict
rustfix to edition-lints, so this test cast might go away soon.

In case you still think this is somewhat feature-complete, here's a
quick list of things currently missing that I want to add before telling
people they can use this:

  • Make this an actual compiletest mode, with test [fix] … output
    and everything
  • Assert that fixed files still compile
  • Assert that fixed files produce no (or a known set of) diagnostics
    output
  • Update update-references.sh to support rustfix
  • Use a published version of rustfix (i.e.: publish a new version
    rustfix that exposes a useful API for this)

@killercup
Copy link
Member Author

r? @Manishearth

@Manishearth
Copy link
Member

I'd rather not have this a separate mode, and instead be a feature of UI tests themselves.

@rust-highfive
Copy link
Collaborator

The job x86_64-gnu-llvm-3.9 of 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:04:51] travis_fold:start:tidy
travis_time:start:tidy
tidy check
[00:04:52] tidy error: /checkout/src/tools/compiletest/src/runtest.rs:2591: TODO is deprecated; use FIXME
[00:04:52] tidy error: /checkout/src/tools/compiletest/src/autofix.rs: incorrect license
[00:04:53] some tidy checks failed
[00:04:53] 
[00:04:53] 
[00:04:53] command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-tools-bin/tidy" "/checkout/src" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "--no-vendor" "--quiet"
[00:04:53] 
[00:04:53] 
[00:04:53] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test src/tools/tidy
[00:04:53] Build completed unsuccessfully in 0:01:55
[00:04:53] Build completed unsuccessfully in 0:01:55
[00:04:53] Makefile:79: recipe for target 'tidy' failed
[00:04:53] make: *** [tidy] Error 1

The command "stamp sh -x -c "$RUN_SCRIPT"" exited with 2.
travis_time:start:0cbb9d72
$ date && (curl -fs --head https://google.com | grep ^Date: | sed 's/Date: //g' || true)

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)

@kennytm kennytm added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Apr 19, 2018
@@ -13,6 +13,7 @@ regex = "0.2"
serde = "1.0"
serde_json = "1.0"
serde_derive = "1.0"
rustfix = { git = "https://github.com/rust-lang-nursery/rustfix" }
Copy link
Member

Choose a reason for hiding this comment

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

We should publish before landing

let mut new_content = String::new();

// Add the lines before the section we want to replace
new_content.push_str(&file_content
Copy link
Member

Choose a reason for hiding this comment

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

I feel like this API should be within rustfix itself, ideally shared with the rest of the code.

This also allocates once per suggestion.

Perhaps rustfix should have an API where it applies all suggestions in order, with a callback for asking for confirmation and stuff (which we pass as an empty callback here)

The purpose of this is both to test rustfix and the suggestions, so we need to use the same code as rustfix here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, absolutely. This is just the simplest code that works.

@bors
Copy link
Contributor

bors commented Apr 21, 2018

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

@shepmaster
Copy link
Member

Ping from triage @killercup ! Will you have time to address the review feedback soon?

@killercup
Copy link
Member Author

I'll have time to update this PR tomorrow (thank god bors for May Day)

@killercup
Copy link
Member Author

@alexcrichton asked how this PR and rustfix in general was doing.

I was only able to make little progress here today. The PR is rebased and I moved the API for fixing suggestions to the rustfix crate (still unpublished, but that shouldn't be a blocker).

Next immediate step is to add compiling of fixed files and asserting previously observed warnings are gone. After that, filtering of edition-critical lints.

@rust-highfive
Copy link
Collaborator

The job x86_64-gnu-llvm-3.9 of 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:05:15] travis_fold:start:tidy
travis_time:start:tidy
tidy check
[00:05:16] tidy error: /checkout/src/tools/compiletest/src/runtest.rs:2609: TODO is deprecated; use FIXME
[00:05:16] tidy error: /checkout/src/tools/compiletest/src/runtest.rs:2610: line longer than 100 chars
[00:05:16] tidy error: /checkout/src/tools/compiletest/src/runtest.rs:2623: TODO is deprecated; use FIXME
[00:05:17] some tidy checks failed
[00:05:17] 
[00:05:17] 
[00:05:17] command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-tools-bin/tidy" "/checkout/src" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "--no-vendor" "--quiet"
[00:05:17] 
[00:05:17] 
[00:05:17] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test src/tools/tidy
[00:05:17] Build completed unsuccessfully in 0:02:06
[00:05:17] Build completed unsuccessfully in 0:02:06
[00:05:17] make: *** [tidy] Error 1
[00:05:17] Makefile:79: recipe for target 'tidy' failed

The command "stamp sh -x -c "$RUN_SCRIPT"" exited with 2.
travis_time:start:0a9e736c
$ date && (curl -fs --head https://google.com | grep ^Date: | sed 's/Date: //g' || true)

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)

@rust-highfive
Copy link
Collaborator

The job x86_64-gnu-llvm-3.9 of 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:04:45] travis_fold:start:tidy
travis_time:start:tidy
tidy check
[00:04:46] tidy error: /checkout/src/tools/compiletest/src/runtest.rs:2610: line longer than 100 chars
[00:04:47] some tidy checks failed
[00:04:47] 
[00:04:47] 
[00:04:47] command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-tools-bin/tidy" "/checkout/src" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "--no-vendor" "--quiet"
[00:04:47] 
[00:04:47] 
[00:04:47] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test src/tools/tidy
[00:04:47] Build completed unsuccessfully in 0:01:52
[00:04:47] Build completed unsuccessfully in 0:01:52
[00:04:47] Makefile:79: recipe for target 'tidy' failed
[00:04:47] make: *** [tidy] Error 1

The command "stamp sh -x -c "$RUN_SCRIPT"" exited with 2.
travis_time:start:3df2d08c
$ date && (curl -fs --head https://google.com | grep ^Date: | sed 's/Date: //g' || true)

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)

@alexcrichton
Copy link
Member

Awesome thanks for the cc @killercup!

I'm curious, though, would it perhaps be best to put tests into the rustfix crate itself? I'd imagine that'd allow for much faster iteration on rustfix itself. Or is the purpose here to test suggestions as they are added to rustc, using what's likely to be a relatively stable base in rustfix?

I can try to clean up some of the todo items here tomorrow, I've had some experience in the past adding new rustfix modes and whatnot.

@killercup
Copy link
Member Author

killercup commented May 1, 2018 via email

@alexcrichton alexcrichton force-pushed the compiletest-rustfix branch 2 times, most recently from 9c4ffbf to 4ea828b Compare May 2, 2018 16:02
@alexcrichton
Copy link
Member

Ok I've pushed up a commit that makes a dedicated suite for rustfix tests and populated with a set of working tests from src/test/ui/suggestions.

I think the last step here is to publish rustfix to crates.io and get it pulled in from there.

@killercup would it be possible to split out the binary/library to avoid having compiletest depend on dependencies like clap in this repo?

@killercup
Copy link
Member Author

Thanks so much, @alexcrichton!

@Manishearth said in #50084 (comment) he'd rather see this is part of the UI tests, probably to speed the tests up and to see the regular diagnostics at the same time.

@alexcrichton
Copy link
Member

@Manishearth can you elaborate on the idea for a UI mode? The implementation here with the necessary bells and whistles seems like it's pretty different from UI and somewhat makes sense as a separate mode?

@Manishearth
Copy link
Member

In general I see the process of testing such things to be the same as the process for testing things that need UI tests; i.e. if you're writing a fixture test you're probably also going to write a UI test.

This also makes it easy to "upgrade" UI tests to fixture tests by adding a .fixed file, which hopefully will improve rustc suggestions overall.

@killercup
Copy link
Member Author

I think the "upgrade UI tests" workflow is pretty powerful: Ideally, we'd be able to make one PR soon that adds .fixed files for all the UI tests that already compile after running rustfix, and then open a "help wanted" issue with a list of UI tests whose suggestions are broken. With some good instructions this could get people involved just like the "new diagnostics" effort a few years ago.

That said, it's not important right now: We only care about a handful of lints right now.

@alexcrichton alexcrichton changed the title WIP: First step towards rustfix compiletest mode First step towards rustfix compiletest mode May 3, 2018
@alexcrichton
Copy link
Member

Ok sounds good to me! I've folded this back into the UI test suite with the following implementation:

  • The presence of // run-rustfix will execute rustfix and ensure the compiled code has no errors
  • Rustfix assertions are located at name.fixed
  • If name.fixed exists and // run-rustfix isn't specified, an error is generated

@alexcrichton
Copy link
Member

r? @Manishearth

@killercup
Copy link
Member Author

Thanks for working on this, @alexcrichton!

If name.fixed exists and // run-rustfix isn't specified, an error is generated

Why? Is this to trigger the "ensure the compiled code has no errors" thing? Would it make sense to add a .fixed.stderr file, so to run UI tests against the fixed file too?

Also: Can we rename .rs.fixed to .fixed.rs to get syntax highlighting? (I only just noticed this and I know it's my fault.)

@alexcrichton
Copy link
Member

@bors: r=Manishearth

@bors
Copy link
Contributor

bors commented May 4, 2018

📌 Commit e539c2b has been approved by Manishearth

@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 May 4, 2018
@bors
Copy link
Contributor

bors commented May 4, 2018

🔒 Merge conflict

@bors bors 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-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels May 4, 2018
killercup and others added 7 commits May 4, 2018 15:01
This is the first small step towards testing auto-fixable compiler
suggestions using compiletest. Currently, it only checks if next to a
UI test there also happens to a `*.rs.fixed` file, and then uses rustfix
(added as external crate) on the original file, and asserts that it
produces the fixed version.

To show that this works, I've included one such test. I picked this test
case at random (and because it was simple) -- It is not relevant to the
2018 edition. Indeed, in the near future, we want to be able to restrict
rustfix to edition-lints, so this test cast might go away soon.

In case you still think this is somewhat feature-complete, here's a
quick list of things currently missing that I want to add before telling
people they can use this:

- [ ] Make this an actual compiletest mode, with `test [fix] …` output
  and everything
- [ ] Assert that fixed files still compile
- [ ] Assert that fixed files produce no (or a known set of) diagnostics
  output
- [ ] Update `update-references.sh` to support rustfix
- [ ] Use a published version of rustfix (i.e.: publish a new version
  rustfix that exposes a useful API for this)
Uses branch from <rust-lang/rustfix#63>
until we publish a new release.
This commit adds a dedicated mode to compiletest for running rustfix tests,
adding a new `src/test/rustfix` directory which will execute all tests as a
"rustfix" test, namely requiring that a `*.fixed` is next to the main file which
is the result of the rustfix project's application of fixes.

The `rustfix` crate is pulled in to actually perform the fixing, and the rustfix
compiletest mode will assert a few properties about the fixing:

* The expected fixed output must be the same as rustc's output suggestions
  applied to the original code.
* The fixed code must compile successfully
* The fixed code must have no further diagnostics emitted about it
@alexcrichton
Copy link
Member

@bors: r=Manishearth

@bors
Copy link
Contributor

bors commented May 4, 2018

📌 Commit 6f2d023 has been approved by Manishearth

@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 May 4, 2018
@bors
Copy link
Contributor

bors commented May 4, 2018

⌛ Testing commit 6f2d023 with merge 1d16826...

bors added a commit that referenced this pull request May 4, 2018
First step towards rustfix compiletest mode

This is the first small step towards testing auto-fixable compiler
suggestions using compiletest. Currently, it only checks if next to a
UI test there also happens to a `*.rs.fixed` file, and then uses rustfix
(added as external crate) on the original file, and asserts that it
produces the fixed version.

To show that this works, I've included one such test. I picked this test
case at random (and because it was simple) -- It is not relevant to the
2018 edition. Indeed, in the near future, we want to be able to restrict
rustfix to edition-lints, so this test cast might go away soon.

In case you still think this is somewhat feature-complete, here's a
quick list of things currently missing that I want to add before telling
people they can use this:

- [x] Make this an actual compiletest mode, with `test [fix] …` output
  and everything
- [x] Assert that fixed files still compile
- [x] Assert that fixed files produce no (or a known set of) diagnostics
  output
- [x] Update `update-references.sh` to support rustfix
- [x] Use a published version of rustfix (i.e.: publish a new version
  rustfix that exposes a useful API for this)
@bors
Copy link
Contributor

bors commented May 5, 2018

☀️ Test successful - status-appveyor, status-travis
Approved by: Manishearth
Pushing 1d16826 to master...

@bors bors merged commit 6f2d023 into rust-lang:master May 5, 2018
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Aug 29, 2021
…Simulacrum

Remove vestigial rustfix tests.

The directory `src/test/rustfix` is not actually tested. It looks like a mistake was made when rustfix tests were originally introduced in rust-lang#50084.  In commit 6f2d023 they were moved to `src/test/ui`, but the tests in the original directory weren't deleted.
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.

None yet

7 participants