danger-jacoco 0.1.3 → 0.1.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: bbe04fa92db358efe7b876a9cc4a96ba345fed7f
4
- data.tar.gz: 4ee1125c139adce7f13e98ff8233a1ddae339640
2
+ SHA256:
3
+ metadata.gz: e27bdd91acf2d25a2fa8f0eb6e0a07e5375f6864d831d8ca3883437db5d95bd3
4
+ data.tar.gz: 4f5bfaf1bdecdf96e99044f0f63db762f52adbea608654b334f85e80588d3ae5
5
5
  SHA512:
6
- metadata.gz: 3b781beccdd7e277ed4a6296864ea3e1fb56315aa0bb636ae4e0002b758cd0dc5f55702e0c0380f4007501f1a87ff405e7c460cb349fd02eacba7c3d52f49acf
7
- data.tar.gz: c3708a9d043202c10748711683cfefddab20808eec536c2790a3f56ec463f47b306224fa6303f8c5d54174fc8e31ca38083629c5116ea2293a5fca66f71f3e63
6
+ metadata.gz: 873ab75273b2c8cdefcd3fe3fb524e5fe2173debfa4cc96c44a0b8a5ec5c2de3d8e0a4c89107467d2abff3976d6e7244fd14fa7c5e0fed6bbad6b0c3e25e2b53
7
+ data.tar.gz: ac8dba5b3af75092aa7e483f5d0fdde9780df01aa5f38cbc3b6f9f71cc29f182d8bf50398425991900b976406c32f16923cda9acbfb6c7c49287ed7f6f06d32c
@@ -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,13 @@
1
+ name: ci
2
+ on: [push]
3
+ jobs:
4
+ test:
5
+ runs-on: ubuntu-18.04
6
+ steps:
7
+ - uses: actions/checkout@v1
8
+ - uses: actions/setup-ruby@v1
9
+ with:
10
+ ruby-version: '2.6.x'
11
+ - run: gem install bundler
12
+ - run: bundle install
13
+ - run: bundle exec rake spec
@@ -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
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  # Specify your gem's dependencies in danger-jacoco.gemspec
data/Guardfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # A guardfile for making Danger Plugins
2
4
  # For more info see https://github.com/guard/guard#readme
