Skip to content

Commit

Permalink
Merge pull request #371 from danmayer/support_coverage_options
Browse files Browse the repository at this point in the history
handle stdlib branch coverage options, now a default in simplecov 0.1…
  • Loading branch information
danmayer committed Apr 13, 2020
2 parents 8cd0841 + a48192f commit edbba0b
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 8 deletions.
4 changes: 4 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ Style/ClassVars:
Enabled: false
Style/MultilineBlockChain:
Enabled: false
Style/StringLiterals:
Enabled: false
Style/IfInsideElse:
Enabled: false
Style/FrozenStringLiteralComment:
Enabled: true
Style/GuardClause:
Expand Down
15 changes: 10 additions & 5 deletions lib/coverband/collectors/coverage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,17 @@ def initialize
raise NotImplementedError, 'Coverage needs Ruby > 2.3.0' if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.3.0')

require 'coverage'
if Coverage.ruby_version_greater_than_or_equal_to?('2.6.0')
::Coverage.start(oneshot_lines: Coverband.configuration.use_oneshot_lines_coverage) unless ::Coverage.running?
elsif Coverage.ruby_version_greater_than_or_equal_to?('2.5.0')
::Coverage.start unless ::Coverage.running?
if defined?(SimpleCov) && defined?(Rails) && defined?(Rails.env) && Rails.env.test?
puts "Coverband: detected SimpleCov in test Env, allowing it to start Coverage"
puts "Coverband: to ensure no error logs or missing Coverage call `SimpleCov.start` prior to requiring Coverband"
else
::Coverage.start
if Coverage.ruby_version_greater_than_or_equal_to?('2.6.0')
::Coverage.start(oneshot_lines: Coverband.configuration.use_oneshot_lines_coverage) unless ::Coverage.running?
elsif Coverage.ruby_version_greater_than_or_equal_to?('2.5.0')
::Coverage.start unless ::Coverage.running?
else
::Coverage.start
end
end
reset_instance
end
Expand Down
10 changes: 8 additions & 2 deletions lib/coverband/collectors/delta.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,17 @@ def self.reset
private

def generate
# TODO: if we filtered before doing this we would avoid calculating the line diff on a ton of files
# This would be a fairly noticeable perf win
current_coverage.each_with_object({}) do |(file, line_counts), new_results|
# This handles Coverage branch support, setup by default in
# simplecov 0.18.x
arr_line_counts = line_counts.is_a?(Hash) ? line_counts[:lines] : line_counts
new_results[file] = if @@previous_coverage && @@previous_coverage[file]
array_diff(line_counts, @@previous_coverage[file])
prev_line_counts = @@previous_coverage[file].is_a?(Hash) ? @@previous_coverage[file][:lines] : @@previous_coverage[file]
array_diff(arr_line_counts, prev_line_counts)
else
line_counts
arr_line_counts
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/coverband/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
# use format '4.2.1.rc.1' ~> 4.2.1.rc to prerelease versions like v4.2.1.rc.2 and v4.2.1.rc.3
###
module Coverband
VERSION = '4.2.5.rc.1'
VERSION = '4.2.5.rc.2'
end
15 changes: 15 additions & 0 deletions test/coverband/collectors/delta_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,21 @@ def setup
assert_equal(current_coverage, results)
end

test 'Coverage has branching enabled and has gone up' do
current_coverage = {
'car.rb' => { lines: [nil, 1, 5, 1] }
}
::Coverage.expects(:peek_result).returns(current_coverage)
results = Coverband::Collectors::Delta.results

current_coverage = {
'car.rb' => { lines: [nil, 1, 7, 1] }
}
::Coverage.expects(:peek_result).returns(current_coverage)
results = Coverband::Collectors::Delta.results
assert_equal({ 'car.rb' => [nil, 0, 2, 0] }, results)
end

if Coverband.configuration.one_shot_coverage_implemented_in_ruby_version?
test 'oneshot coverage calls clear' do
Coverband.configuration.stubs(:use_oneshot_lines_coverage).returns(true)
Expand Down

0 comments on commit edbba0b

Please sign in to comment.