simplecov-phpunit 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 749ad3dd4db01d6def1fc51ce5d53f82b03bddd4
4
+ data.tar.gz: 81f70e121994b16da0562780bc2e0ee77c940a23
5
+ SHA512:
6
+ metadata.gz: 2e8ee94c7c0c3e8e4e215736f24c8d0f2077f45edc1e5503611e7bddcd725b586202ff3279d34f573645c5d09a9337f7ae33fb93e5d29edacf75610b1469d4d4
7
+ data.tar.gz: a4b4ea6474ca353489d4e11d0198d5354f5a030c01fccb80d8c5fc85c5641ba58df51e9231e02123f25ad237cd9e9972c3505c48eb75a24f2987874e146e7cd5
data/.editorconfig ADDED
@@ -0,0 +1,14 @@
1
+ # editorconfig.org
2
+
3
+ root = true
4
+
5
+ [*]
6
+ indent_style = tab
7
+ indent_size = 4
8
+ end_of_line = lf
9
+ charset = utf-8
10
+ trim_trailing_whitespace = false
11
+ insert_final_newline = true
12
+
13
+ [*.yml]
14
+ indent_style = space
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ /.bundle/
2
+ .setup
3
+ Gemfile.lock
4
+ /releases/
5
+ *.html
data/.travis.yml ADDED
@@ -0,0 +1,23 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0
4
+ - 2.1
5
+ - 2.2
6
+ - 2.3
7
+ - 2.4.0-preview1
8
+ - ruby-head
9
+ - jruby-9.0
10
+ - jruby-head
11
+ - rbx-2
12
+ sudo: required
13
+ before_install:
14
+ - gem update --system
15
+ - gem install bundler -v '~>1.11'
16
+ - bundler --version
17
+ install:
18
+ - make
19
+ - gem build simplecov-phpunit.gemspec
20
+ - gem install simplecov-phpunit-*.gem
21
+ - gem list -l simplecov-phpunit
22
+ script:
23
+ - make test
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+
2
+ source 'https://rubygems.org'
3
+ gemspec
data/Makefile ADDED
@@ -0,0 +1,8 @@
1
+
2
+ GEM_NAME = simplecov-phpunit
3
+
4
+ include Makefile.common
5
+
6
+ .PHONY: test
7
+ test:
8
+ RUBYOPT=-w $(BUNDLER) exec ./test/suite_all.rb -v
data/Makefile.common ADDED
@@ -0,0 +1,56 @@
1
+
2
+ # Ruby Common Big
3
+ # 2016-05-20
4
+
5
+ MV = mv -nv
6
+ RM = rm -rfd
7
+ MKDIR = mkdir -p
8
+ CHMOD = chmod
9
+ BUNDLER = bundle
10
+ BUNDLER_OPTIONS = --jobs=5 --retry=3
11
+ GEMSPEC_FILE = $(GEM_NAME).gemspec
12
+
13
+ .PHONY: all
14
+ all: setup $(ALL_TARGETS_EXT)
15
+
16
+ .PHONY: setup
17
+ setup: .setup
18
+
19
+ .setup:
20
+ $(BUNDLER) install $(BUNDLER_OPTIONS)
21
+ touch $@
22
+
23
+ .PHONY: install
24
+ install:
25
+ gem_file=$$(gem build $(GEMSPEC_FILE) | grep 'File:' | tail -1 | awk '{ print $$2 }'); \
26
+ sudo gem install $$gem_file; \
27
+ $(RM) $$gem_file
28
+
29
+ .PHONY: uninstall
30
+ uninstall:
31
+ sudo gem uninstall $(GEM_NAME)
32
+
33
+ .PHONY: update
34
+ update:
35
+ $(BUNDLER) update
36
+
37
+ .PHONY: clean
38
+ clean:
39
+ $(RM) .bundle .setup Gemfile.lock
40
+
41
+ .PHONY: release
42
+ release: | releases
43
+ set -e; \
44
+ gem_file=$$(gem build $(GEMSPEC_FILE) | grep 'File:' | tail -1 | awk '{ print $$2 }'); \
45
+ dst="releases/$$gem_file"; \
46
+ [ ! -f $$dst ]; \
47
+ $(MV) $$gem_file releases; \
48
+ gem push $$dst; \
49
+ echo 'done'
50
+
51
+ releases:
52
+ $(MKDIR) $@
53
+
54
+ tmp:
55
+ $(MKDIR) $@
56
+ $(CHMOD) u=rwx,go-rwx $@
data/README.md ADDED
@@ -0,0 +1,47 @@
1
+ # SimpleCov PHPUnit Formatter
2
+
3
+ PHPUnit-like HTML Formatter for SimpleCov.
4
+
5
+ This [SimpleCov](https://www.ruby-toolbox.com/projects/simplecov)-plugin generates a coverage report (`coverage/index.html`) done like by [PHPUnit](https://phpunit.de/) ([PHP_CodeCoverage](https://github.com/sebastianbergmann/php-code-coverage)). Each Ruby source file get its own HTML page.
6
+
7
+ ## Install
8
+
9
+ The preferred method of installation is via RubyGems.org:
10
+ https://rubygems.org/gems/simplecov-phpunit
11
+
12
+ gem install simplecov-phpunit
13
+
14
+ or via `Gemfile`:
15
+
16
+ gem 'simplecov-phpunit', '~>0.1'
17
+
18
+ or via `.gemspec`:
19
+
20
+ spec.add_development_dependency 'simplecov', '~>0.12'
21
+ spec.add_development_dependency 'simplecov-phpunit', '~>0.1'
22
+
23
+ ## Usage
24
+
25
+ require 'simplecov'
26
+ require 'simplecov-phpunit'
27
+
28
+ SimpleCov.formatter = SimpleCov::Formatter::PHPUnit
29
+ SimpleCov.start
30
+
31
+ ## Project Links
32
+
33
+ - [Gem](https://rubygems.org/gems/simplecov-phpunit)
34
+ - [Travis CI Repository](https://travis-ci.org/TheFox/simplecov-phpunit)
35
+
36
+ ## Weblinks
37
+
38
+ - [SimpleCov](https://www.ruby-toolbox.com/projects/simplecov) ([GitHub](https://github.com/colszowka/simplecov))
39
+ - [PHPUnit](https://phpunit.de/)
40
+
41
+ ## License
42
+
43
+ Copyright (C) 2016 Christian Mayer <https://fox21.at>
44
+
45
+ This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
46
+
47
+ This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
@@ -0,0 +1,266 @@
1
+
2
+ require 'simplecov'
3
+
4
+ module SimpleCov
5
+ module Formatter
6
+
7
+ class PHPUnit < SimpleCov::Formatter::SimpleFormatter
8
+
9
+ def initialize()
10
+ super()
11
+
12
+ @base_dir_path = Dir.pwd
13
+ @coverage_dir_path = "#{@base_dir_path}/coverage"
14
+ @index_html_file = File.open("#{@coverage_dir_path}/index.html", 'wb')
15
+
16
+ @version_html = %{<a href="https://github.com/TheFox/simplecov-phpunit">SimpleCov PHPUnit Formatter #{PHPUnitFormatter::VERSION}</a>}
17
+ @ruby_version_html = %{<a href="https://www.ruby-lang.org/en/">Ruby #{RUBY_VERSION}</a>}
18
+
19
+ simplecov_version = Gem.latest_spec_for('simplecov').version.to_s
20
+ @simplecov_version_html = %{<a href="https://github.com/colszowka/simplecov">SimpleCov #{simplecov_version}</a>}
21
+ end
22
+
23
+ def format(result)
24
+ puts "write coverage for '#{@base_dir_path}'"
25
+
26
+ total_status = status_by_percent(result.files.covered_percent)
27
+ total_percent_f = '%.2f' % result.files.covered_percent
28
+
29
+ @index_html_file.write(%{<!DOCTYPE html>
30
+ <html lang="en">
31
+ <head>
32
+ <meta charset="UTF-8" />
33
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
34
+
35
+ <title>Code Coverage for #{@base_dir_path}</title>
36
+
37
+ <link href="_assets/css/bootstrap.min.css" rel="stylesheet">
38
+ <link href="_assets/css/style.css" rel="stylesheet">
39
+
40
+ <!--[if lt IE 9]>
41
+ <script src="_assets/js/html5shiv.min.js"></script>
42
+ <script src="_assets/js/respond.min.js"></script>
43
+ <![endif]-->
44
+ </head>
45
+ <div class="container">
46
+ <table class="table table-bordered">
47
+ <thead>
48
+ <tr>
49
+ <td>&nbsp;</td>
50
+ <td colspan="3"><div align="center"><strong>Code Coverage</strong></div></td>
51
+ </tr>
52
+ <tr>
53
+ <td>&nbsp;</td>
54
+ <td colspan="3"><div align="center"><strong>Lines</strong></div></td>
55
+ </tr>
56
+ </thead>
57
+ <tr>
58
+ <td class="#{total_status}">Total</td>
59
+ <td class="#{total_status} big">
60
+ <div class="progress">
61
+ <div class="progress-bar progress-bar-#{total_status}" role="progressbar" aria-valuenow="#{total_percent_f}" aria-valuemin="0" aria-valuemax="100" style="width: #{total_percent_f}%">
62
+ <span class="sr-only">#{total_percent_f}% covered (#{total_status})</span>
63
+ </div>
64
+ </div>
65
+ </td>
66
+ <td class="#{total_status} small"><div align="right">#{total_percent_f}%</div></td>
67
+ <td class="#{total_status} small"><div align="right">#{result.files.covered_lines}&nbsp;/&nbsp;#{result.files.lines_of_code}</div></td>
68
+ </tr>
69
+ })
70
+
71
+ result.files.each do |file|
72
+ relative_file_path = file.filename[@base_dir_path.size.next..-1]
73
+ # file_name = File.basename(file.filename)
74
+ html_file_path = relative_file_path
75
+ .split('/')
76
+ .join('_') + '.html'
77
+
78
+ puts "write coverage '#{relative_file_path}'"
79
+
80
+ file_status = status_by_percent(file.covered_percent)
81
+ file_percent_f = '%.2f' % file.covered_percent
82
+
83
+ @index_html_file.write(%{
84
+
85
+ <tr>
86
+ <td class="#{file_status}"><span class="glyphicon glyphicon-file"></span> <a href="#{html_file_path}">#{relative_file_path}</a></td>
87
+ <td class="#{file_status} big">
88
+ <div class="progress">
89
+ <div class="progress-bar progress-bar-#{file_status}" role="progressbar" aria-valuenow="100.00" aria-valuemin="0" aria-valuemax="100" style="width: #{file_percent_f}%">
90
+ <span class="sr-only">#{file_percent_f}% covered (#{file_status})</span>
91
+ </div>
92
+ </div>
93
+ </td>
94
+ <td class="#{file_status} small"><div align="right">#{file_percent_f}%</div></td>
95
+ <td class="#{file_status} small"><div align="right">#{file.covered_lines.count}&nbsp;/&nbsp;#{file.lines_of_code}</div></td>
96
+ </tr>
97
+
98
+ })
99
+
100
+ @html_file = File.open("#{@coverage_dir_path}/#{html_file_path}", 'wb')
101
+ @html_file.write(%{<!DOCTYPE html>
102
+ <html lang="en">
103
+ <head>
104
+ <meta charset="UTF-8" />
105
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
106
+
107
+ <title>Code Coverage for #{file.filename}</title>
108
+
109
+ <link href="_assets/css/bootstrap.min.css" rel="stylesheet">
110
+ <link href="_assets/css/style.css" rel="stylesheet">
111
+
112
+ <!--[if lt IE 9]>
113
+ <script src="_assets/js/html5shiv.min.js"></script>
114
+ <script src="_assets/js/respond.min.js"></script>
115
+ <![endif]-->
116
+ </head>
117
+ <body>
118
+ <header>
119
+ <div class="container">
120
+ <div class="row">
121
+ <div class="col-md-12">
122
+ <ol class="breadcrumb">
123
+ <li><a href="index.html">#{@base_dir_path}</a></li>
124
+ <li class="active">#{relative_file_path}</li>
125
+ </ol>
126
+ </div>
127
+ </div>
128
+ </div>
129
+ </header>
130
+ <div class="container">
131
+ <table class="table table-bordered">
132
+ <thead>
133
+ <tr>
134
+ <td>&nbsp;</td>
135
+ <td colspan="3"><div align="center"><strong>Code Coverage</strong></div></td>
136
+ </tr>
137
+ <tr>
138
+ <td>&nbsp;</td>
139
+ <td colspan="3"><div align="center"><strong>Lines</strong></div></td>
140
+ </tr>
141
+ </thead>
142
+ <tbody>
143
+ <tr>
144
+ <td class="#{file_status}">Total</td>
145
+ <td class="#{file_status} big">
146
+ <div class="progress">
147
+ <div class="progress-bar progress-bar-#{file_status}" role="progressbar" aria-valuenow="#{file_percent_f}" aria-valuemin="0" aria-valuemax="100" style="width: #{file_percent_f}%">
148
+ <span class="sr-only">#{file_percent_f}% covered (#{file_status})</span>
149
+ </div>
150
+ </div>
151
+ </td>
152
+ <td class="#{file_status} small"><div align="right">#{file_percent_f}%</div></td>
153
+ <td class="#{file_status} small"><div align="right">#{file.covered_lines.count}&nbsp;/&nbsp;#{file.lines_of_code}</div></td>
154
+ </tr>
155
+ </tbody>
156
+ </table>
157
+ <table id="code" class="table table-borderless table-condensed">
158
+ <tbody>
159
+ })
160
+
161
+ file.lines.each do |line|
162
+ # puts " line #{line.line_number} #{line.coverage} #{line.status} #{line.src}"
163
+
164
+ if line.covered?
165
+ @html_file.write(%{<tr class="covered-by-large-tests"><td><div align="right"><a name="#{line.line_number}"></a><a href="##{line.line_number}">#{line.line_number}</a></div></td><td class="codeLine"><span class="default">#{line.src}</span></td></tr>})
166
+ elsif line.missed?
167
+ @html_file.write(%{<tr class="danger"><td><div align="right"><a name="#{line.line_number}"></a><a href="##{line.line_number}">#{line.line_number}</a></div></td><td class="codeLine"><span class="default">#{line.src}</span></td></tr>})
168
+ elsif line.skipped?
169
+ @html_file.write(%{<tr class="warning"><td><div align="right"><a name="#{line.line_number}"></a><a href="##{line.line_number}">#{line.line_number}</a></div></td><td class="codeLine"><span class="default">#{line.src}</span></td></tr>})
170
+ else
171
+ @html_file.write(%{<tr><td><div align="right"><a name="#{line.line_number}"></a><a href="##{line.line_number}">#{line.line_number}</a></div></td><td class="codeLine"><span class="default">#{line.src}</span></td></tr>})
172
+ end
173
+
174
+ end
175
+
176
+ @html_file.write(%{
177
+ </tbody>
178
+ </table>
179
+ <footer>
180
+ <hr/>
181
+ <h4>Legend</h4>
182
+ <p>
183
+ <span class="success"><strong>Executed</strong></span>
184
+ <span class="danger"><strong>Not Executed</strong></span>
185
+ <span class="warning"><strong>Skipped Code</strong></span>
186
+ </p>
187
+ <p>
188
+ <small>Generated by #{@version_html} using #{@ruby_version_html} and #{@simplecov_version_html} at #{result.created_at.strftime('%F %T %z')}.</small>
189
+ </p>
190
+ </footer>
191
+ </div>
192
+
193
+ <script src="_assets/js/jquery.min.js" type="text/javascript"></script>
194
+ <script src="_assets/js/bootstrap.min.js" type="text/javascript"></script>
195
+ <script src="_assets/js/holder.min.js" type="text/javascript"></script>
196
+ <script type="text/javascript">
197
+ $(function(){
198
+ var $window = $(window)
199
+ , $top_link = $('#toplink')
200
+ , $body = $('body, html')
201
+ , offset = $('#code').offset().top;
202
+
203
+ $top_link.hide().click(function(event){
204
+ event.preventDefault();
205
+ $body.animate({scrollTop:0}, 800);
206
+ });
207
+
208
+ $window.scroll(function(){
209
+ if($window.scrollTop() > offset){
210
+ $top_link.fadeIn();
211
+ }
212
+ else{
213
+ $top_link.fadeOut();
214
+ }
215
+ }).scroll();
216
+
217
+ $('.popin').popover({trigger: 'hover'});
218
+ });
219
+ </script>
220
+ </body>
221
+ </html>
222
+ })
223
+
224
+ @html_file.close
225
+ end
226
+
227
+ @index_html_file.write(%{
228
+ </table>
229
+ <footer>
230
+ <hr/>
231
+ <h4>Legend</h4>
232
+ <p>
233
+ <span class="danger"><strong>Low</strong>: 0% to 49%</span>
234
+ <span class="warning"><strong>Medium</strong>: 50% to 89%</span>
235
+ <span class="success"><strong>High</strong>: 90% to 100%</span>
236
+ </p>
237
+ <p>
238
+ <small>Generated by #{@version_html} using #{@ruby_version_html} and #{@simplecov_version_html} at #{result.created_at.strftime('%F %T %z')}.</small>
239
+ </p>
240
+ </footer>
241
+ </div>
242
+ <script src="_assets/js/jquery.min.js" type="text/javascript"></script>
243
+ <script src="_assets/js/bootstrap.min.js" type="text/javascript"></script>
244
+ <script src="_assets/js/holder.min.js" type="text/javascript"></script>
245
+ </html>
246
+ })
247
+
248
+ @index_html_file.close
249
+ end
250
+
251
+ private
252
+
253
+ def status_by_percent(percent)
254
+ if percent >= 50.0 && percent < 90.0
255
+ 'warning'
256
+ elsif percent >= 90.0
257
+ 'success'
258
+ else
259
+ 'danger'
260
+ end
261
+ end
262
+
263
+ end
264
+
265
+ end
266
+ end
@@ -0,0 +1,14 @@
1
+
2
+ module SimpleCov
3
+ module Formatter
4
+
5
+ module PHPUnitFormatter
6
+
7
+ VERSION = '0.1.0'
8
+ DATE = '2016-09-13'
9
+ HOMEPAGE = 'https://github.com/TheFox/simplecov-phpunit'
10
+
11
+ end
12
+
13
+ end
14
+ end
@@ -0,0 +1,3 @@
1
+
2
+ require 'simplecov-phpunit/version'
3
+ require 'simplecov-phpunit/simplecov-phpunit'
@@ -0,0 +1,26 @@
1
+ # coding: UTF-8
2
+
3
+ lib = File.expand_path('../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+
6
+ require 'simplecov-phpunit/version'
7
+
8
+ Gem::Specification.new do |spec|
9
+ spec.name = 'simplecov-phpunit'
10
+ spec.version = SimpleCov::Formatter::PHPUnitFormatter::VERSION
11
+ spec.date = SimpleCov::Formatter::PHPUnitFormatter::DATE
12
+ spec.author = 'Christian Mayer'
13
+ spec.email = 'christian@fox21.at'
14
+
15
+ spec.summary = %q{SimpleCov PHPUnit Formatter}
16
+ spec.description = %q{PHPUnit-like HTML Formatter for SimpleCov.}
17
+ spec.homepage = SimpleCov::Formatter::PHPUnitFormatter::HOMEPAGE
18
+ spec.license = 'GPL-3.0'
19
+
20
+ spec.files = `git ls-files -z`.split("\x0").reject{ |f| f.match(%r{^(test|spec|features)/}) }
21
+ spec.require_paths = ['lib']
22
+ spec.required_ruby_version = '>=2.0.0'
23
+
24
+ spec.add_development_dependency 'minitest', '~>5.8'
25
+ spec.add_development_dependency 'simplecov', '~>0.12'
26
+ end
@@ -0,0 +1,10 @@
1
+ {
2
+ "folders":[
3
+ {
4
+ "path": ".",
5
+ "name": "SimpleCov PHPUnit",
6
+ "folder_exclude_patterns": [ ],
7
+ "file_exclude_patterns": [ ]
8
+ }
9
+ ]
10
+ }
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: simplecov-phpunit
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Christian Mayer
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-09-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: minitest
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '5.8'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '5.8'
27
+ - !ruby/object:Gem::Dependency
28
+ name: simplecov
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.12'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.12'
41
+ description: PHPUnit-like HTML Formatter for SimpleCov.
42
+ email: christian@fox21.at
43
+ executables: []
44
+ extensions: []
45
+ extra_rdoc_files: []
46
+ files:
47
+ - ".editorconfig"
48
+ - ".gitignore"
49
+ - ".travis.yml"
50
+ - Gemfile
51
+ - Makefile
52
+ - Makefile.common
53
+ - README.md
54
+ - lib/simplecov-phpunit.rb
55
+ - lib/simplecov-phpunit/simplecov-phpunit.rb
56
+ - lib/simplecov-phpunit/version.rb
57
+ - simplecov-phpunit.gemspec
58
+ - simplecov-phpunit.sublime-project
59
+ homepage: https://github.com/TheFox/simplecov-phpunit
60
+ licenses:
61
+ - GPL-3.0
62
+ metadata: {}
63
+ post_install_message:
64
+ rdoc_options: []
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: 2.0.0
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ requirements: []
78
+ rubyforge_project:
79
+ rubygems_version: 2.5.1
80
+ signing_key:
81
+ specification_version: 4
82
+ summary: SimpleCov PHPUnit Formatter
83
+ test_files: []