Skip to content

Commit

Permalink
fix for #536 to cleanup and remove simulate oneshot coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
danmayer committed Jun 2, 2024
1 parent 437a8db commit 3c42c95
Show file tree
Hide file tree
Showing 9 changed files with 5 additions and 34 deletions.
19 changes: 2 additions & 17 deletions lib/coverband/adapters/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,21 +65,8 @@ def raw_store

def split_coverage(types, coverage_cache, options = {})
types.reduce({}) do |data, type|
if type == Coverband::RUNTIME_TYPE && Coverband.configuration.simulate_oneshot_lines_coverage
data.update(type => coverage_cache[type] ||= simulated_runtime_coverage)
else
data.update(type => coverage_cache[type] ||= coverage(type, options))
end
end
end

def simulated_runtime_coverage
runtime_data = coverage(Coverband::RUNTIME_TYPE)
eager_data = coverage(Coverband::EAGER_TYPE)
eager_data.values do |vals|
vals["data"].map! { |line_coverage| line_coverage ? (0 - line_coverage) : line_coverage }
data.update(type => coverage_cache[type] ||= coverage(type, options))
end
merge_reports(runtime_data, eager_data, skip_expansion: true)
end

def merged_coverage(types, coverage_cache)
Expand Down Expand Up @@ -138,14 +125,12 @@ def merge_expanded_data(new_expanded, old_expanded)
}
end

# TODO: This should only be 2 cases get our dup / not dups aligned
# TODO: This should have cases reduced
def array_add(latest, original)
if latest.empty? && original.empty?
[]
elsif Coverband.configuration.use_oneshot_lines_coverage
latest.map!.with_index { |v, i| ((v + original[i] >= 1) ? 1 : 0) if v && original[i] }
elsif Coverband.configuration.simulate_oneshot_lines_coverage
latest.map.with_index { |v, i| ((v + original[i] >= 1) ? 1 : 0) if v && original[i] }
else
latest.map.with_index { |v, i| (v && original[i]) ? v + original[i] : nil }
end
Expand Down
2 changes: 1 addition & 1 deletion lib/coverband/collectors/delta.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def results
transform_oneshot_lines_results(current_coverage)
else
new_results = generate
@@previous_coverage = current_coverage unless Coverband.configuration.simulate_oneshot_lines_coverage
@@previous_coverage = current_coverage
new_results
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/coverband/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def reset
@web_debug = false
@report_on_exit = true
@use_oneshot_lines_coverage = ENV["ONESHOT"] || false
@simulate_oneshot_lines_coverage = ENV["SIMULATE_ONESHOT"] || false
@simulate_oneshot_lines_coverage = false # this is being deprecated
@current_root = nil
@all_root_paths = nil
@all_root_patterns = nil
Expand Down
1 change: 0 additions & 1 deletion test/benchmarks/benchmark.rake
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ namespace :benchmarks do
config.logger = $stdout
config.store = benchmark_redis_store
config.use_oneshot_lines_coverage = true if ENV["ONESHOT"]
config.simulate_oneshot_lines_coverage = true if ENV["SIMULATE_ONESHOT"]
end
end

Expand Down
3 changes: 0 additions & 3 deletions test/coverband/adapters/base_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ def test_array_add
assert_equal [8, 11, nil, nil], Coverband::Adapters::Base.new.send(:array_add, latest, original)
Coverband.configuration.stubs(:use_oneshot_lines_coverage).returns(true)
assert_equal [1, 1, nil, nil], Coverband::Adapters::Base.new.send(:array_add, latest, original)
Coverband.configuration.stubs(:use_oneshot_lines_coverage).returns(false)
Coverband.configuration.stubs(:simulate_oneshot_lines_coverage).returns(true)
assert_equal [1, 1, nil, nil], Coverband::Adapters::Base.new.send(:array_add, latest, original)
end

describe "Coverband::Adapters::Base using file" do
Expand Down
8 changes: 0 additions & 8 deletions test/coverband/adapters/redis_store_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,6 @@ def test_coverage_for_file
assert_equal example_line, @store.coverage["app_path/dog.rb"]["data"]
end

def test_coverage_with_simulate_oneshot_lines_coverage
Coverband.configuration.stubs(:simulate_oneshot_lines_coverage).returns(true)
mock_file_hash
expected = basic_coverage
@store.save_report(expected)
assert_equal example_line, @store.get_coverage_report[:runtime]["app_path/dog.rb"]["data"]
end

def test_coverage_when_null
assert_nil @store.coverage["app_path/dog.rb"]
end
Expand Down
1 change: 0 additions & 1 deletion test/rails5_dummy/config/coverband.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,4 @@
config.background_reporting_enabled = true
config.track_routes = true
config.use_oneshot_lines_coverage = true if ENV["ONESHOT"]
config.simulate_oneshot_lines_coverage = true if ENV["SIMULATE_ONESHOT"]
end
1 change: 0 additions & 1 deletion test/rails5_dummy/config/coverband_missing_redis.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,4 @@
config.track_gems = true
config.gem_details = true
config.use_oneshot_lines_coverage = true if ENV["ONESHOT"]
config.simulate_oneshot_lines_coverage = true if ENV["SIMULATE_ONESHOT"]
end
2 changes: 1 addition & 1 deletion test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
require_relative "unique_files"
$VERBOSE = original_verbosity

unless ENV["ONESHOT"] || ENV["SIMULATE_ONESHOT"] || $SKIP_SIMPLECOV
unless ENV["ONESHOT"] || $SKIP_SIMPLECOV
SimpleCov.formatter = Coveralls::SimpleCov::Formatter
SimpleCov.start do
add_filter "test/forked"
Expand Down

0 comments on commit 3c42c95

Please sign in to comment.