danger-jacoco-instacart 0.1.10 → 0.1.12.SNAPSHOT.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.yardoc/checksums +2 -2
- data/.yardoc/object_types +0 -0
- data/.yardoc/objects/root.dat +0 -0
- data/lib/jacoco/gem_version.rb +1 -1
- data/lib/jacoco/plugin.rb +53 -16
- data/spec/fixtures/output_a.xml +1 -1
- data/spec/fixtures/output_b.xml +0 -2
- data/spec/fixtures/output_c.xml +2 -2
- data/spec/fixtures/output_d.xml +35 -0
- data/spec/fixtures/output_e.xml +34 -0
- data/spec/fixtures/output_f.xml +33 -0
- data/spec/jacoco_spec.rb +97 -0
- metadata +10 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4ff75e66844360f83e9ccff23b81dd5af28d2d373f212caa3275501b4164ea9d
|
4
|
+
data.tar.gz: e93ad8c6350b8935f7ead4660945a58530d893ee44ade1e13b681d0dc3a07c0c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 92409828a407f2d31d6990af3fe3a6cb35e95824800b972e71c6ea6ed9e70679206058791fa9754a1ca342ebed7ee68514bfd258f27013d3b219e1c1245f7906
|
7
|
+
data.tar.gz: 69a151c0b3491bcff7546769c9055b0e52a3caa187be0196682b665bfb6a94c33f0fe05165a057f066da22a551801529a488e839bcfb559d461d0e3c0d07e4cf
|
data/.yardoc/checksums
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
/Users/alexanderbezverhni/workspace/junk/danger-jacoco/lib/danger_jacoco.rb 38229d934b3315bb2a5a4eec18eb65f3c54d304f
|
2
|
-
/Users/alexanderbezverhni/workspace/junk/danger-jacoco/lib/jacoco/gem_version.rb
|
3
|
-
/Users/alexanderbezverhni/workspace/junk/danger-jacoco/lib/jacoco/plugin.rb
|
2
|
+
/Users/alexanderbezverhni/workspace/junk/danger-jacoco/lib/jacoco/gem_version.rb 1c81f68cb95296bfd592c1b57e0f2e6341f56b55
|
3
|
+
/Users/alexanderbezverhni/workspace/junk/danger-jacoco/lib/jacoco/plugin.rb e99030c6a408c1bc77962b844d74c324daecad40
|
4
4
|
/Users/alexanderbezverhni/workspace/junk/danger-jacoco/lib/jacoco/sax_parser.rb 370e2799f8dbdf7d642c820214e6ea84c30c9cb0
|
5
5
|
/Users/alexanderbezverhni/workspace/junk/danger-jacoco/lib/jacoco/model/counter.rb 368f4a9811617b7a174ddf837a8fac49a4bc32a6
|
6
6
|
/Users/alexanderbezverhni/workspace/junk/danger-jacoco/lib/jacoco/model/report.rb 7cf45ee71ff347a130320f6190ddb25525c7095d
|
data/.yardoc/object_types
CHANGED
Binary file
|
data/.yardoc/objects/root.dat
CHANGED
Binary file
|
data/lib/jacoco/gem_version.rb
CHANGED
data/lib/jacoco/plugin.rb
CHANGED
@@ -20,9 +20,10 @@ module Danger
|
|
20
20
|
# @tags jacoco, coverage, java, android, kotlin
|
21
21
|
#
|
22
22
|
class DangerJacoco < Plugin # rubocop:disable Metrics/ClassLength
|
23
|
-
attr_accessor :minimum_project_coverage_percentage, :minimum_class_coverage_percentage,
|
24
|
-
:
|
25
|
-
:
|
23
|
+
attr_accessor :minimum_project_coverage_percentage, :minimum_class_coverage_percentage,
|
24
|
+
:minimum_composable_class_coverage_percentage, :only_check_new_files, :files_extension,
|
25
|
+
:minimum_package_coverage_map, :minimum_class_coverage_map, :fail_no_coverage_data_found,
|
26
|
+
:title, :class_column_title, :subtitle_success, :subtitle_failure, :file_to_create_on_failure
|
26
27
|
|
27
28
|
# Initialize the plugin with configured parameters or defaults
|
28
29
|
def setup
|
@@ -30,6 +31,7 @@ module Danger
|
|
30
31
|
setup_texts
|
31
32
|
@only_check_new_files = false unless only_check_new_files
|
32
33
|
@files_extension = ['.kt', '.java'] unless files_extension
|
34
|
+
@file_to_create_on_failure = 'danger_jacoco_failure_status_file.txt' unless file_to_create_on_failure
|
33
35
|
end
|
34
36
|
|
35
37
|
# Initialize the plugin with configured optional texts
|
@@ -44,6 +46,7 @@ module Danger
|
|
44
46
|
def setup_minimum_coverages
|
45
47
|
@minimum_project_coverage_percentage = 0 unless minimum_project_coverage_percentage
|
46
48
|
@minimum_class_coverage_percentage = 0 unless minimum_class_coverage_percentage
|
49
|
+
@minimum_composable_class_coverage_percentage = 0 unless minimum_composable_class_coverage_percentage
|
47
50
|
@minimum_package_coverage_map = {} unless minimum_package_coverage_map
|
48
51
|
@minimum_class_coverage_map = {} unless minimum_class_coverage_map
|
49
52
|
end
|
@@ -79,9 +82,10 @@ module Danger
|
|
79
82
|
@fail_no_coverage_data_found = fail_no_coverage_data_found
|
80
83
|
|
81
84
|
setup
|
82
|
-
|
85
|
+
class_to_file_path_hash = classes(delimiter)
|
86
|
+
classnames = class_to_file_path_hash.keys
|
83
87
|
|
84
|
-
parser = Jacoco::SAXParser.new(
|
88
|
+
parser = Jacoco::SAXParser.new(classnames)
|
85
89
|
Nokogiri::XML::SAX::Parser.new(parser).parse(File.open(path))
|
86
90
|
|
87
91
|
total_covered = total_coverage(path)
|
@@ -90,7 +94,7 @@ module Danger
|
|
90
94
|
report_markdown = header
|
91
95
|
report_markdown += "| #{class_column_title} | Covered | Required | Status |\n"
|
92
96
|
report_markdown += "|:---|:---:|:---:|:---:|\n"
|
93
|
-
class_coverage_above_minimum = markdown_class(parser, report_markdown, report_url)
|
97
|
+
class_coverage_above_minimum = markdown_class(parser, report_markdown, report_url, class_to_file_path_hash)
|
94
98
|
subtitle = class_coverage_above_minimum ? subtitle_success : subtitle_failure
|
95
99
|
report_markdown.insert(header.length, "#### #{subtitle}\n")
|
96
100
|
markdown(report_markdown)
|
@@ -104,12 +108,17 @@ module Danger
|
|
104
108
|
def classes(delimiter)
|
105
109
|
git = @dangerfile.git
|
106
110
|
affected_files = only_check_new_files ? git.added_files : git.added_files + git.modified_files
|
111
|
+
class_to_file_path_hash = {}
|
107
112
|
affected_files.select { |file| files_extension.reduce(false) { |state, el| state || file.end_with?(el) } }
|
108
|
-
.
|
113
|
+
.each do |file| # "src/java/com/example/CachedRepository.java"
|
114
|
+
classname = file.split('.').first.split(delimiter)[1] # "com/example/CachedRepository"
|
115
|
+
class_to_file_path_hash[classname] = file
|
116
|
+
end
|
117
|
+
class_to_file_path_hash
|
109
118
|
end
|
110
119
|
|
111
120
|
# It returns a specific class code coverage and an emoji status as well
|
112
|
-
def report_class(jacoco_class)
|
121
|
+
def report_class(jacoco_class, file_path)
|
113
122
|
report_result = {
|
114
123
|
covered: 'No coverage data found : -',
|
115
124
|
status: ':black_joker:',
|
@@ -119,7 +128,7 @@ module Danger
|
|
119
128
|
counter = coverage_counter(jacoco_class)
|
120
129
|
unless counter.nil?
|
121
130
|
coverage = (counter.covered.fdiv(counter.covered + counter.missed) * 100).floor
|
122
|
-
required_coverage = required_class_coverage(jacoco_class)
|
131
|
+
required_coverage = required_class_coverage(jacoco_class, file_path)
|
123
132
|
status = coverage_status(coverage, required_coverage)
|
124
133
|
|
125
134
|
report_result = {
|
@@ -133,13 +142,19 @@ module Danger
|
|
133
142
|
end
|
134
143
|
|
135
144
|
# Determines the required coverage for the class
|
136
|
-
|
145
|
+
# rubocop:disable Metrics/AbcSize
|
146
|
+
# rubocop:disable Metrics/CyclomaticComplexity
|
147
|
+
def required_class_coverage(jacoco_class, file_path)
|
137
148
|
key = minimum_class_coverage_map.keys.detect { |k| jacoco_class.name.match(k) } || jacoco_class.name
|
138
149
|
required_coverage = minimum_class_coverage_map[key]
|
150
|
+
includes_composables = File.read(file_path).include? '@Composable' if File.exist?(file_path)
|
151
|
+
required_coverage = minimum_composable_class_coverage_percentage if required_coverage.nil? && includes_composables
|
139
152
|
required_coverage = package_coverage(jacoco_class.name) if required_coverage.nil?
|
140
153
|
required_coverage = minimum_class_coverage_percentage if required_coverage.nil?
|
141
154
|
required_coverage
|
142
155
|
end
|
156
|
+
# rubocop:enable Metrics/AbcSize
|
157
|
+
# rubocop:enable Metrics/CyclomaticComplexity
|
143
158
|
|
144
159
|
# it returns the most suitable coverage by package name to class or nil
|
145
160
|
def package_coverage(class_name)
|
@@ -184,10 +199,8 @@ module Danger
|
|
184
199
|
private
|
185
200
|
|
186
201
|
def coverage_counter(jacoco_class)
|
187
|
-
|
188
|
-
|
189
|
-
line_counter = counters.detect { |e| e.type.eql? 'LINE' }
|
190
|
-
counter = branch_counter.nil? ? line_counter : branch_counter
|
202
|
+
all_class_counters = jacoco_class.counters
|
203
|
+
counter = class_counter(all_class_counters)
|
191
204
|
|
192
205
|
if counter.nil?
|
193
206
|
no_coverage_data_found_message = "No coverage data found for #{jacoco_class.name}"
|
@@ -200,24 +213,48 @@ module Danger
|
|
200
213
|
counter
|
201
214
|
end
|
202
215
|
|
216
|
+
def class_counter(all_class_counters)
|
217
|
+
instruction_counter = all_class_counters.detect { |e| e.type.eql? 'INSTRUCTION' }
|
218
|
+
branch_counter = all_class_counters.detect { |e| e.type.eql? 'BRANCH' }
|
219
|
+
line_counter = all_class_counters.detect { |e| e.type.eql? 'LINE' }
|
220
|
+
if !instruction_counter.nil?
|
221
|
+
instruction_counter
|
222
|
+
elsif !branch_counter.nil?
|
223
|
+
branch_counter
|
224
|
+
else
|
225
|
+
line_counter
|
226
|
+
end
|
227
|
+
end
|
228
|
+
|
203
229
|
# rubocop:disable Style/SignalException
|
204
230
|
def report_fails(class_coverage_above_minimum, total_covered)
|
205
231
|
if total_covered[:covered] < minimum_project_coverage_percentage
|
206
232
|
# fail danger if total coverage is smaller than minimum_project_coverage_percentage
|
207
233
|
covered = total_covered[:covered]
|
208
234
|
fail("Total coverage of #{covered}%. Improve this to at least #{minimum_project_coverage_percentage}%")
|
235
|
+
# rubocop:disable Lint/UnreachableCode (rubocop mistakenly thinks that this line is unreachable since priorly called "fail" raises an error, but in fact "fail" is caught and handled)
|
236
|
+
create_status_file_on_failure if class_coverage_above_minimum
|
237
|
+
# rubocop:enable Lint/UnreachableCode
|
209
238
|
end
|
210
239
|
|
211
240
|
return if class_coverage_above_minimum
|
212
241
|
|
213
242
|
fail("Class coverage is below minimum. Improve to at least #{minimum_class_coverage_percentage}%")
|
243
|
+
# rubocop:disable Lint/UnreachableCode (rubocop mistakenly thinks that this line is unreachable since priorly called "fail" raises an error, but in fact "fail" is caught and handled)
|
244
|
+
create_status_file_on_failure
|
245
|
+
# rubocop:enable Lint/UnreachableCode
|
214
246
|
end
|
215
247
|
# rubocop:enable Style/SignalException
|
216
248
|
|
217
|
-
def
|
249
|
+
def create_status_file_on_failure
|
250
|
+
File.open(file_to_create_on_failure, 'w') {}
|
251
|
+
end
|
252
|
+
|
253
|
+
def markdown_class(parser, report_markdown, report_url, class_to_file_path_hash)
|
218
254
|
class_coverage_above_minimum = true
|
219
255
|
parser.classes.each do |jacoco_class| # Check metrics for each classes
|
220
|
-
|
256
|
+
file_path = class_to_file_path_hash[jacoco_class.name]
|
257
|
+
rp = report_class(jacoco_class, file_path)
|
221
258
|
rl = report_link(jacoco_class.name, report_url)
|
222
259
|
ln = "| #{rl} | #{rp[:covered]}% | #{rp[:required_coverage_percentage]}% | #{rp[:status]} |\n"
|
223
260
|
report_markdown << ln
|
data/spec/fixtures/output_a.xml
CHANGED
@@ -10,7 +10,7 @@
|
|
10
10
|
<counter type="COMPLEXITY" missed="0" covered="1"/>
|
11
11
|
<counter type="METHOD" missed="0" covered="1"/>
|
12
12
|
</method>
|
13
|
-
<counter type="INSTRUCTION" missed="
|
13
|
+
<counter type="INSTRUCTION" missed="46" covered="46"/>
|
14
14
|
<counter type="LINE" missed="0" covered="14"/>
|
15
15
|
<counter type="COMPLEXITY" missed="5" covered="7"/>
|
16
16
|
<counter type="METHOD" missed="0" covered="7"/>
|
data/spec/fixtures/output_b.xml
CHANGED
@@ -9,7 +9,6 @@
|
|
9
9
|
<counter type="COMPLEXITY" missed="0" covered="1"/>
|
10
10
|
<counter type="METHOD" missed="0" covered="1"/>
|
11
11
|
</method>
|
12
|
-
<counter type="INSTRUCTION" missed="0" covered="46"/>
|
13
12
|
<counter type="COMPLEXITY" missed="5" covered="7"/>
|
14
13
|
<counter type="METHOD" missed="0" covered="7"/>
|
15
14
|
<counter type="CLASS" missed="0" covered="1"/>
|
@@ -17,7 +16,6 @@
|
|
17
16
|
<sourcefile name="CachedRepository.java">
|
18
17
|
<line nr="16" mi="0" ci="2" mb="0" cb="0"/>
|
19
18
|
<line nr="17" mi="0" ci="3" mb="0" cb="0"/>
|
20
|
-
<counter type="INSTRUCTION" missed="2" covered="98"/>
|
21
19
|
<counter type="COMPLEXITY" missed="2" covered="11"/>
|
22
20
|
<counter type="METHOD" missed="2" covered="11"/>
|
23
21
|
<counter type="CLASS" missed="2" covered="4"/>
|
data/spec/fixtures/output_c.xml
CHANGED
@@ -10,7 +10,7 @@
|
|
10
10
|
<counter type="COMPLEXITY" missed="0" covered="1"/>
|
11
11
|
<counter type="METHOD" missed="0" covered="1"/>
|
12
12
|
</method>
|
13
|
-
<counter type="INSTRUCTION" missed="
|
13
|
+
<counter type="INSTRUCTION" missed="46" covered="46"/>
|
14
14
|
<counter type="LINE" missed="0" covered="14"/>
|
15
15
|
<counter type="COMPLEXITY" missed="5" covered="7"/>
|
16
16
|
<counter type="METHOD" missed="0" covered="7"/>
|
@@ -41,7 +41,7 @@
|
|
41
41
|
<counter type="COMPLEXITY" missed="0" covered="1"/>
|
42
42
|
<counter type="METHOD" missed="0" covered="1"/>
|
43
43
|
</method>
|
44
|
-
<counter type="INSTRUCTION" missed="
|
44
|
+
<counter type="INSTRUCTION" missed="18" covered="36"/>
|
45
45
|
<counter type="LINE" missed="0" covered="12"/>
|
46
46
|
<counter type="COMPLEXITY" missed="5" covered="8"/>
|
47
47
|
<counter type="METHOD" missed="0" covered="9"/>
|
@@ -0,0 +1,35 @@
|
|
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="46" covered="118"/>
|
13
|
+
<counter type="LINE" missed="1" covered="14"/>
|
14
|
+
<counter type="COMPLEXITY" missed="5" covered="7"/>
|
15
|
+
<counter type="METHOD" missed="0" covered="7"/>
|
16
|
+
<counter type="CLASS" missed="0" covered="1"/>
|
17
|
+
<counter type="BRANCH" missed="2" covered="3" />
|
18
|
+
</class>
|
19
|
+
<sourcefile name="CachedRepository.java">
|
20
|
+
<line nr="16" mi="0" ci="2" mb="0" cb="0"/>
|
21
|
+
<line nr="17" mi="0" ci="3" mb="0" cb="0"/>
|
22
|
+
<counter type="COMPLEXITY" missed="2" covered="11"/>
|
23
|
+
<counter type="METHOD" missed="2" covered="11"/>
|
24
|
+
<counter type="CLASS" missed="2" covered="4"/>
|
25
|
+
</sourcefile>
|
26
|
+
<counter type="INSTRUCTION" missed="80" covered="324"/>
|
27
|
+
<counter type="COMPLEXITY" missed="11" covered="39"/>
|
28
|
+
<counter type="METHOD" missed="9" covered="37"/>
|
29
|
+
<counter type="CLASS" missed="2" covered="10"/>
|
30
|
+
</package>
|
31
|
+
<counter type="INSTRUCTION" missed="39399" covered="19321"/>
|
32
|
+
<counter type="COMPLEXITY" missed="5517" covered="1444"/>
|
33
|
+
<counter type="METHOD" missed="3382" covered="1120"/>
|
34
|
+
<counter type="CLASS" missed="491" covered="370"/>
|
35
|
+
</report>
|
@@ -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="LINE" missed="1" covered="14"/>
|
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
|
+
<counter type="BRANCH" missed="4" covered="3" />
|
17
|
+
</class>
|
18
|
+
<sourcefile name="CachedRepository.java">
|
19
|
+
<line nr="16" mi="0" ci="2" mb="0" cb="0"/>
|
20
|
+
<line nr="17" mi="0" ci="3" mb="0" cb="0"/>
|
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>
|
@@ -0,0 +1,33 @@
|
|
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="LINE" missed="1" covered="14"/>
|
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="COMPLEXITY" missed="2" covered="11"/>
|
21
|
+
<counter type="METHOD" missed="2" covered="11"/>
|
22
|
+
<counter type="CLASS" missed="2" covered="4"/>
|
23
|
+
</sourcefile>
|
24
|
+
<counter type="INSTRUCTION" missed="80" covered="324"/>
|
25
|
+
<counter type="COMPLEXITY" missed="11" covered="39"/>
|
26
|
+
<counter type="METHOD" missed="9" covered="37"/>
|
27
|
+
<counter type="CLASS" missed="2" covered="10"/>
|
28
|
+
</package>
|
29
|
+
<counter type="INSTRUCTION" missed="39399" covered="19321"/>
|
30
|
+
<counter type="COMPLEXITY" missed="5517" covered="1444"/>
|
31
|
+
<counter type="METHOD" missed="3382" covered="1120"/>
|
32
|
+
<counter type="CLASS" missed="491" covered="370"/>
|
33
|
+
</report>
|
data/spec/jacoco_spec.rb
CHANGED
@@ -25,6 +25,7 @@ module Danger
|
|
25
25
|
|
26
26
|
allow(@dangerfile.git).to receive(:modified_files).and_return(modified_files)
|
27
27
|
allow(@dangerfile.git).to receive(:added_files).and_return(added_files)
|
28
|
+
allow(File).to receive(:open).and_call_original
|
28
29
|
end
|
29
30
|
|
30
31
|
it :report do
|
@@ -43,6 +44,36 @@ module Danger
|
|
43
44
|
expect(@dangerfile.status_report[:markdowns][0].message).to include('| `com/example/CachedRepository` | 50% | 100% | :warning: |')
|
44
45
|
end
|
45
46
|
|
47
|
+
it 'creates supplied status file upon failure' do
|
48
|
+
path_a = "#{File.dirname(__FILE__)}/fixtures/output_a.xml"
|
49
|
+
|
50
|
+
@my_plugin.minimum_project_coverage_percentage = 100
|
51
|
+
@my_plugin.minimum_class_coverage_percentage = 60
|
52
|
+
@my_plugin.file_to_create_on_failure = 'kmm.txt'
|
53
|
+
|
54
|
+
expect(File).to receive(:open).with('kmm.txt', 'w')
|
55
|
+
@my_plugin.report path_a
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'creates default status file upon failure' do
|
59
|
+
path_a = "#{File.dirname(__FILE__)}/fixtures/output_a.xml"
|
60
|
+
|
61
|
+
@my_plugin.minimum_class_coverage_percentage = 60
|
62
|
+
|
63
|
+
expect(File).to receive(:open).with('danger_jacoco_failure_status_file.txt', 'w')
|
64
|
+
@my_plugin.report path_a
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'does _not_ create status file upon success' do
|
68
|
+
path_a = "#{File.dirname(__FILE__)}/fixtures/output_a.xml"
|
69
|
+
|
70
|
+
@my_plugin.minimum_class_coverage_percentage = 40
|
71
|
+
@my_plugin.file_to_create_on_failure = 'kmm.txt'
|
72
|
+
|
73
|
+
expect(File).to_not receive(:open).with('kmm.txt', 'w')
|
74
|
+
@my_plugin.report path_a
|
75
|
+
end
|
76
|
+
|
46
77
|
it 'test regex class coverage' do
|
47
78
|
path_a = "#{File.dirname(__FILE__)}/fixtures/output_a.xml"
|
48
79
|
|
@@ -295,6 +326,72 @@ module Danger
|
|
295
326
|
|
296
327
|
expect(@dangerfile.status_report[:markdowns][0].message).to include('| New files | Covered | Required | Status |')
|
297
328
|
end
|
329
|
+
|
330
|
+
it 'instruction coverage takes over all the rest coverages for classes' do
|
331
|
+
path_a = "#{File.dirname(__FILE__)}/fixtures/output_d.xml"
|
332
|
+
|
333
|
+
@my_plugin.minimum_class_coverage_percentage = 50
|
334
|
+
|
335
|
+
@my_plugin.report path_a
|
336
|
+
|
337
|
+
expect(@dangerfile.status_report[:markdowns][0].message).to include('| `com/example/CachedRepository` | 71% | 50% | :white_check_mark: |')
|
338
|
+
end
|
339
|
+
|
340
|
+
it 'branch coverage takes over line coverage for classes, when instruction coverage is not available' do
|
341
|
+
path_a = "#{File.dirname(__FILE__)}/fixtures/output_e.xml"
|
342
|
+
|
343
|
+
@my_plugin.minimum_class_coverage_percentage = 50
|
344
|
+
|
345
|
+
@my_plugin.report path_a
|
346
|
+
|
347
|
+
expect(@dangerfile.status_report[:markdowns][0].message).to include('| `com/example/CachedRepository` | 42% | 50% | :warning: |')
|
348
|
+
end
|
349
|
+
|
350
|
+
it 'line coverage takes over for classes, when both instruction coverage and branch coverage are not available' do
|
351
|
+
path_a = "#{File.dirname(__FILE__)}/fixtures/output_f.xml"
|
352
|
+
|
353
|
+
@my_plugin.minimum_class_coverage_percentage = 50
|
354
|
+
|
355
|
+
@my_plugin.report path_a
|
356
|
+
|
357
|
+
expect(@dangerfile.status_report[:markdowns][0].message).to include('| `com/example/CachedRepository` | 93% | 50% | :white_check_mark: |')
|
358
|
+
end
|
359
|
+
|
360
|
+
describe 'with CachedRepository containing @Composable annotation' do
|
361
|
+
before do
|
362
|
+
allow(File).to receive(:exist?).with('src/java/com/example/CachedRepository.java').and_return(true)
|
363
|
+
allow(File).to receive(:read).with('src/java/com/example/CachedRepository.java').and_return('package com.kevin.mia.mikaela class Vika { @Composable fun someUiWidget() {} }')
|
364
|
+
end
|
365
|
+
|
366
|
+
it 'applies minimum_composable_class_coverage_percentage' do
|
367
|
+
path_a = "#{File.dirname(__FILE__)}/fixtures/output_a.xml"
|
368
|
+
|
369
|
+
@my_plugin.minimum_class_coverage_percentage = 55
|
370
|
+
@my_plugin.minimum_composable_class_coverage_percentage = 45
|
371
|
+
|
372
|
+
@my_plugin.report path_a
|
373
|
+
|
374
|
+
expect(@dangerfile.status_report[:markdowns][0].message).to include('| `com/example/CachedRepository` | 50% | 45% | :white_check_mark: |')
|
375
|
+
end
|
376
|
+
end
|
377
|
+
|
378
|
+
describe 'with CachedRepository _not_ containing @Composable annotation' do
|
379
|
+
before do
|
380
|
+
allow(File).to receive(:exist?).with('src/java/com/example/CachedRepository.java').and_return(true)
|
381
|
+
allow(File).to receive(:read).with('src/java/com/example/CachedRepository.java').and_return('package com.kevin.mia.mikaela class Vika { fun main() {} }')
|
382
|
+
end
|
383
|
+
|
384
|
+
it 'does not apply minimum_composable_class_coverage_percentage' do
|
385
|
+
path_a = "#{File.dirname(__FILE__)}/fixtures/output_a.xml"
|
386
|
+
|
387
|
+
@my_plugin.minimum_class_coverage_percentage = 55
|
388
|
+
@my_plugin.minimum_composable_class_coverage_percentage = 45
|
389
|
+
|
390
|
+
@my_plugin.report path_a
|
391
|
+
|
392
|
+
expect(@dangerfile.status_report[:markdowns][0].message).to include('| `com/example/CachedRepository` | 50% | 55% | :warning: |')
|
393
|
+
end
|
394
|
+
end
|
298
395
|
end
|
299
396
|
end
|
300
397
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: danger-jacoco-instacart
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.12.SNAPSHOT.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Anton Malinskiy
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2022-08
|
12
|
+
date: 2022-09-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: danger-plugin-api
|
@@ -208,6 +208,9 @@ files:
|
|
208
208
|
- spec/fixtures/output_a.xml
|
209
209
|
- spec/fixtures/output_b.xml
|
210
210
|
- spec/fixtures/output_c.xml
|
211
|
+
- spec/fixtures/output_d.xml
|
212
|
+
- spec/fixtures/output_e.xml
|
213
|
+
- spec/fixtures/output_f.xml
|
211
214
|
- spec/jacoco_spec.rb
|
212
215
|
- spec/spec_helper.rb
|
213
216
|
homepage: https://github.com/alexanderbezverhni/danger-jacoco
|
@@ -225,9 +228,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
225
228
|
version: '2.6'
|
226
229
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
227
230
|
requirements:
|
228
|
-
- - "
|
231
|
+
- - ">"
|
229
232
|
- !ruby/object:Gem::Version
|
230
|
-
version:
|
233
|
+
version: 1.3.1
|
231
234
|
requirements: []
|
232
235
|
rubygems_version: 3.1.2
|
233
236
|
signing_key:
|
@@ -237,5 +240,8 @@ test_files:
|
|
237
240
|
- spec/fixtures/output_a.xml
|
238
241
|
- spec/fixtures/output_b.xml
|
239
242
|
- spec/fixtures/output_c.xml
|
243
|
+
- spec/fixtures/output_d.xml
|
244
|
+
- spec/fixtures/output_e.xml
|
245
|
+
- spec/fixtures/output_f.xml
|
240
246
|
- spec/jacoco_spec.rb
|
241
247
|
- spec/spec_helper.rb
|