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

Update Coverage for Ruby 3.2 interface changes. #3150

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/truffle/coverage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@

module Coverage

def self.start
def self.supported?(mode)
mode == :lines
end

def self.start(*arguments, **options)
# Arguments/options are ignored.
Copy link
Member

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>'

Copy link
Member

@eregon eregon Jul 6, 2023

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.

Copy link
Contributor Author

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.

Copy link
Member

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?).

Truffle::Coverage.enable
end

Expand Down