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,85 @@
1
+ # frozen_string_literal: true
2
+
3
+ require(File.expand_path('spec_helper', __dir__))
4
+ require('code_coverage/coverage_parser')
5
+
6
+ module CodeCoverage
7
+ describe CoverageParser do
8
+ before do
9
+ @parser = CoverageParser.new
10
+ @content = nil
11
+ end
12
+
13
+ it 'extracts all file coverage' do
14
+ read_file('/assets/coverage_jacoco.json')
15
+ items = @parser.parse(@content)
16
+ expect(items.length).to(be(18))
17
+ end
18
+
19
+ context 'html not found' do
20
+ it 'returns empty hash' do
21
+ read_file('/assets/missing_json.html')
22
+ items = @parser.parse(@content)
23
+ expect(items.length).to(be_zero)
24
+ end
25
+ end
26
+
27
+ context 'no files in json' do
28
+ it 'returns empty json' do
29
+ read_file('/assets/coverage_no_files.json')
30
+ items = @parser.parse(@content)
31
+ expect(items.length).to(be_zero)
32
+ end
33
+ end
34
+
35
+ context 'jacoco' do
36
+ it 'combines directory and file name' do
37
+ read_file('/assets/coverage_jacoco_single.json')
38
+ items = @parser.parse(@content)
39
+ expect(items.length).to(be(1))
40
+ expect(items.first.file).to(eq('com/example/kyaak/myapplication/MainActivity.java'))
41
+ end
42
+
43
+ it 'parses elements' do
44
+ read_file('/assets/coverage_jacoco_single.json')
45
+ items = @parser.parse(@content)
46
+ expect(items.length).to(be(1))
47
+ expect(items.first.line).to(be(75.0))
48
+ expect(items.first.method).to(be(13.34))
49
+ expect(items.first.instruction).to(be(65.44))
50
+ expect(items.first.conditional).to(be(49.99))
51
+ end
52
+ end
53
+
54
+ context 'cobertura' do
55
+ it 'does not add parent name if file has directory' do
56
+ read_file('/assets/coverage_cobertura_single.json')
57
+ items = @parser.parse(@content)
58
+ expect(items.length).to(be(1))
59
+ expect(items.first.file).to(eq('src/cpp/default/builder_example/ExampleListener.cpp'))
60
+ end
61
+
62
+ it 'does not add python packages' do
63
+ read_file('/assets/coverage_cobertura_python.json')
64
+ items = @parser.parse(@content)
65
+ expect(items.length).to(be(12))
66
+ items.each do |item|
67
+ expect(item.file).not_to(match(%r{.*\..*\/.*}))
68
+ end
69
+ end
70
+
71
+ it 'does not add dot packages' do
72
+ read_file('/assets/coverage_dot_package_single.json')
73
+ items = @parser.parse(@content)
74
+ expect(items.length).to(be(1))
75
+ expect(items.first.file).to(eq('generator.py'))
76
+ end
77
+ end
78
+
79
+ context
80
+ end
81
+ end
82
+
83
+ def read_file(file)
84
+ @content = File.read(File.dirname(__FILE__) + file)
85
+ end
@@ -0,0 +1,72 @@
1
+ # frozen_string_literal: true
2
+
3
+ require('pathname')
4
+ ROOT = Pathname.new(File.expand_path('..', __dir__))
5
+ $LOAD_PATH.unshift((ROOT + 'lib').to_s)
6
+ $LOAD_PATH.unshift((ROOT + 'spec').to_s)
7
+
8
+ require('bundler/setup')
9
+
10
+ require('rspec')
11
+ require('danger')
12
+ require('mocha')
13
+
14
+ require('simplecov')
15
+
16
+ SimpleCov.start
17
+
18
+ if %x(git remote -v) == ''
19
+ puts('You cannot run tests without setting a local git remote on this repo')
20
+ puts("It's a weird side-effect of Danger's internals.")
21
+ exit(0)
22
+ end
23
+
24
+ # Use coloured output, it's the best.
25
+ RSpec.configure do |config|
26
+ config.filter_gems_from_backtrace('bundler')
27
+ config.color = true
28
+ config.tty = true
29
+ config.mock_with(:mocha)
30
+ end
31
+
32
+ require('danger_plugin')
33
+
34
+ # These functions are a subset of https://github.com/danger/danger/blob/master/spec/spec_helper.rb
35
+ # If you are expanding these files, see if it's already been done ^.
36
+
37
+ # A silent version of the user interface,
38
+ # it comes with an extra function `.string` which will
39
+ # strip all ANSI colours from the string.
40
+
41
+ # rubocop:disable Lint/NestedMethodDefinition
42
+ def testing_ui
43
+ @output = StringIO.new
44
+ def @output.winsize
45
+ [20, 9999]
46
+ end
47
+
48
+ cork = Cork::Board.new(out: @output)
49
+ def cork.string
50
+ out.string.gsub(%r{\e\[([;\d]+)?m}, '')
51
+ end
52
+ cork
53
+ end
54
+ # rubocop:enable Lint/NestedMethodDefinition
55
+
56
+ # Example environment (ENV) that would come from
57
+ # running a PR on TravisCI
58
+ def testing_env
59
+ {
60
+ 'HAS_JOSH_K_SEAL_OF_APPROVAL' => 'true',
61
+ 'TRAVIS_PULL_REQUEST' => '800',
62
+ 'TRAVIS_REPO_SLUG' => 'artsy/eigen',
63
+ 'TRAVIS_COMMIT_RANGE' => '759adcbd0d8f...13c4dc8bb61d',
64
+ 'DANGER_GITHUB_API_TOKEN' => '123sbdq54erfsd3422gdfio'
65
+ }
66
+ end
67
+
68
+ # A stubbed out Dangerfile for use in tests
69
+ def testing_dangerfile
70
+ env = Danger::EnvironmentManager.new(testing_env)
71
+ Danger::Dangerfile.new(env, testing_ui)
72
+ end
metadata ADDED
@@ -0,0 +1,239 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: danger-code_coverage
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Martin Schwamberger
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-06-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: danger-plugin-api
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '12.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '12.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: mocha
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.8'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.8'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.8'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.8'
83
+ - !ruby/object:Gem::Dependency
84
+ name: simplecov
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.16'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.16'
97
+ - !ruby/object:Gem::Dependency
98
+ name: simplecov-console
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.4'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.4'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rubocop
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '0.68'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '0.68'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rubocop-performance
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '1.2'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '1.2'
139
+ - !ruby/object:Gem::Dependency
140
+ name: rubocop-thread_safety
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '0.3'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '0.3'
153
+ - !ruby/object:Gem::Dependency
154
+ name: yard
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: '0.9'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: '0.9'
167
+ description: Danger plugin for Jenkins-Code-Coverage-Api plugin.
168
+ email:
169
+ - kyaak.dev@gmail.com
170
+ executables: []
171
+ extensions: []
172
+ extra_rdoc_files: []
173
+ files:
174
+ - ".gitignore"
175
+ - ".rubocop.yml"
176
+ - ".travis.yml"
177
+ - CHANGELOG.md
178
+ - Gemfile
179
+ - LICENSE.txt
180
+ - README.md
181
+ - Rakefile
182
+ - danger-code_coverage.gemspec
183
+ - lib/code_coverage/coverage_item.rb
184
+ - lib/code_coverage/coverage_parser.rb
185
+ - lib/code_coverage/gem_version.rb
186
+ - lib/code_coverage/markdown_table.rb
187
+ - lib/code_coverage/plugin.rb
188
+ - lib/danger_code_coverage.rb
189
+ - lib/danger_plugin.rb
190
+ - sonar-project.properties
191
+ - spec/assets/coverage_cobertura_python.json
192
+ - spec/assets/coverage_cobertura_single.json
193
+ - spec/assets/coverage_dot_package_single.json
194
+ - spec/assets/coverage_jacoco.json
195
+ - spec/assets/coverage_jacoco_multiple_unordered.json
196
+ - spec/assets/coverage_jacoco_no_conditional.json
197
+ - spec/assets/coverage_jacoco_single.json
198
+ - spec/assets/coverage_no_files.json
199
+ - spec/assets/missing_json.html
200
+ - spec/code_coverage_spec.rb
201
+ - spec/coverage_parser_spec.rb
202
+ - spec/spec_helper.rb
203
+ homepage: https://github.com/Kyaak/danger-code_coverage
204
+ licenses:
205
+ - MIT
206
+ metadata: {}
207
+ post_install_message:
208
+ rdoc_options: []
209
+ require_paths:
210
+ - lib
211
+ required_ruby_version: !ruby/object:Gem::Requirement
212
+ requirements:
213
+ - - ">="
214
+ - !ruby/object:Gem::Version
215
+ version: 2.3.0
216
+ required_rubygems_version: !ruby/object:Gem::Requirement
217
+ requirements:
218
+ - - ">="
219
+ - !ruby/object:Gem::Version
220
+ version: '0'
221
+ requirements: []
222
+ rubygems_version: 3.0.4
223
+ signing_key:
224
+ specification_version: 4
225
+ summary: Read Jenkins code-coverage reports and comment pull request with coverage
226
+ for changed files.
227
+ test_files:
228
+ - spec/assets/coverage_cobertura_python.json
229
+ - spec/assets/coverage_cobertura_single.json
230
+ - spec/assets/coverage_dot_package_single.json
231
+ - spec/assets/coverage_jacoco.json
232
+ - spec/assets/coverage_jacoco_multiple_unordered.json
233
+ - spec/assets/coverage_jacoco_no_conditional.json
234
+ - spec/assets/coverage_jacoco_single.json
235
+ - spec/assets/coverage_no_files.json
236
+ - spec/assets/missing_json.html
237
+ - spec/code_coverage_spec.rb
238
+ - spec/coverage_parser_spec.rb
239
+ - spec/spec_helper.rb