-
Notifications
You must be signed in to change notification settings - Fork 533
JRuby on Windows #480
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
JRuby on Windows #480
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In addition to the code comment, is there a test that fails without this change? The JRuby build seems to have been passing. If there isn't, can you please make one?
# Check if on Windows via RUBY_PLATFORM (CRuby) and RUBY_DESCRIPTION (JRuby) | ||
win_platform_regex = /mingw|mswin/ | ||
return "'#{s && s.to_s.gsub('\'','\'"\'"\'')}'" if RUBY_PLATFORM !~ win_platform_regex && RUBY_DESCRIPTION !~ win_platform_regex | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about shortening this to the more intention revealing:
def escape(s)
return escape_for_windows(s) if windows_platform?
escape_for_sh(s) # not sure what the best name for this method is: are we escaping for sh? linux? linux_shell?
end
Then move the existing code to fill in the new methods referenced above. Then add a test (or more) for each method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure. I agree that the suggested refactorings into intention revealing methods make the code a lot more readable/understandable.
I re-ran the build and the status was updated. Not sure why it wasn't updating before. |
1bc69ac
to
63a5193
Compare
Good question. As you probably noticed, I've been trying to update the Travis CI build to include Windows. I think the current tests are sufficient if run on Windows as they test that I was able to add a Windows Ruby build and got 5 failures and a number of errors in it. I'm hunting them one by one on my machine right now. The Windows JRuby build seems like no dice at the moment as Travis CI doesn't officially support it, so I'm manually scripting installation of JRuby with a Travis CI shell script, but if I don't get it working, the Windows Ruby build would probably suffice and should help quite a bit in testing Windows support in general with the only difference in JRuby being to check the RUBY_DESCRIPTION on top of RUBY_PLATFORM to ascertain Windows from non-Windows environments. This is a fun break from some tough work I was busy with last week, so I'm more than happy to involve myself with this. I hope you're not in a rush. I'm taking my time given that I need a break from last week. Thanks for acknowledging the bug and for providing code refactoring feedback that I agree makes the code more readable. I look forward to addressing all failing Windows Ruby tests and performing the refactoring in the foreseeable future. Godspeed. p.s. Once done, I'll make sure to rebase the latest code from trunk/master too since it's been a little while since I reported this.. |
No rush, carry on at your own pace. |
If you want to break down this PR, you could add the new Travis CI builds first, in a separate PR. You can marking the Windows Ruby build(s) as optional so they don't impact others. It would be nice to have Ruby 2.7 added sooner than later. |
d83c645
to
6194bdb
Compare
71af01d
to
79b1ed0
Compare
Done. I marked the Windows Ruby build(s) as optional. I got both Ruby Windows and JRuby Windows working. I took off Ruby 2.7 (it's a in a separate pull request now). In summary, the changes mostly focus on removing reliance on bash shell commands that are incompatible with Windows, such as Thanks for making the Ruby Godspeed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just had one comment about the encoding tests.
Also, can you please catch up to master and squash commits when you are ready?
@@ -35,13 +35,15 @@ def setup | |||
def test_diff_with_greek_encoding | |||
d = @git.diff | |||
patch = d.patch | |||
return unless Encoding.default_external == (Encoding::UTF_8 rescue Encoding::UTF8) # skip test on Windows / check UTF8 in JRuby instead |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is quite right. What do you think about this:
skip 'Encoding tests do not work in Windows' if windows_platform?
On other platforms, these tests should work not matter what the external encoding is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I forgot to mention... I have not ever seen rescue
used in this way. Can you point me to something that explains how you are using it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
About your first question, if you can figure out a better way to skip tests on Windows, then power to you! After all, they do not work in their current form inside the Windows Command Prompt or Git Bash and I did not feel it was important enough for me to invest more time into it (especially given that there was zero coverage before to begin with, so any coverage now is better than nothing)
About your second question, I learned this from a senior Ruby developer called Chris Sepic more than a decade ago while working at this Chicago suburb company, Leapfrog Online.
Basically, in rare cases where you do not need to do anything with the error exception object, instead of doing this:
begin
try_something
rescue => e
do_nothing_with_e
end
You can drop the error exception object:
begin
try_something
rescue
do_something
end
And then finally, you can fold it into one line:
try_something rescue do_something
I don't advise using this in the majority of cases. I only used it because this was a test (not production code) and brevity helped keep things on one line.
Specifically, there is this odd quirk about JRuby where it calls the encoding constant UTF8 instead of UTF_8, so instead of me writing something very long and elaborate to check it such as:
if Encoding.constants.include?(:UTF_8)
# do something with Encoding::UTF_8
elsif Encoding.constants.include?(:UTF8)
# do something with Encoding::UTF8
end
I just shortened it knowing that if you call `Encoding::UTF_8` in JRuby, it bombs, and then the `rescue` keyword rescues it unto the next value to compare to, which is `Encoding::UTF8`
Again, this is not a recommended technique in general. I just did it because it was low-risk code in a test (spec).
assert(patch.include?("-Φθγητ οπορτερε ιν ιδεριντ\n")) | ||
assert(patch.include?("+Φεθγιατ θρβανιτασ ρεπριμιqθε\n")) | ||
end | ||
|
||
def test_diff_with_japanese_and_korean_encoding | ||
d = @git.diff.path('test2.txt') | ||
patch = d.patch | ||
return unless Encoding.default_external == (Encoding::UTF_8 rescue Encoding::UTF8) # skip test on Windows / check UTF8 in JRuby instead |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here.
Signed-off-by: Andy Maleh <andy.am@gmail.com>
Hi, it's been a month since I made the changes. I was wondering if there is anything else you need of me before merging this pull request. I have been relying on my own fork (git-glimmer) for my project Glimmer DSL for SWT in the meantime. I was hoping I would move back to the Cheers, Andy p.s. Regarding |
Your checklist for this pull request
🚨Please review the guidelines for contributing to this repository.
Description
Please describe your pull request.
Hi, I encountered an issue with using git gem (via jeweler gem) on Windows running in JRuby.
It turns out it was not escaping strings properly because it was running in JRuby instead of CRuby, thus not detecting Windows correctly via RUBY_PLATFORM. I fixed it by adding a check for RUBY_DESCRIPTION too.
Cheers.