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

Add prioritize_line_class_coverage option #43

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ jacoco.minimum_class_coverage_map = { # optional (default is empty)
jacoco.minimum_class_coverage_percentage = 75 # default 0
jacoco.files_extension = [".java"] # default [".kt", ".java"]
jacoco.report("path/to/jacoco.xml", "http://jacoco-html-reports/")
jacoco.prioritize_line_class_coverage = true # default false
```

to your `Dangerfile`
Expand Down
8 changes: 7 additions & 1 deletion lib/jacoco/plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class DangerJacoco < Plugin # rubocop:disable Metrics/ClassLength
attr_accessor :minimum_package_coverage_map
attr_accessor :minimum_class_coverage_map
attr_accessor :fail_no_coverage_data_found
attr_accessor :prioritize_line_class_coverage

# Initialize the plugin with configured parameters or defaults
def setup
Expand All @@ -34,6 +35,7 @@ def setup
@minimum_package_coverage_map = {} unless minimum_package_coverage_map
@minimum_class_coverage_map = {} unless minimum_class_coverage_map
@files_extension = ['.kt', '.java'] unless files_extension
@prioritize_line_class_coverage = false unless prioritize_line_class_coverage
end

# Parses the xml output of jacoco to Ruby model classes
Expand Down Expand Up @@ -161,7 +163,11 @@ def coverage_counter(jacoco_class)
counters = jacoco_class.counters
branch_counter = counters.detect { |e| e.type.eql? 'BRANCH' }
line_counter = counters.detect { |e| e.type.eql? 'LINE' }
counter = branch_counter.nil? ? line_counter : branch_counter
counter = if @prioritize_line_class_coverage
line_counter
else
branch_counter.nil? ? line_counter : branch_counter
end

if counter.nil?
no_coverage_data_found_message = "No coverage data found for #{jacoco_class.name}"
Expand Down
11 changes: 11 additions & 0 deletions spec/jacoco_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,17 @@ module Danger

expect { @my_plugin.report path_a, fail_no_coverage_data_found: false }.to_not raise_error(RuntimeError)
end

it 'test with prioritize line class coverage' do
path_a = "#{File.dirname(__FILE__)}/fixtures/output_a.xml"

@my_plugin.minimum_class_coverage_map = { 'com/example/CachedRepository' => 80 }
@my_plugin.prioritize_line_class_coverage = true

@my_plugin.report path_a

expect(@dangerfile.status_report[:markdowns][0].message).to include('| `com/example/CachedRepository` | 100% | 80% | :white_check_mark: |')
end
end
end
end
Expand Down