danger-code_coverage 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,250 @@
1
+ {
2
+ "_class": "io.jenkins.plugins.coverage.targets.CoverageResult",
3
+ "results": {
4
+ "children": [
5
+ {
6
+ "children": [
7
+ {
8
+ "children": [
9
+ {
10
+ "children": [
11
+ {
12
+ "children": [
13
+ {},
14
+ {}
15
+ ],
16
+ "elements": [
17
+ {
18
+ "denominator": 2.0,
19
+ "name": "Class",
20
+ "numerator": 0.0,
21
+ "ratio": 0.0
22
+ },
23
+ {
24
+ "denominator": 7.0,
25
+ "name": "Method",
26
+ "numerator": 0.0,
27
+ "ratio": 13.3444
28
+ },
29
+ {
30
+ "denominator": 75.0,
31
+ "name": "Instruction",
32
+ "numerator": 0.0,
33
+ "ratio": 65.442
34
+ },
35
+ {
36
+ "denominator": 21.0,
37
+ "name": "Line",
38
+ "numerator": 0.0,
39
+ "ratio": 75.0
40
+ },
41
+ {
42
+ "denominator": 2.0,
43
+ "name": "Conditional",
44
+ "numerator": 0.0,
45
+ "ratio": 49.99
46
+ }
47
+ ],
48
+ "name": "MainActivity.java"
49
+ }
50
+ ],
51
+ "elements": [
52
+ {
53
+ "denominator": 3.0,
54
+ "name": "File",
55
+ "numerator": 1.0,
56
+ "ratio": 33.333332
57
+ },
58
+ {
59
+ "denominator": 4.0,
60
+ "name": "Class",
61
+ "numerator": 1.0,
62
+ "ratio": 25.0
63
+ },
64
+ {
65
+ "denominator": 15.0,
66
+ "name": "Method",
67
+ "numerator": 1.0,
68
+ "ratio": 6.6666665
69
+ },
70
+ {
71
+ "denominator": 110.0,
72
+ "name": "Instruction",
73
+ "numerator": 6.0,
74
+ "ratio": 5.4545455
75
+ },
76
+ {
77
+ "denominator": 34.0,
78
+ "name": "Line",
79
+ "numerator": 1.0,
80
+ "ratio": 2.9411764
81
+ },
82
+ {
83
+ "denominator": 6.0,
84
+ "name": "Conditional",
85
+ "numerator": 2.0,
86
+ "ratio": 33.333332
87
+ }
88
+ ],
89
+ "name": "com/example/kyaak/myapplication"
90
+ }
91
+ ],
92
+ "elements": [
93
+ {
94
+ "denominator": 5.0,
95
+ "name": "Package",
96
+ "numerator": 3.0,
97
+ "ratio": 60.0
98
+ },
99
+ {
100
+ "denominator": 18.0,
101
+ "name": "File",
102
+ "numerator": 3.0,
103
+ "ratio": 16.666666
104
+ },
105
+ {
106
+ "denominator": 21.0,
107
+ "name": "Class",
108
+ "numerator": 3.0,
109
+ "ratio": 14.285714
110
+ },
111
+ {
112
+ "denominator": 193.0,
113
+ "name": "Method",
114
+ "numerator": 6.0,
115
+ "ratio": 3.1088083
116
+ },
117
+ {
118
+ "denominator": 2169.0,
119
+ "name": "Instruction",
120
+ "numerator": 52.0,
121
+ "ratio": 2.3974183
122
+ },
123
+ {
124
+ "denominator": 296.0,
125
+ "name": "Line",
126
+ "numerator": 9.0,
127
+ "ratio": 3.0405405
128
+ },
129
+ {
130
+ "denominator": 178.0,
131
+ "name": "Conditional",
132
+ "numerator": 3.0,
133
+ "ratio": 1.6853932
134
+ }
135
+ ],
136
+ "name": "project"
137
+ }
138
+ ],
139
+ "elements": [
140
+ {
141
+ "denominator": 1.0,
142
+ "name": "Group",
143
+ "numerator": 1.0,
144
+ "ratio": 100.0
145
+ },
146
+ {
147
+ "denominator": 5.0,
148
+ "name": "Package",
149
+ "numerator": 3.0,
150
+ "ratio": 60.0
151
+ },
152
+ {
153
+ "denominator": 18.0,
154
+ "name": "File",
155
+ "numerator": 3.0,
156
+ "ratio": 16.666666
157
+ },
158
+ {
159
+ "denominator": 21.0,
160
+ "name": "Class",
161
+ "numerator": 3.0,
162
+ "ratio": 14.285714
163
+ },
164
+ {
165
+ "denominator": 193.0,
166
+ "name": "Method",
167
+ "numerator": 6.0,
168
+ "ratio": 3.1088083
169
+ },
170
+ {
171
+ "denominator": 2169.0,
172
+ "name": "Instruction",
173
+ "numerator": 52.0,
174
+ "ratio": 2.3974183
175
+ },
176
+ {
177
+ "denominator": 296.0,
178
+ "name": "Line",
179
+ "numerator": 9.0,
180
+ "ratio": 3.0405405
181
+ },
182
+ {
183
+ "denominator": 178.0,
184
+ "name": "Conditional",
185
+ "numerator": 3.0,
186
+ "ratio": 1.6853932
187
+ }
188
+ ],
189
+ "name": "code_quality: jacoco.xml"
190
+ }
191
+ ],
192
+ "elements": [
193
+ {
194
+ "denominator": 1.0,
195
+ "name": "Report",
196
+ "numerator": 1.0,
197
+ "ratio": 100.0
198
+ },
199
+ {
200
+ "denominator": 1.0,
201
+ "name": "Group",
202
+ "numerator": 1.0,
203
+ "ratio": 100.0
204
+ },
205
+ {
206
+ "denominator": 5.0,
207
+ "name": "Package",
208
+ "numerator": 3.0,
209
+ "ratio": 60.0
210
+ },
211
+ {
212
+ "denominator": 18.0,
213
+ "name": "File",
214
+ "numerator": 3.0,
215
+ "ratio": 16.666666
216
+ },
217
+ {
218
+ "denominator": 21.0,
219
+ "name": "Class",
220
+ "numerator": 3.0,
221
+ "ratio": 14.285714
222
+ },
223
+ {
224
+ "denominator": 193.0,
225
+ "name": "Method",
226
+ "numerator": 6.0,
227
+ "ratio": 3.1088083
228
+ },
229
+ {
230
+ "denominator": 2169.0,
231
+ "name": "Instruction",
232
+ "numerator": 52.0,
233
+ "ratio": 2.3974183
234
+ },
235
+ {
236
+ "denominator": 296.0,
237
+ "name": "Line",
238
+ "numerator": 9.0,
239
+ "ratio": 3.0405405
240
+ },
241
+ {
242
+ "denominator": 178.0,
243
+ "name": "Conditional",
244
+ "numerator": 3.0,
245
+ "ratio": 1.6853932
246
+ }
247
+ ],
248
+ "name": "All reports"
249
+ }
250
+ }
@@ -0,0 +1,65 @@
1
+ {
2
+ "_class": "io.jenkins.plugins.coverage.targets.CoverageResult",
3
+ "results": {
4
+ "children": [
5
+ {
6
+ "children": [
7
+ {
8
+ "children": [
9
+ {
10
+ "children": [],
11
+ "elements": [],
12
+ "name": "repository"
13
+ }
14
+ ],
15
+ "elements": [
16
+ {
17
+ "denominator": 1.0,
18
+ "name": "Package",
19
+ "numerator": 0.0,
20
+ "ratio": 0.0
21
+ }
22
+ ],
23
+ "name": "project"
24
+ }
25
+ ],
26
+ "elements": [
27
+ {
28
+ "denominator": 1.0,
29
+ "name": "Group",
30
+ "numerator": 0.0,
31
+ "ratio": 0.0
32
+ },
33
+ {
34
+ "denominator": 1.0,
35
+ "name": "Package",
36
+ "numerator": 0.0,
37
+ "ratio": 0.0
38
+ }
39
+ ],
40
+ "name": "cobertura: coverage.xml"
41
+ }
42
+ ],
43
+ "elements": [
44
+ {
45
+ "denominator": 1.0,
46
+ "name": "Report",
47
+ "numerator": 0.0,
48
+ "ratio": 0.0
49
+ },
50
+ {
51
+ "denominator": 1.0,
52
+ "name": "Group",
53
+ "numerator": 0.0,
54
+ "ratio": 0.0
55
+ },
56
+ {
57
+ "denominator": 1.0,
58
+ "name": "Package",
59
+ "numerator": 0.0,
60
+ "ratio": 0.0
61
+ }
62
+ ],
63
+ "name": "All reports"
64
+ }
65
+ }
@@ -0,0 +1,7 @@
1
+ <html>
2
+ <head>
3
+ <meta http-equiv="refresh" content="1;url=.."/>
4
+ <script>window.location.replace("..");</script>
5
+ </head>
6
+ <body style="background-color: white; color: white;">Not Found</body>
7
+ </html>
@@ -0,0 +1,134 @@
1
+ # frozen_string_literal: true
2
+
3
+ require(File.expand_path('spec_helper', __dir__))
4
+ MARKDOWN_FIRST_TABLE_INDEX = 4
5
+ JAVA_ALL_BASELINE = '/var/lib/jenkins/workspace/projectname/b2b-app-android-analyze/repository/'
6
+
7
+ module Danger
8
+ describe Danger::DangerCodeCoverage do
9
+ it 'should be a plugin' do
10
+ expect(Danger::DangerCodeCoverage.new(nil)).to(be_a(Danger::Plugin))
11
+ end
12
+
13
+ describe 'with Dangerfile' do
14
+ before do
15
+ @dangerfile = testing_dangerfile
16
+ @plugin = @dangerfile.code_coverage
17
+ end
18
+
19
+ describe 'report' do
20
+ it 'does not add table if no files in json' do
21
+ mock_coverage_json('/assets/coverage_no_files.json')
22
+ mock_file_in_changeset(true)
23
+
24
+ @plugin.report
25
+ markdowns = @dangerfile.status_report[:markdowns]
26
+ expect(markdowns.length).to(be_zero)
27
+ end
28
+
29
+ it 'adds header' do
30
+ mock_coverage_json('/assets/coverage_jacoco_single.json')
31
+ mock_file_in_changeset(true)
32
+
33
+ @plugin.report
34
+ markdowns = @dangerfile.status_report[:markdowns]
35
+ expect(markdowns.length).to(be(1))
36
+ lines = markdowns.first.message.split("\n")
37
+ headers = lines[2].split('|')
38
+ expect(headers[1]).to(eq('**File**'))
39
+ expect(headers[2]).to(eq('**Total**'))
40
+ expect(headers[3]).to(eq('**Method**'))
41
+ expect(headers[4]).to(eq('**Line**'))
42
+ expect(headers[5]).to(eq('**Conditional**'))
43
+ expect(headers[6]).to(eq('**Instruction**'))
44
+ end
45
+
46
+ it 'adds entry values' do
47
+ mock_coverage_json('/assets/coverage_jacoco_single.json')
48
+ mock_file_in_changeset(true)
49
+
50
+ @plugin.report
51
+ markdowns = @dangerfile.status_report[:markdowns]
52
+ expect(markdowns.length).to(be(1))
53
+ lines = markdowns.first.message.split("\n")
54
+ entries = lines[4].split('|')
55
+ expect(entries[1]).to(eq('com/example/kyaak/myapplication/MainActivity.java'))
56
+ expect(entries[3]).to(eq('13.34'))
57
+ expect(entries[4]).to(eq('75.0'))
58
+ expect(entries[5]).to(eq('49.99'))
59
+ expect(entries[6]).to(eq('65.44'))
60
+ end
61
+
62
+ it 'adds dash for missing value' do
63
+ mock_coverage_json('/assets/coverage_jacoco_no_conditional.json')
64
+ mock_file_in_changeset(true)
65
+
66
+ @plugin.report
67
+ markdowns = @dangerfile.status_report[:markdowns]
68
+ expect(markdowns.length).to(be(1))
69
+ lines = markdowns.first.message.split("\n")
70
+ entries = lines[4].split('|')
71
+ expect(entries[1]).to(eq('com/example/kyaak/myapplication/MainActivity.java'))
72
+ expect(entries[3]).to(eq('13.34'))
73
+ expect(entries[4]).to(eq('75.0'))
74
+ expect(entries[5]).to(eq('-'))
75
+ expect(entries[6]).to(eq('65.44'))
76
+ end
77
+
78
+ it 'adds total' do
79
+ mock_coverage_json('/assets/coverage_jacoco_single.json')
80
+ mock_file_in_changeset(true)
81
+
82
+ @plugin.report
83
+ markdowns = @dangerfile.status_report[:markdowns]
84
+ expect(markdowns.length).to(be(1))
85
+ lines = markdowns.first.message.split("\n")
86
+ entries = lines[4].split('|')
87
+ expect(entries[2]).to(eq('50.94'))
88
+ end
89
+
90
+ it 'ignores empty column in total' do
91
+ mock_coverage_json('/assets/coverage_jacoco_no_conditional.json')
92
+ mock_file_in_changeset(true)
93
+
94
+ @plugin.report
95
+ markdowns = @dangerfile.status_report[:markdowns]
96
+ expect(markdowns.length).to(be(1))
97
+ lines = markdowns.first.message.split("\n")
98
+ entries = lines[4].split('|')
99
+ expect(entries[2]).to(eq('51.26'))
100
+ end
101
+
102
+ it 'sorts lines by total value descending' do
103
+ mock_coverage_json('/assets/coverage_jacoco_multiple_unordered.json')
104
+ mock_file_in_changeset(true)
105
+
106
+ @plugin.report
107
+ markdowns = @dangerfile.status_report[:markdowns]
108
+ expect(markdowns.length).to(be(1))
109
+ lines = markdowns.first.message.split("\n")
110
+ first = lines[4].split('|')
111
+ second = lines[5].split('|')
112
+ third = lines[6].split('|')
113
+
114
+ expect(first[1]).to(include('MainActivity2.java'))
115
+ expect(second[1]).to(include('MainActivity3.java'))
116
+ expect(third[1]).to(include('MainActivity.java'))
117
+ end
118
+ end
119
+ end
120
+ end
121
+ end
122
+
123
+ def mock_coverage_json(file)
124
+ content = File.read(File.dirname(__FILE__) + file)
125
+ @plugin.stubs(:coverage_json).returns(content)
126
+ end
127
+
128
+ def mock_target_files(list)
129
+ @plugin.stubs(:target_files).returns(list)
130
+ end
131
+
132
+ def mock_file_in_changeset(value)
133
+ @plugin.stubs(:file_in_changeset?).returns(value)
134
+ end