3
5
 
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 "path/to/jacoco.xml"
27
+ jacoco.report("path/to/jacoco.xml", "http://jacoco-html-reports/")
21
28
  ```
22
29
 
23
30
  to your `Dangerfile`
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'bundler/gem_tasks'
2
4
  require 'rspec/core/rake_task'
3
5
  require 'rubocop/rake_task'
@@ -1,43 +1,45 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
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.rb'
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 = %q{A short description of danger-jacoco.}
12
- spec.summary = %q{A longer description of danger-jacoco.}
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', '~> 1.16'
26
- spec.add_development_dependency 'rake', '~> 12.3'
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 "rubocop", "~> 0.51"
33
- spec.add_development_dependency "yard", "~> 0.9"
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.5'
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
@@ -1 +1,3 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'jacoco/gem_version'
data/lib/danger_plugin.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'jacoco/plugin'
2
4
 
3
5
  require 'jacoco/dom_parser'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Jacoco
2
4
  # DOM parser for Jacoco report
3
5
  class DOMParser
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Jacoco
2
- VERSION = '0.1.3'.freeze
4
+ VERSION = '0.1.8'
3
5
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'happymapper'
2
4
  require 'jacoco/model/counter'
3
5
  require 'jacoco/model/method'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'happymapper'
2
4
 
3
5
  module Jacoco
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'happymapper'
2
4
  require 'jacoco/model/group'
3
5
  require 'jacoco/model/package'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'happymapper'
2
4
  require 'jacoco/model/counter'
3
5
  require 'jacoco/model/method'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'happymapper'
2
4
  require 'jacoco/model/counter'
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'happymapper'
2
4
  require 'jacoco/model/class'
3
5
  require 'jacoco/model/sourcefile'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'happymapper'
2
4
  require 'jacoco/model/session_info'
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'happymapper'
2
4
 
3
5
  module Jacoco
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'happymapper'
2
4
 
3
5
  module Jacoco
data/lib/jacoco/plugin.rb CHANGED
@@ -1,21 +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
- attr_accessor :minimum_class_coverage_percentage
11
- attr_accessor :files_extension
12
- attr_accessor :minimum_class_coverage_map
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
13
25
 
26
+ # Initialize the plugin with configured parameters or defaults
14
27
  def setup
15
28
  @minimum_project_coverage_percentage = 0 unless minimum_project_coverage_percentage
16
29
  @minimum_class_coverage_percentage = 0 unless minimum_class_coverage_percentage
30
+ @minimum_package_coverage_map = {} unless minimum_package_coverage_map
17
31
  @minimum_class_coverage_map = {} unless minimum_class_coverage_map
18
32
  @files_extension = ['.kt', '.java'] unless files_extension
33
+ @title = 'JaCoCo' unless title
19
34
  end
20
35
 
21
36
  # Parses the xml output of jacoco to Ruby model classes
@@ -30,6 +45,7 @@ module Danger
30
45
  # This is a fast report based on SAX parser
31
46
  #
32
47
  # @path path to the xml output of jacoco
48
+ # @report_url URL where html report hosted
33
49
  # @delimiter git.modified_files returns full paths to the
34
50
  # changed files. We need to get the class from this path to check the
35
51
  # Jacoco report,
@@ -43,7 +59,9 @@ module Danger
43
59
  # Java => blah/blah/java/slashed_package/Source.java
44
60
  # Kotlin => blah/blah/kotlin/slashed_package/Source.kt
45
61
  #
46
- def report(path, delimiter = %r{\/java\/|\/kotlin\/})
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
+
47
65
  setup
48
66
  classes = classes(delimiter)
49
67
 
@@ -52,10 +70,10 @@ module Danger
52
70
 
53
71
  total_covered = total_coverage(path)
54
72
 
55
- report_markdown = "### JaCoCO Code Coverage #{total_covered[:covered]}% #{total_covered[:status]}\n"
56
- report_markdown << "| Class | Covered | Meta | Status |\n"
57
- report_markdown << "|:---:|:---:|:---:|:---:|\n"
58
- 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)
59
77
  markdown(report_markdown)
60
78
 
61
79
  report_fails(class_coverage_above_minimum, total_covered)
@@ -71,17 +89,49 @@ module Danger
71
89
 
72
90
  # It returns a specific class code coverage and an emoji status as well
73
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
+
74
98
  counter = coverage_counter(jacoco_class)
75
- coverage = (counter.covered.fdiv(counter.covered + counter.missed) * 100).floor
76
- required_coverage = minimum_class_coverage_map[jacoco_class.name]
99
+ unless counter.nil?
100
+ coverage = (counter.covered.fdiv(counter.covered + counter.missed) * 100).floor
101
+ required_coverage = required_class_coverage(jacoco_class)
102
+ status = coverage_status(coverage, required_coverage)
103
+
104
+ report_result = {
105
+ covered: coverage,
106
+ status: status,
107
+ required_coverage_percentage: required_coverage
108
+ }
109
+ end
110
+
111
+ report_result
112
+ end
113
+
114
+ # Determines the required coverage for the class
115
+ def required_class_coverage(jacoco_class)
116
+ key = minimum_class_coverage_map.keys.detect { |k| jacoco_class.name.match(k) } || jacoco_class.name
117
+ required_coverage = minimum_class_coverage_map[key]
118
+ required_coverage = package_coverage(jacoco_class.name) if required_coverage.nil?
77
119
  required_coverage = minimum_class_coverage_percentage if required_coverage.nil?
78
- status = coverage_status(coverage, required_coverage)
120
+ required_coverage
121
+ end
79
122
 
80
- {
81
- covered: coverage,
82
- status: status,
83
- required_coverage_percentage: required_coverage
84
- }
123
+ # it returns the most suitable coverage by package name to class or nil
124
+ def package_coverage(class_name)
125
+ path = class_name
126
+ package_parts = class_name.split('/')
127
+ package_parts.reverse_each do |item|
128
+ size = item.size
129
+ path = path[0...-size]
130
+ coverage = minimum_package_coverage_map[path]
131
+ path = path[0...-1] unless path.empty?
132
+ return coverage unless coverage.nil?
133
+ end
134
+ nil
85
135
  end
86
136
 
87
137
  # it returns an emoji for coverage status
@@ -116,7 +166,14 @@ module Danger
116
166
  branch_counter = counters.detect { |e| e.type.eql? 'BRANCH' }
117
167
  line_counter = counters.detect { |e| e.type.eql? 'LINE' }
118
168
  counter = branch_counter.nil? ? line_counter : branch_counter
119
- raise "No coverage data found for #{jacoco_class.name}" if counter.nil?
169
+
170
+ if counter.nil?
171
+ no_coverage_data_found_message = "No coverage data found for #{jacoco_class.name}"
172
+
173
+ raise no_coverage_data_found_message if @fail_no_coverage_data_found.instance_of?(TrueClass)
174
+
175
+ warn no_coverage_data_found_message
176
+ end
120
177
 
121
178
  counter
122
179
  end
@@ -135,11 +192,12 @@ module Danger
135
192
  end
136
193
  # rubocop:enable Style/SignalException
137
194
 
138
- def markdown_class(parser, report_markdown)
195
+ def markdown_class(parser, report_markdown, report_url)
139
196
  class_coverage_above_minimum = true
140
197
  parser.classes.each do |jacoco_class| # Check metrics for each classes
141
198
  rp = report_class(jacoco_class)
142
- ln = "| `#{jacoco_class.name}` | #{rp[:covered]}% | #{rp[:required_coverage_percentage]}% | #{rp[:status]} |\n"
199
+ rl = report_link(jacoco_class.name, report_url)
200
+ ln = "| #{rl} | #{rp[:covered]}% | #{rp[:required_coverage_percentage]}% | #{rp[:status]} |\n"
143
201
  report_markdown << ln
144
202
 
145
203
  class_coverage_above_minimum &&= rp[:covered] >= rp[:required_coverage_percentage]
@@ -147,5 +205,14 @@ module Danger
147
205
 
148
206
  class_coverage_above_minimum
149
207
  end
208
+
209
+ def report_link(class_name, report_url)
210
+ if report_url.empty?
211
+ "`#{class_name}`"
212
+ else
213
+ report_filepath = "#{class_name.gsub(%r{/(?=[^/]*/.)}, '.')}.html"
214
+ "[`#{class_name}`](#{report_url + report_filepath})"
215
+ end
216
+ end
150
217
  end
151
218
  end
@@ -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
- if @class_names.include?(Hash[attrs]['name'])
42
- c = Jacoco::Class.new
43
- c.name = Hash[attrs]['name']
44
- c.counters = []
45
- @current_class = c
46
- @classes.push c
47
- elsif @current_class.nil?
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
@@ -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="&lt;init&gt;" 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,16 +1,21 @@
1
- require File.expand_path("../spec_helper", __FILE__)
1
+ # frozen_string_literal: true
2
2
 
3
- module Danger
3
+ # rubocop:disable Layout/LineLength
4
+ # rubocop:disable Metrics/ModuleLength
5
+ # rubocop:disable Metrics/BlockLength
6
+
7
+ require File.expand_path('spec_helper', __dir__)
4
8
 
9
+ module Danger
5
10
  describe Danger::DangerJacoco do
6
- it "should be a plugin" do
11
+ it 'should be a plugin' do
7
12
  expect(Danger::DangerJacoco.new(nil)).to be_a Danger::Plugin
8
13
  end
9
14
 
10
15
  #
11
16
  # You should test your custom attributes and methods here
12
17
  #
13
- describe "with Dangerfile" do
18
+ describe 'with Dangerfile' do
14
19
  before do
15
20
  @dangerfile = testing_dangerfile
16
21
  @my_plugin = @dangerfile.jacoco
@@ -20,27 +25,154 @@ module Danger
20
25
 
21
26
  allow(@dangerfile.git).to receive(:modified_files).and_return(modified_files)
22
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
23
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: |')
24
44
  end
25
45
 
46
+ it 'test regex class coverage' do
47
+ path_a = "#{File.dirname(__FILE__)}/fixtures/output_a.xml"
26
48
 
27
- it :report do
49
+ @my_plugin.minimum_project_coverage_percentage = 50
50
+ @my_plugin.minimum_class_coverage_map = { '.*Repository' => 60 }
51
+
52
+ @my_plugin.report path_a
53
+
54
+ expect(@dangerfile.status_report[:markdowns][0].message).to include('| `com/example/CachedRepository` | 50% | 60% | :warning: |')
55
+ end
56
+
57
+ it 'test with 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 = { 'com/example/' => 70 }
62
+
63
+ @my_plugin.report path_a
64
+
65
+ expect(@dangerfile.status_report[:markdowns][0].message).to include('| `com/example/CachedRepository` | 50% | 70% | :warning: |')
66
+ end
67
+
68
+ it 'test with bigger overlapped package coverage' do
69
+ path_a = "#{File.dirname(__FILE__)}/fixtures/output_a.xml"
70
+
71
+ @my_plugin.minimum_project_coverage_percentage = 50
72
+ @my_plugin.minimum_package_coverage_map = {
73
+ 'com/example/' => 70,
74
+ 'com/' => 90
75
+ }
76
+
77
+ @my_plugin.report path_a
78
+
79
+ expect(@dangerfile.status_report[:markdowns][0].message).to include('| `com/example/CachedRepository` | 50% | 70% | :warning: |')
80
+ end
81
+
82
+ it 'test with lower overlapped package coverage' do
83
+ path_a = "#{File.dirname(__FILE__)}/fixtures/output_a.xml"
84
+
85
+ @my_plugin.minimum_project_coverage_percentage = 50
86
+ @my_plugin.minimum_package_coverage_map = {
87
+ 'com/example/' => 77,
88
+ 'com/' => 30
89
+ }
90
+
91
+ @my_plugin.report path_a
92
+
93
+ expect(@dangerfile.status_report[:markdowns][0].message).to include('| `com/example/CachedRepository` | 50% | 77% | :warning: |')
94
+ end
95
+
96
+ it 'test with overlapped package coverage and bigger class coverage' do
97
+ path_a = "#{File.dirname(__FILE__)}/fixtures/output_a.xml"
98
+
99
+ @my_plugin.minimum_project_coverage_percentage = 50
100
+ @my_plugin.minimum_package_coverage_map = {
101
+ 'com/example/' => 77,
102
+ 'com/' => 30
103
+ }
104
+ @my_plugin.minimum_class_coverage_map = { 'com/example/CachedRepository' => 100 }
105
+
106
+ @my_plugin.report path_a
107
+
108
+ expect(@dangerfile.status_report[:markdowns][0].message).to include('| `com/example/CachedRepository` | 50% | 100% | :warning: |')
109
+ end
110
+
111
+ it 'test with overlapped package coverage and lowwer class coverage' do
28
112
  path_a = "#{File.dirname(__FILE__)}/fixtures/output_a.xml"
29
113
 
30
114
  @my_plugin.minimum_project_coverage_percentage = 50
31
- @my_plugin.minimum_class_coverage_map = { "com/example/CachedRepository" => 100}
115
+ @my_plugin.minimum_package_coverage_map = {
116
+ 'com/example/' => 90,
117
+ 'com/' => 85
118
+ }
119
+ @my_plugin.minimum_class_coverage_map = { 'com/example/CachedRepository' => 80 }
32
120
 
33
121
  @my_plugin.report path_a
34
122
 
35
- expect(@dangerfile.status_report[:errors]).to eq(["Total coverage of 32.9%. Improve this to at least 50%",
36
- "Class coverage is below minimum. Improve to at least 0%"])
37
- expect(@dangerfile.status_report[:markdowns][0].message).to include("### JaCoCO Code Coverage 32.9% :warning:")
38
- expect(@dangerfile.status_report[:markdowns][0].message).to include("| Class | Covered | Meta | Status |")
39
- expect(@dangerfile.status_report[:markdowns][0].message).to include("|:---:|:---:|:---:|:---:|")
40
- expect(@dangerfile.status_report[:markdowns][0].message).to include("| `com/example/CachedRepository` | 50% | 100% | :warning: |")
123
+ expect(@dangerfile.status_report[:markdowns][0].message).to include('| `com/example/CachedRepository` | 50% | 80% | :warning: |')
124
+ end
125
+
126
+ it 'adds a link to report' 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
+ @my_plugin.report(path_a, 'http://test.com/')
41
133
 
134
+ expect(@dangerfile.status_report[:markdowns][0].message).to include('| [`com/example/CachedRepository`](http://test.com/com.example/CachedRepository.html) | 50% | 80% | :warning: |')
42
135
  end
43
136
 
137
+ it 'When option "fail_no_coverage_data_found" is set to optionally fail, it doesn\'t fail the execution' do
138
+ path_a = "#{File.dirname(__FILE__)}/fixtures/output_a.xml"
139
+
140
+ @my_plugin.minimum_class_coverage_percentage = 80
141
+ @my_plugin.minimum_project_coverage_percentage = 50
142
+
143
+ expect { @my_plugin.report(path_a, fail_no_coverage_data_found: true) }.to_not raise_error(RuntimeError)
144
+ end
145
+
146
+ it 'When option "fail_no_coverage_data_found" is not set, the execution fails on empty data' do
147
+ path_a = "#{File.dirname(__FILE__)}/fixtures/output_b.xml"
148
+
149
+ @my_plugin.minimum_class_coverage_percentage = 80
150
+ @my_plugin.minimum_project_coverage_percentage = 50
151
+
152
+ expect { @my_plugin.report path_a }.to raise_error(RuntimeError)
153
+ end
154
+
155
+ it 'When option "fail_no_coverage_data_found" is set to optionally fail, the execution fails on empty data' do
156
+ path_a = "#{File.dirname(__FILE__)}/fixtures/output_b.xml"
157
+
158
+ @my_plugin.minimum_class_coverage_percentage = 80
159
+ @my_plugin.minimum_project_coverage_percentage = 50
160
+
161
+ expect { @my_plugin.report path_a, fail_no_coverage_data_found: true }.to raise_error(RuntimeError)
162
+ end
163
+
164
+ it 'When option "fail_no_coverage_data_found" is set to optionally warn (not fail), the execution doesn\'t fail on empty data' do
165
+ path_a = "#{File.dirname(__FILE__)}/fixtures/output_b.xml"
166
+
167
+ @my_plugin.minimum_class_coverage_percentage = 80
168
+ @my_plugin.minimum_project_coverage_percentage = 50
169
+
170
+ expect { @my_plugin.report path_a, fail_no_coverage_data_found: false }.to_not raise_error(RuntimeError)
171
+ end
44
172
  end
45
173
  end
46
174
  end
175
+
176
+ # rubocop:enable Layout/LineLength
177
+ # rubocop:enable Metrics/ModuleLength
178
+ # 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('../../', __FILE__))
3
- $LOAD_PATH.unshift((ROOT + 'lib').to_s)
4
- $LOAD_PATH.unshift((ROOT + 'spec').to_s)
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.3
4
+ version: 0.1.8
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: 2018-10-26 00:00:00.000000000 Z
11
+ date: 2021-06-29 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: '1.16'
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: '1.16'
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: '12.3'
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: '12.3'
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: '0.51'
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: '0.51'
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.5
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.5
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: '0'
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
- rubyforge_project:
221
- rubygems_version: 2.6.13
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
data/.travis.yml DELETED
@@ -1,12 +0,0 @@
1
- language: ruby
2
- cache:
3
- directories:
4
- - bundle
5
-
6
- rvm:
7
- - 2.0
8
- - 2.1.3
9
- - 2.3.1
10
-
11
- script:
12
- - bundle exec rake spec