-
Notifications
You must be signed in to change notification settings - Fork 190
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
Update Coverage for Ruby 3.2 interface changes. #3150
Conversation
You mean there are already specs for this, right? Like https://github.com/ruby/spec/blob/master/library/coverage/supported_spec.rb |
Do you mind doing this untag process? I am in Japan with only my laptop and apparently arm64 is not a supported architecture :) |
end | ||
|
||
def self.start(*arguments, **options) | ||
# Arguments/options are ignored. |
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.
This doesn't seem correct, e.g. if lines: false
we shouldn't enable coverage.
For unknown kwargs, should we raise ArgumentError?
Surprisingly CRuby seems to ignores extra kwargs:
$ ruby -v -rcoverage -e 'Coverage.start(foo: true)'
ruby 3.2.2 (2023-03-30 revision e51014f9c0) [x86_64-linux]
But it does not allow any positional argument:
$ ruby -v -rcoverage -e 'Coverage.start(1)'
ruby 3.2.2 (2023-03-30 revision e51014f9c0) [x86_64-linux]
-e:1:in `start': no implicit conversion of Integer into Hash (TypeError)
Coverage.start(1)
^
from -e:1:in `<main>'
$ ruby -v -rcoverage -e 'Coverage.start(1, foo: true)'
ruby 3.2.2 (2023-03-30 revision e51014f9c0) [x86_64-linux]
-e:1:in `start': wrong number of arguments (given 2, expected 0..1) (ArgumentError)
Coverage.start(1, foo: true)
^^^^^^^^^^^^
from -e:1:in `<main>'
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.
This doesn't seem correct, e.g. if
lines: false
we shouldn't enable coverage.
Actually that seems the CRuby semantics :/
So that part seems OK.
$ ruby -v -rcoverage -e 'Coverage.start(foo: true); p Coverage.running?'
ruby 3.2.2 (2023-03-30 revision e51014f9c0) [x86_64-linux]
true
(and also ruby -v -rcoverage -e 'Coverage.start(foo: true); p Coverage.running?; require "drb"; p Coverage.result'
)
Even for lines: false
it enables 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.
Maybe we should write more ruby specs for this behaviour? I think we can tighten it up for 3.3.
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.
Yes that would be great, and you can add the specs in this PR and they'll get sync'd in ruby/spec.
I think we can tighten it up for 3.3.
I'm not sure we can change this confusing behavior, compatibility-wise. At least it seems useful to spec the current behavior, even though it's confusing.
Maybe it's designed so Coverage.start
never raises an error or so (when there wasn't Coverage.supported?
).
It is supported (both on linux and macos). |
Are you sure there is nothing wrong with the result method too? I applied your patch to truffleruby+graalvm-23.0.0 (installed from rbenv) and in my code using sus+covered I keep getting: core/type.rb:276:in `convert_type': no implicit conversion of Symbol into Integer (TypeError) from core/type.rb:178:in `rb_to_int_fallback' from /Users/mauro/.rbenv/versions/truffleruby+graalvm-23.0.0/graalvm/Contents/Home/languages/ruby/lib/gems/gems/covered-0.21.0/lib/covered/capture.rb:40:in `[]' Apparently, result returns a Hash of this type: { "/Users/mauro/.rbenv/versions/truffleruby+graalvm-23.0.0/graalvm/Contents/Home/languages/ruby/lib/gems/gems/sus-0.21.1/lib/sus/tree.rb"=>[1, 1, 1, 0, nil, nil, 1, 0, nil, 0, nil, 0, 0, 0, nil, nil, nil, 0, nil, nil, 1, 0, 0, nil, nil, nil, nil], ... but the covered code expects a hash with a :lines key instead of an array. |
@mtortonesi Interesting, that seems a difference between
|
@eregon wow. You really weren't kidding about Coverage having a "confusing behavior"... What is the best way to deal with that? Adding to TruffleRuby's Coverage class a class variable keeping track if the start method was called with a :lines argument? |
Yeah Ruby's Right, that could be tracked as an instance variable on the Coverage module. |
Can confirm this code works for me: def self.start(*arguments, **options)
# Arguments/options are ignored
@lines = true if options[:lines]
Truffle::Coverage.enable
end
def self.result
result = peek_result
Truffle::Coverage.disable
result.transform_values! { |_,lines_array| {lines: lines_array} } if @lines
result
end AFAIK, transform_values! is Ruby 2.4+ only, though. |
@ioquatix Could you integrate that in your PR and add specs? |
I'll close this in favour of #3151 |
Fixes #3149.
Related #1636.
Tests for this should be in ruby spec itself.