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

ruby-rewrite fails to actually rewrite the input file when a rewriter is loaded. This fixes the issue. #162

Merged
merged 4 commits into from Aug 22, 2014
Merged

Conversation

MrJoy
Copy link
Contributor

@MrJoy MrJoy commented Aug 22, 2014

At the end of the @rewriters.each loop, the value of buffer.name is no longer valid due to debugging annotations:

        new_buffer = Source::Buffer.new(initial_buffer.name +
                                    '|after ' + rewriter_class.name)

This preserves the original name, allowing the file to be properly rewritten.

@MrJoy
Copy link
Contributor Author

MrJoy commented Aug 22, 2014

Test case to follow as soon as I figure out the right strategy for it. Suggestions on your preferred approach would be greatly appreciated.

@whitequark
Copy link
Owner

Your commit message is a bit confusing... could you use something like "- Always rewrite source file with original filename regardless of returned AST" ?

Also, you don't have to recreate the PR. You can force-push the branch (git push -f origin fix_file_rewriting_with_rewriters) and it will update the PR.

I think you can add a rewriter that would trigger the bug, and invoke the runner merely with "system", and then verify that the runner succeeded and the correct file was changed. You could name the file test/test_runner_rewrite.rb, and the sample runner test/rewriter_bug_162.rb or something like that.

Thanks!

@MrJoy
Copy link
Contributor Author

MrJoy commented Aug 22, 2014

The bug is that any rewriter at all will cause the file to not be rewritten. So the message "Always rewrite source file with original filename regardless of returned AST" is a touch misleading as it doesn't actually have anything to do with the AST.

The approach you suggest is what came to mind after perusing the test suite. Glad to hear you find it acceptable! I'll also need a fixture file of course, so I'm inclined to bundle all three files into a sub-directory under test/. Say, test/bug_XXX (I'll file a proper issue momentarily and reference it from here) with files like bug_XXX_rewriter.rb, test_runner_rewrite.rb, and bug_XXX_input.rb. I'll FileUtils.mkdir('test/tmp') and copy the source file in, then assert that the original andtmp/` versions should not be identical.

@MrJoy
Copy link
Contributor Author

MrJoy commented Aug 22, 2014

(And once we suss out ideal commit message, I'll do a force-push here instead of re-submitting again...)

@MrJoy
Copy link
Contributor Author

MrJoy commented Aug 22, 2014

Bug filed as #163

@MrJoy
Copy link
Contributor Author

MrJoy commented Aug 22, 2014

I've confirmed the new test case fails passes with the fix by running:

ruby test/bug_163/test_runner_rewrite.rb

And that it fails without the fix by running:

git revert --no-commit 0e4e2037f11300f2c90f53c817e19f085999012e
ruby test/bug_163/test_runner_rewrite.rb

@MrJoy
Copy link
Contributor Author

MrJoy commented Aug 22, 2014

In light of my clarification, suggested commit message?

…ed, due to it getting confused about the filename.
@MrJoy MrJoy changed the title Actually rewrite source file when rewriters are actually used. ruby-rewrite fails to actually rewrite the input file when a rewriter is loaded. This fixes the issue. Aug 22, 2014
@MrJoy
Copy link
Contributor Author

MrJoy commented Aug 22, 2014

Clarifications provided.

@MrJoy
Copy link
Contributor Author

MrJoy commented Aug 22, 2014

Erk. Travis shows green now: https://travis-ci.org/whitequark/parser/builds/33318214

class TestRunnerRewrite < Minitest::Test
def setup
@ruby_rewrite = BASE_DIR.expand_path + '../bin/ruby-rewrite'
@tmp_dir = BASE_DIR + 'tmp'
Copy link
Owner

Choose a reason for hiding this comment

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

Please use Dir.mktmpdir for this.

@whitequark
Copy link
Owner

Also, the commit messages for the tests shouldn't go into the changelog--so you need to remove the "- " prefix for them.

Otherwise, your PR is fine.

@MrJoy
Copy link
Contributor Author

MrJoy commented Aug 22, 2014

Will fix these up. Can you run travis cache --delete to see if that fixes the Rubinius issue?

@whitequark
Copy link
Owner

@MrJoy That wouldn't work afaik, we'll need to wait until Travis updates images.

@MrJoy
Copy link
Contributor Author

MrJoy commented Aug 22, 2014

Ok. I'm also tossing in a slight tweak that is apparently (waiting on Travis to confirm) harmless elsewhere but seemed to be needed for me to run the tests under Rubinius locally. I can back it out if you don't want. (See commit 1c3237d)

@MrJoy
Copy link
Contributor Author

MrJoy commented Aug 22, 2014

Except for Rubinius issue, all's green in Travis.

whitequark added a commit that referenced this pull request Aug 22, 2014
`ruby-rewrite` fails to actually rewrite the input file when a rewriter is loaded.  This fixes the issue.
@whitequark whitequark merged commit 21ce3d5 into whitequark:master Aug 22, 2014
@MrJoy MrJoy deleted the fix_file_rewriting_with_rewriters branch August 25, 2014 10:18
@MrJoy MrJoy restored the fix_file_rewriting_with_rewriters branch October 1, 2014 04:56
@MrJoy MrJoy deleted the fix_file_rewriting_with_rewriters branch December 13, 2014 23:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants