Skip to content

Commit b15c638

Browse files
committed
Fix Coverage.result and handling of stop and clear options
1 parent bab0dd2 commit b15c638

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

lib/truffle/coverage.rb

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,33 @@ def self.start(modes = Truffle::UNDEFINED)
3535
nil
3636
end
3737

38-
def self.result(stop: true, clear: true)
38+
def self.result(**options)
39+
if options.empty?
40+
stop = true
41+
clear = true
42+
else
43+
stop = options[:stop]
44+
clear = options[:clear]
45+
end
46+
47+
if stop && !clear
48+
warn 'stop implies clear', uplevel: 1
49+
end
50+
3951
result = peek_result
52+
53+
# TODO: There should be a difference between :stop and :clear in a way they affect counters.
54+
# :stop means to remove all the counters at all, :clear - to set 0 values only.
55+
# Now we remove counters in both cases.
4056
Truffle::Coverage.disable if stop || clear
4157
Truffle::Coverage.enable if !stop && clear
4258

43-
# if there is only the default mode (:lines only) - return result as array per file,
44-
# otherwise return result for each mode separately (e.g. for :branches, :methods, :lines)
59+
# By default provides only lines coverage measurement.
60+
# If some mode was specified explicitly then return counters per mode separately (e.g. for :lines, :branches, etc).
61+
# Support only :lines for now.
4562
if !@default_mode
46-
result.transform_values! do |_, *lines_array|
47-
# need to add nil to the beginning of each lines array, because the
48-
# first line has index 1 and not 0
49-
{ lines: lines_array.unshift(nil) }
63+
result.transform_values! do |lines|
64+
{ lines: lines }
5065
end
5166
end
5267

0 commit comments

Comments
 (0)