Skip to content

Commit 1dacb04

Browse files
mtortonesiandrykonchin
authored andcommitted
Coverage#result: added support for stop and clear arguments and fixed a couple of bugs.
1 parent 967f3a6 commit 1dacb04

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

lib/truffle/coverage.rb

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,19 @@ def self.start(*arguments, **options)
2222
Truffle::Coverage.enable
2323
end
2424

25-
def self.result
25+
def self.result(stop: true, clear: true)
2626
result = peek_result
27-
Truffle::Coverage.disable
27+
Truffle::Coverage.disable if stop || clear
28+
Truffle::Coverage.enable if !stop && clear
2829
# We have to wrap the coverage lines array in a hash with the :lines key if
2930
# the :lines option was given
30-
result.transform_values! { |_,lines_array| {lines: lines_array} } if @lines
31+
if @lines
32+
result.transform_values! do |_,*lines_array|
33+
# need to add nil to the beginning of each lines array, because the
34+
# first line has index 1 and not 0
35+
{ lines: lines_array.unshift(nil) }
36+
end
37+
end
3138
result
3239
end
3340

0 commit comments

Comments
 (0)