danger-jacoco 0.1.2 → 0.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.github/dependabot.yml +20 -0
- data/.github/workflows/ci.yaml +13 -0
- data/.github/workflows/release.yaml +23 -0
- data/Gemfile +2 -0
- data/Guardfile +2 -0
- data/README.md +8 -1
- data/Rakefile +2 -0
- data/danger-jacoco.gemspec +13 -11
- data/lib/danger_jacoco.rb +2 -0
- data/lib/danger_plugin.rb +2 -0
- data/lib/jacoco/dom_parser.rb +2 -0
- data/lib/jacoco/gem_version.rb +3 -1
- data/lib/jacoco/model/class.rb +2 -0
- data/lib/jacoco/model/counter.rb +2 -0
- data/lib/jacoco/model/group.rb +2 -0
- data/lib/jacoco/model/line.rb +2 -0
- data/lib/jacoco/model/method.rb +2 -0
- data/lib/jacoco/model/package.rb +2 -0
- data/lib/jacoco/model/report.rb +2 -0
- data/lib/jacoco/model/session_info.rb +2 -0
- data/lib/jacoco/model/sourcefile.rb +2 -0
- data/lib/jacoco/plugin.rb +85 -19
- data/lib/jacoco/sax_parser.rb +11 -10
- data/spec/fixtures/output_a.xml +8 -7
- data/spec/fixtures/output_b.xml +34 -0
- data/spec/jacoco_spec.rb +161 -7
- data/spec/spec_helper.rb +7 -3
- metadata +20 -17
- data/.travis.yml +0 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: d4d5975aa9e605034d57f94ae6c1e83b5b9ba5f9b21be614a3266c5b8d70a36d
|
4
|
+
data.tar.gz: 98ee2072a867384ae8d732cfef8dcda6b201a8da7706e2361481fa5add96bda4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 07e545a038ee4ea8c7aa81c77ef96a1b62756513f90cb9994d762b9f5605689e02eb2a4c2d56c7dfb15b1177e9b9e700f51f4dc44162a7663350031b28f84511
|
7
|
+
data.tar.gz: 6138c222b2bcd09bf9c4e1744e256065bf9c1ac5e3d33c1b080252ccd0e7e50dfc2ab4dc92264bb8e32ab4428ab8887f5a7acbad715e9e8cca9cda210ac3b487
|
@@ -0,0 +1,20 @@
|
|
1
|
+
version: 2
|
2
|
+
updates:
|
3
|
+
- package-ecosystem: bundler
|
4
|
+
directory: "/"
|
5
|
+
schedule:
|
6
|
+
interval: weekly
|
7
|
+
time: "19:00"
|
8
|
+
open-pull-requests-limit: 10
|
9
|
+
ignore:
|
10
|
+
- dependency-name: listen
|
11
|
+
versions:
|
12
|
+
- 3.4.1
|
13
|
+
- 3.5.0
|
14
|
+
- dependency-name: rubocop
|
15
|
+
versions:
|
16
|
+
- 1.10.0
|
17
|
+
- 1.11.0
|
18
|
+
- 1.12.0
|
19
|
+
- 1.8.1
|
20
|
+
- 1.9.1
|
@@ -0,0 +1,23 @@
|
|
1
|
+
name: deploy-release
|
2
|
+
on:
|
3
|
+
push:
|
4
|
+
tags: '*'
|
5
|
+
jobs:
|
6
|
+
test:
|
7
|
+
runs-on: ubuntu-latest
|
8
|
+
steps:
|
9
|
+
- uses: actions/checkout@v1
|
10
|
+
- uses: actions/setup-ruby@v1
|
11
|
+
with:
|
12
|
+
ruby-version: '2.6.x'
|
13
|
+
- run: gem install bundler
|
14
|
+
- run: bundle install
|
15
|
+
- run: bundle exec rake spec
|
16
|
+
- name: setup credentials
|
17
|
+
env:
|
18
|
+
RUBYGEMS_API_KEY: ${{ secrets.RUBYGEMS_API_KEY }}
|
19
|
+
run: |
|
20
|
+
mkdir -p ~/.gem
|
21
|
+
echo -e "---\r\n:rubygems_api_key: $RUBYGEMS_API_KEY" > ~/.gem/credentials
|
22
|
+
chmod 0600 ~/.gem/credentials
|
23
|
+
- run: bundle exec rake release
|
data/Gemfile
CHANGED
data/Guardfile
CHANGED
data/README.md
CHANGED
@@ -15,9 +15,16 @@ Add
|
|
15
15
|
|
16
16
|
```ruby
|
17
17
|
jacoco.minimum_project_coverage_percentage = 50 # default 0
|
18
|
+
jacoco.minimum_package_coverage_map = { # optional (default is empty)
|
19
|
+
'com/package/' => 55,
|
20
|
+
'com/package/more/specific/' => 15
|
21
|
+
}
|
22
|
+
jacoco.minimum_class_coverage_map = { # optional (default is empty)
|
23
|
+
'com/package/more/specific/ClassName' => 15
|
24
|
+
}
|
18
25
|
jacoco.minimum_class_coverage_percentage = 75 # default 0
|
19
26
|
jacoco.files_extension = [".java"] # default [".kt", ".java"]
|
20
|
-
jacoco.report
|
27
|
+
jacoco.report("path/to/jacoco.xml", "http://jacoco-html-reports/")
|
21
28
|
```
|
22
29
|
|
23
30
|
to your `Dangerfile`
|
data/Rakefile
CHANGED
data/danger-jacoco.gemspec
CHANGED
@@ -1,43 +1,45 @@
|
|
1
|
-
#
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
3
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require 'jacoco/gem_version
|
5
|
+
require 'jacoco/gem_version'
|
5
6
|
|
6
7
|
Gem::Specification.new do |spec|
|
7
8
|
spec.name = 'danger-jacoco'
|
8
9
|
spec.version = Jacoco::VERSION
|
9
10
|
spec.authors = ['Anton Malinskiy']
|
10
11
|
spec.email = ['anton@malinskiy.com']
|
11
|
-
spec.description =
|
12
|
-
spec.summary =
|
12
|
+
spec.description = 'A short description of danger-jacoco.'
|
13
|
+
spec.summary = 'A longer description of danger-jacoco.'
|
13
14
|
spec.homepage = 'https://github.com/Malinskiy/danger-jacoco'
|
14
15
|
spec.license = 'MIT'
|
15
16
|
|
16
|
-
spec.files = `git ls-files`.split(
|
17
|
+
spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
|
17
18
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
19
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
20
|
spec.require_paths = ['lib']
|
21
|
+
spec.required_ruby_version = '>= 2.6'
|
20
22
|
|
21
23
|
spec.add_runtime_dependency 'danger-plugin-api', '~> 1.0'
|
22
24
|
spec.add_runtime_dependency 'nokogiri-happymapper', '~> 0.6'
|
23
25
|
|
24
26
|
# General ruby development
|
25
|
-
spec.add_development_dependency 'bundler', '~>
|
26
|
-
spec.add_development_dependency 'rake', '~>
|
27
|
+
spec.add_development_dependency 'bundler', '~> 2.0'
|
28
|
+
spec.add_development_dependency 'rake', '~> 13.0'
|
27
29
|
|
28
30
|
# Testing support
|
29
31
|
spec.add_development_dependency 'rspec', '~> 3.7'
|
30
32
|
|
31
33
|
# Linting code and docs
|
32
|
-
spec.add_development_dependency
|
33
|
-
spec.add_development_dependency
|
34
|
+
spec.add_development_dependency 'rubocop', '~> 1.14'
|
35
|
+
spec.add_development_dependency 'yard', '~> 0.9'
|
34
36
|
|
35
37
|
# Makes testing easy via `bundle exec guard`
|
36
38
|
spec.add_development_dependency 'guard', '~> 2.14'
|
37
39
|
spec.add_development_dependency 'guard-rspec', '~> 4.7'
|
38
40
|
|
39
41
|
# If you want to work on older builds of ruby
|
40
|
-
spec.add_development_dependency 'listen', '3.1
|
42
|
+
spec.add_development_dependency 'listen', '3.5.1'
|
41
43
|
|
42
44
|
# This gives you the chance to run a REPL inside your tests
|
43
45
|
# via:
|
data/lib/danger_jacoco.rb
CHANGED
data/lib/danger_plugin.rb
CHANGED
data/lib/jacoco/dom_parser.rb
CHANGED
data/lib/jacoco/gem_version.rb
CHANGED
data/lib/jacoco/model/class.rb
CHANGED
data/lib/jacoco/model/counter.rb
CHANGED
data/lib/jacoco/model/group.rb
CHANGED
data/lib/jacoco/model/line.rb
CHANGED
data/lib/jacoco/model/method.rb
CHANGED
data/lib/jacoco/model/package.rb
CHANGED
data/lib/jacoco/model/report.rb
CHANGED
data/lib/jacoco/plugin.rb
CHANGED
@@ -1,19 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'jacoco/sax_parser'
|
2
4
|
|
3
5
|
module Danger
|
6
|
+
# Verify code coverage inside your projects
|
7
|
+
# This is done using the jacoco output
|
8
|
+
# Results are passed out as a table in markdown
|
9
|
+
#
|
10
|
+
# @example Verify coverage
|
11
|
+
# jacoco.minimum_project_coverage_percentage = 50
|
12
|
+
#
|
13
|
+
# @example Verify coverage per package
|
14
|
+
# jacoco.minimum_package_coverage_map = { # optional (default is empty)
|
15
|
+
# 'com/package/' => 55,
|
16
|
+
# 'com/package/more/specific/' => 15
|
17
|
+
# }
|
4
18
|
#
|
5
19
|
# @see Anton Malinskiy/danger-jacoco
|
6
20
|
# @tags jacoco, coverage, java, android, kotlin
|
7
21
|
#
|
8
|
-
class DangerJacoco < Plugin
|
9
|
-
attr_accessor :minimum_project_coverage_percentage
|
10
|
-
|
11
|
-
attr_accessor :files_extension
|
22
|
+
class DangerJacoco < Plugin # rubocop:disable Metrics/ClassLength
|
23
|
+
attr_accessor :minimum_project_coverage_percentage, :minimum_class_coverage_percentage, :files_extension,
|
24
|
+
:minimum_package_coverage_map, :minimum_class_coverage_map, :fail_no_coverage_data_found, :title
|
12
25
|
|
26
|
+
# Initialize the plugin with configured parameters or defaults
|
13
27
|
def setup
|
14
28
|
@minimum_project_coverage_percentage = 0 unless minimum_project_coverage_percentage
|
15
29
|
@minimum_class_coverage_percentage = 0 unless minimum_class_coverage_percentage
|
30
|
+
@minimum_package_coverage_map = {} unless minimum_package_coverage_map
|
31
|
+
@minimum_class_coverage_map = {} unless minimum_class_coverage_map
|
16
32
|
@files_extension = ['.kt', '.java'] unless files_extension
|
33
|
+
@title = 'JaCoCo' unless title
|
17
34
|
end
|
18
35
|
|
19
36
|
# Parses the xml output of jacoco to Ruby model classes
|
@@ -28,6 +45,7 @@ module Danger
|
|
28
45
|
# This is a fast report based on SAX parser
|
29
46
|
#
|
30
47
|
# @path path to the xml output of jacoco
|
48
|
+
# @report_url URL where html report hosted
|
31
49
|
# @delimiter git.modified_files returns full paths to the
|
32
50
|
# changed files. We need to get the class from this path to check the
|
33
51
|
# Jacoco report,
|
@@ -41,7 +59,9 @@ module Danger
|
|
41
59
|
# Java => blah/blah/java/slashed_package/Source.java
|
42
60
|
# Kotlin => blah/blah/kotlin/slashed_package/Source.kt
|
43
61
|
#
|
44
|
-
def report(path, delimiter = %r{
|
62
|
+
def report(path, report_url = '', delimiter = %r{/java/|/kotlin/}, fail_no_coverage_data_found: true)
|
63
|
+
@fail_no_coverage_data_found = fail_no_coverage_data_found
|
64
|
+
|
45
65
|
setup
|
46
66
|
classes = classes(delimiter)
|
47
67
|
|
@@ -50,10 +70,10 @@ module Danger
|
|
50
70
|
|
51
71
|
total_covered = total_coverage(path)
|
52
72
|
|
53
|
-
report_markdown = "###
|
54
|
-
report_markdown
|
55
|
-
report_markdown
|
56
|
-
class_coverage_above_minimum = markdown_class(parser, report_markdown)
|
73
|
+
report_markdown = "### #{title} Code Coverage #{total_covered[:covered]}% #{total_covered[:status]}\n"
|
74
|
+
report_markdown += "| Class | Covered | Meta | Status |\n"
|
75
|
+
report_markdown += "|:---|:---:|:---:|:---:|\n"
|
76
|
+
class_coverage_above_minimum = markdown_class(parser, report_markdown, report_url)
|
57
77
|
markdown(report_markdown)
|
58
78
|
|
59
79
|
report_fails(class_coverage_above_minimum, total_covered)
|
@@ -69,14 +89,42 @@ module Danger
|
|
69
89
|
|
70
90
|
# It returns a specific class code coverage and an emoji status as well
|
71
91
|
def report_class(jacoco_class)
|
92
|
+
report_result = {
|
93
|
+
covered: 'No coverage data found : -',
|
94
|
+
status: ':black_joker:',
|
95
|
+
required_coverage_percentage: 'No coverage data found : -'
|
96
|
+
}
|
97
|
+
|
72
98
|
counter = coverage_counter(jacoco_class)
|
73
|
-
|
74
|
-
|
99
|
+
unless counter.nil?
|
100
|
+
coverage = (counter.covered.fdiv(counter.covered + counter.missed) * 100).floor
|
101
|
+
required_coverage = minimum_class_coverage_map[jacoco_class.name]
|
102
|
+
required_coverage = package_coverage(jacoco_class.name) if required_coverage.nil?
|
103
|
+
required_coverage = minimum_class_coverage_percentage if required_coverage.nil?
|
104
|
+
status = coverage_status(coverage, required_coverage)
|
105
|
+
|
106
|
+
report_result = {
|
107
|
+
covered: coverage,
|
108
|
+
status: status,
|
109
|
+
required_coverage_percentage: required_coverage
|
110
|
+
}
|
111
|
+
end
|
75
112
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
113
|
+
report_result
|
114
|
+
end
|
115
|
+
|
116
|
+
# it returns the most suitable coverage by package name to class or nil
|
117
|
+
def package_coverage(class_name)
|
118
|
+
path = class_name
|
119
|
+
package_parts = class_name.split('/')
|
120
|
+
package_parts.reverse_each do |item|
|
121
|
+
size = item.size
|
122
|
+
path = path[0...-size]
|
123
|
+
coverage = minimum_package_coverage_map[path]
|
124
|
+
path = path[0...-1] unless path.empty?
|
125
|
+
return coverage unless coverage.nil?
|
126
|
+
end
|
127
|
+
nil
|
80
128
|
end
|
81
129
|
|
82
130
|
# it returns an emoji for coverage status
|
@@ -111,7 +159,14 @@ module Danger
|
|
111
159
|
branch_counter = counters.detect { |e| e.type.eql? 'BRANCH' }
|
112
160
|
line_counter = counters.detect { |e| e.type.eql? 'LINE' }
|
113
161
|
counter = branch_counter.nil? ? line_counter : branch_counter
|
114
|
-
|
162
|
+
|
163
|
+
if counter.nil?
|
164
|
+
no_coverage_data_found_message = "No coverage data found for #{jacoco_class.name}"
|
165
|
+
|
166
|
+
raise no_coverage_data_found_message if @fail_no_coverage_data_found.instance_of?(TrueClass)
|
167
|
+
|
168
|
+
warn no_coverage_data_found_message
|
169
|
+
end
|
115
170
|
|
116
171
|
counter
|
117
172
|
end
|
@@ -128,18 +183,29 @@ module Danger
|
|
128
183
|
|
129
184
|
fail("Class coverage is below minimum. Improve to at least #{minimum_class_coverage_percentage}%")
|
130
185
|
end
|
186
|
+
# rubocop:enable Style/SignalException
|
131
187
|
|
132
|
-
def markdown_class(parser, report_markdown)
|
188
|
+
def markdown_class(parser, report_markdown, report_url)
|
133
189
|
class_coverage_above_minimum = true
|
134
190
|
parser.classes.each do |jacoco_class| # Check metrics for each classes
|
135
191
|
rp = report_class(jacoco_class)
|
136
|
-
|
192
|
+
rl = report_link(jacoco_class.name, report_url)
|
193
|
+
ln = "| #{rl} | #{rp[:covered]}% | #{rp[:required_coverage_percentage]}% | #{rp[:status]} |\n"
|
137
194
|
report_markdown << ln
|
138
195
|
|
139
|
-
class_coverage_above_minimum &&= rp[:covered] >=
|
196
|
+
class_coverage_above_minimum &&= rp[:covered] >= rp[:required_coverage_percentage]
|
140
197
|
end
|
141
198
|
|
142
199
|
class_coverage_above_minimum
|
143
200
|
end
|
201
|
+
|
202
|
+
def report_link(class_name, report_url)
|
203
|
+
if report_url.empty?
|
204
|
+
"`#{class_name}`"
|
205
|
+
else
|
206
|
+
report_filepath = "#{class_name.gsub(%r{/(?=[^/]*/.)}, '.')}.html"
|
207
|
+
"[`#{class_name}`](#{report_url + report_filepath})"
|
208
|
+
end
|
209
|
+
end
|
144
210
|
end
|
145
211
|
end
|
data/lib/jacoco/sax_parser.rb
CHANGED
@@ -1,12 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'nokogiri'
|
2
4
|
|
3
5
|
module Jacoco
|
4
6
|
# Sax parser for quickly finding class elements in Jacoco report
|
5
7
|
class SAXParser < Nokogiri::XML::SAX::Document
|
6
|
-
attr_accessor :class_names
|
7
|
-
attr_accessor :classes
|
8
|
+
attr_accessor :class_names, :classes
|
8
9
|
|
9
10
|
def initialize(classes)
|
11
|
+
super()
|
10
12
|
@class_names = classes
|
11
13
|
@classes = []
|
12
14
|
@current_class = nil
|
@@ -38,14 +40,13 @@ module Jacoco
|
|
38
40
|
def start_class(attrs)
|
39
41
|
@subelement_index = 0
|
40
42
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
end
|
43
|
+
return unless @class_names.include?(Hash[attrs]['name'])
|
44
|
+
|
45
|
+
c = Jacoco::Class.new
|
46
|
+
c.name = Hash[attrs]['name']
|
47
|
+
c.counters = []
|
48
|
+
@current_class = c
|
49
|
+
@classes.push c
|
49
50
|
end
|
50
51
|
|
51
52
|
def characters(string); end
|
data/spec/fixtures/output_a.xml
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
<report name="test_report">
|
4
4
|
<sessioninfo id="test-id" start="1480057517395" dump="1480057526412"/>
|
5
5
|
<package name="com/example">
|
6
|
-
<class name="com/example/
|
6
|
+
<class name="com/example/CachedRepository">
|
7
7
|
<method name="<init>" desc="()V" line="17">
|
8
8
|
<counter type="INSTRUCTION" missed="0" covered="11"/>
|
9
9
|
<counter type="LINE" missed="0" covered="5"/>
|
@@ -12,18 +12,19 @@
|
|
12
12
|
</method>
|
13
13
|
<counter type="INSTRUCTION" missed="0" covered="46"/>
|
14
14
|
<counter type="LINE" missed="0" covered="14"/>
|
15
|
-
<counter type="COMPLEXITY" missed="
|
15
|
+
<counter type="COMPLEXITY" missed="5" covered="7"/>
|
16
16
|
<counter type="METHOD" missed="0" covered="7"/>
|
17
17
|
<counter type="CLASS" missed="0" covered="1"/>
|
18
|
+
<counter type="BRANCH" missed="2" covered="2" />
|
18
19
|
</class>
|
19
20
|
<sourcefile name="CachedRepository.java">
|
20
21
|
<line nr="16" mi="0" ci="2" mb="0" cb="0"/>
|
21
22
|
<line nr="17" mi="0" ci="3" mb="0" cb="0"/>
|
22
|
-
<counter type="INSTRUCTION" missed="
|
23
|
-
<counter type="LINE" missed="
|
24
|
-
<counter type="COMPLEXITY" missed="
|
25
|
-
<counter type="METHOD" missed="
|
26
|
-
<counter type="CLASS" missed="
|
23
|
+
<counter type="INSTRUCTION" missed="2" covered="98"/>
|
24
|
+
<counter type="LINE" missed="2" covered="19"/>
|
25
|
+
<counter type="COMPLEXITY" missed="2" covered="11"/>
|
26
|
+
<counter type="METHOD" missed="2" covered="11"/>
|
27
|
+
<counter type="CLASS" missed="2" covered="4"/>
|
27
28
|
</sourcefile>
|
28
29
|
<counter type="INSTRUCTION" missed="80" covered="324"/>
|
29
30
|
<counter type="BRANCH" missed="4" covered="4"/>
|
@@ -0,0 +1,34 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><!DOCTYPE report PUBLIC "-//JACOCO//DTD Report 1.0//EN"
|
2
|
+
"report.dtd">
|
3
|
+
<report name="test_report">
|
4
|
+
<sessioninfo id="test-id" start="1480057517395" dump="1480057526412"/>
|
5
|
+
<package name="com/example">
|
6
|
+
<class name="com/example/CachedRepository">
|
7
|
+
<method name="<init>" desc="()V" line="17">
|
8
|
+
<counter type="INSTRUCTION" missed="0" covered="11"/>
|
9
|
+
<counter type="COMPLEXITY" missed="0" covered="1"/>
|
10
|
+
<counter type="METHOD" missed="0" covered="1"/>
|
11
|
+
</method>
|
12
|
+
<counter type="INSTRUCTION" missed="0" covered="46"/>
|
13
|
+
<counter type="COMPLEXITY" missed="5" covered="7"/>
|
14
|
+
<counter type="METHOD" missed="0" covered="7"/>
|
15
|
+
<counter type="CLASS" missed="0" covered="1"/>
|
16
|
+
</class>
|
17
|
+
<sourcefile name="CachedRepository.java">
|
18
|
+
<line nr="16" mi="0" ci="2" mb="0" cb="0"/>
|
19
|
+
<line nr="17" mi="0" ci="3" mb="0" cb="0"/>
|
20
|
+
<counter type="INSTRUCTION" missed="2" covered="98"/>
|
21
|
+
<counter type="COMPLEXITY" missed="2" covered="11"/>
|
22
|
+
<counter type="METHOD" missed="2" covered="11"/>
|
23
|
+
<counter type="CLASS" missed="2" covered="4"/>
|
24
|
+
</sourcefile>
|
25
|
+
<counter type="INSTRUCTION" missed="80" covered="324"/>
|
26
|
+
<counter type="COMPLEXITY" missed="11" covered="39"/>
|
27
|
+
<counter type="METHOD" missed="9" covered="37"/>
|
28
|
+
<counter type="CLASS" missed="2" covered="10"/>
|
29
|
+
</package>
|
30
|
+
<counter type="INSTRUCTION" missed="39399" covered="19321"/>
|
31
|
+
<counter type="COMPLEXITY" missed="5517" covered="1444"/>
|
32
|
+
<counter type="METHOD" missed="3382" covered="1120"/>
|
33
|
+
<counter type="CLASS" missed="491" covered="370"/>
|
34
|
+
</report>
|
data/spec/jacoco_spec.rb
CHANGED
@@ -1,13 +1,167 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
# rubocop:disable Layout/LineLength
|
4
|
+
# rubocop:disable Metrics/ModuleLength
|
5
|
+
# rubocop:disable Metrics/BlockLength
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
require File.expand_path('spec_helper', __dir__)
|
8
|
+
|
9
|
+
module Danger
|
10
|
+
describe Danger::DangerJacoco do
|
11
|
+
it 'should be a plugin' do
|
12
|
+
expect(Danger::DangerJacoco.new(nil)).to be_a Danger::Plugin
|
13
|
+
end
|
14
|
+
|
15
|
+
#
|
16
|
+
# You should test your custom attributes and methods here
|
17
|
+
#
|
18
|
+
describe 'with Dangerfile' do
|
19
|
+
before do
|
20
|
+
@dangerfile = testing_dangerfile
|
21
|
+
@my_plugin = @dangerfile.jacoco
|
22
|
+
|
23
|
+
modified_files = ['src/java/com/example/CachedRepository.java']
|
24
|
+
added_files = ['src/java/Blah.java']
|
25
|
+
|
26
|
+
allow(@dangerfile.git).to receive(:modified_files).and_return(modified_files)
|
27
|
+
allow(@dangerfile.git).to receive(:added_files).and_return(added_files)
|
28
|
+
end
|
29
|
+
|
30
|
+
it :report do
|
31
|
+
path_a = "#{File.dirname(__FILE__)}/fixtures/output_a.xml"
|
32
|
+
|
33
|
+
@my_plugin.minimum_project_coverage_percentage = 50
|
34
|
+
@my_plugin.minimum_class_coverage_map = { 'com/example/CachedRepository' => 100 }
|
35
|
+
|
36
|
+
@my_plugin.report path_a
|
37
|
+
|
38
|
+
expect(@dangerfile.status_report[:errors]).to eq(['Total coverage of 32.9%. Improve this to at least 50%',
|
39
|
+
'Class coverage is below minimum. Improve to at least 0%'])
|
40
|
+
expect(@dangerfile.status_report[:markdowns][0].message).to include('### JaCoCo Code Coverage 32.9% :warning:')
|
41
|
+
expect(@dangerfile.status_report[:markdowns][0].message).to include('| Class | Covered | Meta | Status |')
|
42
|
+
expect(@dangerfile.status_report[:markdowns][0].message).to include('|:---|:---:|:---:|:---:|')
|
43
|
+
expect(@dangerfile.status_report[:markdowns][0].message).to include('| `com/example/CachedRepository` | 50% | 100% | :warning: |')
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'test with package coverage' do
|
47
|
+
path_a = "#{File.dirname(__FILE__)}/fixtures/output_a.xml"
|
48
|
+
|
49
|
+
@my_plugin.minimum_project_coverage_percentage = 50
|
50
|
+
@my_plugin.minimum_package_coverage_map = { 'com/example/' => 70 }
|
51
|
+
|
52
|
+
@my_plugin.report path_a
|
53
|
+
|
54
|
+
expect(@dangerfile.status_report[:markdowns][0].message).to include('| `com/example/CachedRepository` | 50% | 70% | :warning: |')
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'test with bigger overlapped package coverage' do
|
58
|
+
path_a = "#{File.dirname(__FILE__)}/fixtures/output_a.xml"
|
59
|
+
|
60
|
+
@my_plugin.minimum_project_coverage_percentage = 50
|
61
|
+
@my_plugin.minimum_package_coverage_map = {
|
62
|
+
'com/example/' => 70,
|
63
|
+
'com/' => 90
|
64
|
+
}
|
65
|
+
|
66
|
+
@my_plugin.report path_a
|
67
|
+
|
68
|
+
expect(@dangerfile.status_report[:markdowns][0].message).to include('| `com/example/CachedRepository` | 50% | 70% | :warning: |')
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'test with lower overlapped package coverage' do
|
72
|
+
path_a = "#{File.dirname(__FILE__)}/fixtures/output_a.xml"
|
73
|
+
|
74
|
+
@my_plugin.minimum_project_coverage_percentage = 50
|
75
|
+
@my_plugin.minimum_package_coverage_map = {
|
76
|
+
'com/example/' => 77,
|
77
|
+
'com/' => 30
|
78
|
+
}
|
79
|
+
|
80
|
+
@my_plugin.report path_a
|
81
|
+
|
82
|
+
expect(@dangerfile.status_report[:markdowns][0].message).to include('| `com/example/CachedRepository` | 50% | 77% | :warning: |')
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'test with overlapped package coverage and bigger class coverage' do
|
86
|
+
path_a = "#{File.dirname(__FILE__)}/fixtures/output_a.xml"
|
87
|
+
|
88
|
+
@my_plugin.minimum_project_coverage_percentage = 50
|
89
|
+
@my_plugin.minimum_package_coverage_map = {
|
90
|
+
'com/example/' => 77,
|
91
|
+
'com/' => 30
|
92
|
+
}
|
93
|
+
@my_plugin.minimum_class_coverage_map = { 'com/example/CachedRepository' => 100 }
|
94
|
+
|
95
|
+
@my_plugin.report path_a
|
96
|
+
|
97
|
+
expect(@dangerfile.status_report[:markdowns][0].message).to include('| `com/example/CachedRepository` | 50% | 100% | :warning: |')
|
98
|
+
end
|
99
|
+
|
100
|
+
it 'test with overlapped package coverage and lowwer class coverage' do
|
101
|
+
path_a = "#{File.dirname(__FILE__)}/fixtures/output_a.xml"
|
102
|
+
|
103
|
+
@my_plugin.minimum_project_coverage_percentage = 50
|
104
|
+
@my_plugin.minimum_package_coverage_map = {
|
105
|
+
'com/example/' => 90,
|
106
|
+
'com/' => 85
|
107
|
+
}
|
108
|
+
@my_plugin.minimum_class_coverage_map = { 'com/example/CachedRepository' => 80 }
|
109
|
+
|
110
|
+
@my_plugin.report path_a
|
111
|
+
|
112
|
+
expect(@dangerfile.status_report[:markdowns][0].message).to include('| `com/example/CachedRepository` | 50% | 80% | :warning: |')
|
113
|
+
end
|
114
|
+
|
115
|
+
it 'adds a link to report' do
|
116
|
+
path_a = "#{File.dirname(__FILE__)}/fixtures/output_a.xml"
|
117
|
+
|
118
|
+
@my_plugin.minimum_class_coverage_percentage = 80
|
119
|
+
@my_plugin.minimum_project_coverage_percentage = 50
|
120
|
+
|
121
|
+
@my_plugin.report(path_a, 'http://test.com/')
|
122
|
+
|
123
|
+
expect(@dangerfile.status_report[:markdowns][0].message).to include('| [`com/example/CachedRepository`](http://test.com/com.example/CachedRepository.html) | 50% | 80% | :warning: |')
|
124
|
+
end
|
125
|
+
|
126
|
+
it 'When option "fail_no_coverage_data_found" is set to optionally fail, it doesn\'t fail the execution' do
|
127
|
+
path_a = "#{File.dirname(__FILE__)}/fixtures/output_a.xml"
|
128
|
+
|
129
|
+
@my_plugin.minimum_class_coverage_percentage = 80
|
130
|
+
@my_plugin.minimum_project_coverage_percentage = 50
|
131
|
+
|
132
|
+
expect { @my_plugin.report(path_a, fail_no_coverage_data_found: true) }.to_not raise_error(RuntimeError)
|
133
|
+
end
|
134
|
+
|
135
|
+
it 'When option "fail_no_coverage_data_found" is not set, the execution fails on empty data' do
|
136
|
+
path_a = "#{File.dirname(__FILE__)}/fixtures/output_b.xml"
|
137
|
+
|
138
|
+
@my_plugin.minimum_class_coverage_percentage = 80
|
139
|
+
@my_plugin.minimum_project_coverage_percentage = 50
|
140
|
+
|
141
|
+
expect { @my_plugin.report path_a }.to raise_error(RuntimeError)
|
142
|
+
end
|
143
|
+
|
144
|
+
it 'When option "fail_no_coverage_data_found" is set to optionally fail, the execution fails on empty data' do
|
145
|
+
path_a = "#{File.dirname(__FILE__)}/fixtures/output_b.xml"
|
146
|
+
|
147
|
+
@my_plugin.minimum_class_coverage_percentage = 80
|
148
|
+
@my_plugin.minimum_project_coverage_percentage = 50
|
149
|
+
|
150
|
+
expect { @my_plugin.report path_a, fail_no_coverage_data_found: true }.to raise_error(RuntimeError)
|
151
|
+
end
|
152
|
+
|
153
|
+
it 'When option "fail_no_coverage_data_found" is set to optionally warn (not fail), the execution doesn\'t fail on empty data' do
|
154
|
+
path_a = "#{File.dirname(__FILE__)}/fixtures/output_b.xml"
|
155
|
+
|
156
|
+
@my_plugin.minimum_class_coverage_percentage = 80
|
157
|
+
@my_plugin.minimum_project_coverage_percentage = 50
|
158
|
+
|
159
|
+
expect { @my_plugin.report path_a, fail_no_coverage_data_found: false }.to_not raise_error(RuntimeError)
|
10
160
|
end
|
11
161
|
end
|
12
162
|
end
|
13
163
|
end
|
164
|
+
|
165
|
+
# rubocop:enable Layout/LineLength
|
166
|
+
# rubocop:enable Metrics/ModuleLength
|
167
|
+
# rubocop:enable Metrics/BlockLength
|
data/spec/spec_helper.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'pathname'
|
2
|
-
ROOT = Pathname.new(File.expand_path('
|
3
|
-
$LOAD_PATH.unshift(
|
4
|
-
$LOAD_PATH.unshift(
|
4
|
+
ROOT = Pathname.new(File.expand_path('..', __dir__))
|
5
|
+
$LOAD_PATH.unshift("#{ROOT}lib".to_s)
|
6
|
+
$LOAD_PATH.unshift("#{ROOT}spec".to_s)
|
5
7
|
|
6
8
|
require 'bundler/setup'
|
7
9
|
require 'pry'
|
@@ -16,6 +18,8 @@ RSpec.configure do |config|
|
|
16
18
|
config.tty = true
|
17
19
|
end
|
18
20
|
|
21
|
+
RSpec::Expectations.configuration.on_potential_false_positives = :nothing
|
22
|
+
|
19
23
|
require 'danger_plugin'
|
20
24
|
|
21
25
|
# These functions are a subset of https://github.com/danger/danger/blob/master/spec/spec_helper.rb
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: danger-jacoco
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Anton Malinskiy
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-05-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: danger-plugin-api
|
@@ -44,28 +44,28 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '2.0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '2.0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rake
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
61
|
+
version: '13.0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
68
|
+
version: '13.0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rspec
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -86,14 +86,14 @@ dependencies:
|
|
86
86
|
requirements:
|
87
87
|
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: '
|
89
|
+
version: '1.14'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: '
|
96
|
+
version: '1.14'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: yard
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -142,14 +142,14 @@ dependencies:
|
|
142
142
|
requirements:
|
143
143
|
- - '='
|
144
144
|
- !ruby/object:Gem::Version
|
145
|
-
version: 3.1
|
145
|
+
version: 3.5.1
|
146
146
|
type: :development
|
147
147
|
prerelease: false
|
148
148
|
version_requirements: !ruby/object:Gem::Requirement
|
149
149
|
requirements:
|
150
150
|
- - '='
|
151
151
|
- !ruby/object:Gem::Version
|
152
|
-
version: 3.1
|
152
|
+
version: 3.5.1
|
153
153
|
- !ruby/object:Gem::Dependency
|
154
154
|
name: pry
|
155
155
|
requirement: !ruby/object:Gem::Requirement
|
@@ -171,9 +171,11 @@ executables: []
|
|
171
171
|
extensions: []
|
172
172
|
extra_rdoc_files: []
|
173
173
|
files:
|
174
|
+
- ".github/dependabot.yml"
|
175
|
+
- ".github/workflows/ci.yaml"
|
176
|
+
- ".github/workflows/release.yaml"
|
174
177
|
- ".gitignore"
|
175
178
|
- ".rubocop.yml"
|
176
|
-
- ".travis.yml"
|
177
179
|
- Gemfile
|
178
180
|
- Guardfile
|
179
181
|
- LICENSE.txt
|
@@ -196,13 +198,14 @@ files:
|
|
196
198
|
- lib/jacoco/plugin.rb
|
197
199
|
- lib/jacoco/sax_parser.rb
|
198
200
|
- spec/fixtures/output_a.xml
|
201
|
+
- spec/fixtures/output_b.xml
|
199
202
|
- spec/jacoco_spec.rb
|
200
203
|
- spec/spec_helper.rb
|
201
204
|
homepage: https://github.com/Malinskiy/danger-jacoco
|
202
205
|
licenses:
|
203
206
|
- MIT
|
204
207
|
metadata: {}
|
205
|
-
post_install_message:
|
208
|
+
post_install_message:
|
206
209
|
rdoc_options: []
|
207
210
|
require_paths:
|
208
211
|
- lib
|
@@ -210,19 +213,19 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
210
213
|
requirements:
|
211
214
|
- - ">="
|
212
215
|
- !ruby/object:Gem::Version
|
213
|
-
version: '
|
216
|
+
version: '2.6'
|
214
217
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
215
218
|
requirements:
|
216
219
|
- - ">="
|
217
220
|
- !ruby/object:Gem::Version
|
218
221
|
version: '0'
|
219
222
|
requirements: []
|
220
|
-
|
221
|
-
|
222
|
-
signing_key:
|
223
|
+
rubygems_version: 3.0.9
|
224
|
+
signing_key:
|
223
225
|
specification_version: 4
|
224
226
|
summary: A longer description of danger-jacoco.
|
225
227
|
test_files:
|
226
228
|
- spec/fixtures/output_a.xml
|
229
|
+
- spec/fixtures/output_b.xml
|
227
230
|
- spec/jacoco_spec.rb
|
228
231
|
- spec/spec_helper.rb
|