-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Support proper parse the file name in mingw platform. #1014
Conversation
Please add a test using the example from your regex link regex = /^[^:]+/
caller_line = "c:/git/emberjs/ember-crm-backend/app/serializers/lead_serializer.rb:1:in `<top (required)>'"
regex.match(caller_line) #=> #<MatchData "c">
caller_line = "c/git/emberjs/ember-crm-backend/app/serializers/lead_serializer.rb:1:in `<top (required)>'"
regex.match(caller_line) #=> #<MatchData "c/git/emberjs/ember-crm-backend/app/serializers/lead_serializer.rb"> Also, while in here, it might be worth changing the |
Looks like if you change the regex to use a lookahead it works fine CALLER_FILE = /
/A # start of string
\S+ # one or more non-spaces
(?= # stop previous match when
:\d+:in # a colon is followed by one or more digits
# followed by a colon followed by in
)
/x |
@bf4 I just change code to using only CALLER_FILE pattern, also using File.read. it's a bit too hard for me to add a testing, so I just write commit comments instead. 😄 |
serializer_file = File.open(caller.first[/^[^:]+/]) | ||
base._cache_digest = Digest::MD5.hexdigest(serializer_file.read) | ||
serializer_file_path = caller.first[/\A\S+(?=:\d+:in)/] | ||
base._cache_digest = Digest::MD5.hexdigest(File.read(serializer_file_path)) | ||
end |
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.
needs a test!
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.
😈 (yay!)
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.
OK, be seriously, there is already testing existing, but the problem is if you not running in Windows, c:/git won't return to you from ruby side, so it's really hard to write a test to testing that case in Linux.
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.
@bf4 So if you really care about Windows user, just merge this PR and I will propose another to fix testing suite in windows, because even current testing case is not all pass in windows...
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.
if you really care about Windows user
Of course I care. No reason not add a regression test
Also, I'm not a collab so I can't merge it sorry :)
@kurko @joaomdmoura Let's see if we can set up an appveyor account to test on windows. I know RSpec does this and it works pretty well.
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.
using the appveyor is right, since current testing case running in windows can already cover this problem.
But seems its complex and really necessory? Just relay on me should enough, I will definitely working on windows and always report/fix issue if found.
As Windows user, really don't expect we will be regarded as first class support tie like Mac/Linux in Rails ecosystem. 😭
Hey ppl. First of all @Eric-Guo we care about all users. |
58dc096
to
7e5e2b4
Compare
c5cee81
to
5f131b8
Compare
|
I'm happy to pair or pull in your commit |
Sorry, seems after code rebase, some of the comments lost, the existing serialization_scope_name_test can already cover this change, the only problem is caller will return 'c:\git\path' only in Windows, so you can not catch it if you running test suite in Linux/Mac. 😅 |
8c471cd
to
f319d40
Compare
So we will got full file path instead of only c if caller.first is: c:/git/emberjs/ember-crm-backend/app/serializers/lead_serializer.rb:1:in `<top (required)>' CALLER_FILE = / /A # start of string \S+ # one or more non-spaces (?= # stop previous match when :\d+:in # a colon is followed by one or more digits # followed by a colon followed by in ) /x credit from https://gist.github.com/mikezter/540132 and @bf4
@Eric-Guo I made a PR into your master branch with tests. Would you be willing to merge that in so we can merge this? Eric-Guo#1 |
Test caller line parsing and digesting
@bf4 thanks, I running in Windows and new add testing pass after add tzdata, only one testing failed.
|
@joaomdmoura appreciate could merge this now? |
@@ -15,3 +15,6 @@ if version == "master" | |||
else | |||
gem "rails", "~> #{version}.0" | |||
end | |||
|
|||
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem | |||
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] |
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.
jruby doesn't either? or jruby on windows?
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.
@bf4 it's just copy from Railties app template, not known jruby status.
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.
Oh, then that works for me. Since we don't have a Gemfile.lock in version control, we don't even need to edit that.
@Eric-Guo you're saying you have one test failing on windows |
@joaomdmoura @bf4 serializer_generator_test also fixed, because in windows, using \r\n instead of \n. |
assert_no_match /\r\n\r\nend/, content | ||
else | ||
assert_no_match /\n\nend/, content | ||
end |
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.
@Eric-Guo you can just assert_no_match /\r?\n\r?\nend/, content
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.
Can not write like assert_no_match /\r?\n\r?\nend/, content
, because will cause below error.
1) Failure:
SerializerGeneratorTest#test_with_no_attributes_does_not_add_extra_space [c:/git/emberjs/active_model_serializers/test/g
enerators/serializer_generator_test.rb:48]:
Expected /\r?\n\r?\nend/ to not match "\nclass AccountSerializer < ActiveModel::Serializer\n attributes :id\n\nend\n\n"
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.
Or if you want to get wild
# record_separator = $-0 == $/
assert_no_match /#{record_separator}#{record_separator}end/, content
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.
thanks @bf4 give many help and suggestion
FYI: #1066 |
Awesome! |
thanks @bf4 give many help and suggestion, original PR rails-api#1014
Now PR to appveyor branch at #1071 |
Original regexp will failed the file name parse in Windows.
Example link: http://rubular.com/r/QRJfZ11BZL