simplecov 0.18.5 → 0.22.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 +4 -4
- data/CHANGELOG.md +93 -520
- data/README.md +131 -36
- data/doc/alternate-formatters.md +12 -2
- data/doc/commercial-services.md +5 -0
- data/lib/minitest/simplecov_plugin.rb +1 -1
- data/lib/simplecov/configuration.rb +110 -16
- data/lib/simplecov/default_formatter.rb +20 -0
- data/lib/simplecov/defaults.rb +11 -8
- data/lib/simplecov/exit_codes/exit_code_handling.rb +29 -0
- data/lib/simplecov/exit_codes/maximum_coverage_drop_check.rb +83 -0
- data/lib/simplecov/exit_codes/minimum_coverage_by_file_check.rb +54 -0
- data/lib/simplecov/exit_codes/minimum_overall_coverage_check.rb +53 -0
- data/lib/simplecov/exit_codes.rb +5 -0
- data/lib/simplecov/file_list.rb +12 -6
- data/lib/simplecov/filter.rb +7 -5
- data/lib/simplecov/formatter/multi_formatter.rb +5 -7
- data/lib/simplecov/formatter.rb +2 -2
- data/lib/simplecov/lines_classifier.rb +3 -3
- data/lib/simplecov/no_defaults.rb +1 -1
- data/lib/simplecov/process.rb +19 -0
- data/lib/simplecov/result.rb +8 -35
- data/lib/simplecov/result_merger.rb +121 -57
- data/lib/simplecov/source_file/line.rb +1 -1
- data/lib/simplecov/source_file.rb +9 -3
- data/lib/simplecov/useless_results_remover.rb +5 -3
- data/lib/simplecov/version.rb +1 -1
- data/lib/simplecov.rb +130 -139
- metadata +34 -15
- data/CODE_OF_CONDUCT.md +0 -76
- data/CONTRIBUTING.md +0 -51
- data/ISSUE_TEMPLATE.md +0 -23
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
SimpleCov [](https://badge.fury.io/rb/simplecov) [](https://badge.fury.io/rb/simplecov) [][Continuous Integration] [](https://codeclimate.com/github/simplecov-ruby/simplecov/maintainability) [](http://inch-ci.org/github/simplecov-ruby/simplecov)
|
2
2
|
=========
|
3
3
|
|
4
4
|
**Code coverage for Ruby**
|
@@ -10,14 +10,14 @@ SimpleCov [](https://badge
|
|
10
10
|
* [Continuous Integration]
|
11
11
|
|
12
12
|
[Coverage]: https://ruby-doc.org/stdlib/libdoc/coverage/rdoc/Coverage.html "API doc for Ruby's Coverage library"
|
13
|
-
[Source Code]: https://github.com/
|
13
|
+
[Source Code]: https://github.com/simplecov-ruby/simplecov "Source Code @ GitHub"
|
14
14
|
[API documentation]: http://rubydoc.info/gems/simplecov/frames "RDoc API Documentation at Rubydoc.info"
|
15
15
|
[Configuration]: http://rubydoc.info/gems/simplecov/SimpleCov/Configuration "Configuration options API documentation"
|
16
|
-
[Changelog]: https://github.com/
|
16
|
+
[Changelog]: https://github.com/simplecov-ruby/simplecov/blob/main/CHANGELOG.md "Project Changelog"
|
17
17
|
[Rubygem]: http://rubygems.org/gems/simplecov "SimpleCov @ rubygems.org"
|
18
|
-
[Continuous Integration]: https://github.com/
|
19
|
-
[Dependencies]: https://gemnasium.com/
|
20
|
-
[simplecov-html]: https://github.com/
|
18
|
+
[Continuous Integration]: https://github.com/simplecov-ruby/simplecov/actions?query=workflow%3Astable "SimpleCov is built around the clock by github.com"
|
19
|
+
[Dependencies]: https://gemnasium.com/simplecov-ruby/simplecov "SimpleCov dependencies on Gemnasium"
|
20
|
+
[simplecov-html]: https://github.com/simplecov-ruby/simplecov-html "SimpleCov HTML Formatter Source Code @ GitHub"
|
21
21
|
|
22
22
|
SimpleCov is a code coverage analysis tool for Ruby. It uses [Ruby's built-in Coverage][Coverage] library to gather code
|
23
23
|
coverage data, but makes processing its results much easier by providing a clean API to filter, group, merge, format,
|
@@ -37,8 +37,8 @@ configured automatically when you launch SimpleCov. If you're curious, you can f
|
|
37
37
|
|
38
38
|
*Code and Bug Reports*
|
39
39
|
|
40
|
-
* [Issue Tracker](https://github.com/
|
41
|
-
* See [CONTRIBUTING](https://github.com/
|
40
|
+
* [Issue Tracker](https://github.com/simplecov-ruby/simplecov/issues)
|
41
|
+
* See [CONTRIBUTING](https://github.com/simplecov-ruby/simplecov/blob/main/CONTRIBUTING.md) for how to contribute along
|
42
42
|
with some common problems to check out before creating an issue.
|
43
43
|
|
44
44
|
*Questions, Problems, Suggestions, etc.*
|
@@ -69,13 +69,16 @@ Getting started
|
|
69
69
|
The `SimpleCov.start` **must** be issued **before any of your application
|
70
70
|
code is required!**
|
71
71
|
|
72
|
+
This is especially true if you use anything that keeps your tests application loaded like spring, check out the **[spring section](#want-to-use-spring-with-simplecov)**.
|
73
|
+
|
72
74
|
SimpleCov must be running in the process that you want the code coverage
|
73
75
|
analysis to happen on. When testing a server process (e.g. a JSON API
|
74
76
|
endpoint) via a separate test process (e.g. when using Selenium) where you
|
75
77
|
want to see all code executed by the `rails server`, and not just code
|
76
|
-
executed in your actual test files, you
|
78
|
+
executed in your actual test files, you need to require SimpleCov in the
|
79
|
+
server process. For rails for instance, you'll want to add something like this
|
77
80
|
to the top of `bin/rails`, but below the "shebang" line (`#! /usr/bin/env
|
78
|
-
ruby`):
|
81
|
+
ruby`) and after config/boot is required:
|
79
82
|
|
80
83
|
```ruby
|
81
84
|
if ENV['RAILS_ENV'] == 'test'
|
@@ -104,10 +107,6 @@ Getting started
|
|
104
107
|
5. Add the following to your `.gitignore` file to ensure that coverage results
|
105
108
|
are not tracked by Git (optional):
|
106
109
|
|
107
|
-
```
|
108
|
-
echo "coverage" >> .gitignore
|
109
|
-
```
|
110
|
-
Or if you use Windows:
|
111
110
|
```
|
112
111
|
echo coverage >> .gitignore
|
113
112
|
```
|
@@ -167,8 +166,8 @@ to use SimpleCov with them. Here's an overview of the known ones:
|
|
167
166
|
race conditions occur when results are merged.
|
168
167
|
</td>
|
169
168
|
<td>
|
170
|
-
<a href="https://github.com/
|
171
|
-
<a href="https://github.com/
|
169
|
+
<a href="https://github.com/simplecov-ruby/simplecov/issues/64">#64</a> &
|
170
|
+
<a href="https://github.com/simplecov-ruby/simplecov/pull/185">#185</a>
|
172
171
|
</td>
|
173
172
|
</tr>
|
174
173
|
<tr>
|
@@ -192,7 +191,7 @@ to use SimpleCov with them. Here's an overview of the known ones:
|
|
192
191
|
to explicitly set the output root using `SimpleCov.root('foo/bar/baz')`
|
193
192
|
</td>
|
194
193
|
<td>
|
195
|
-
<a href="https://github.com/
|
194
|
+
<a href="https://github.com/simplecov-ruby/simplecov/issues/95">#95</a>
|
196
195
|
</td>
|
197
196
|
</tr>
|
198
197
|
<tr>
|
@@ -203,11 +202,11 @@ to use SimpleCov with them. Here's an overview of the known ones:
|
|
203
202
|
Because of how Spork works internally (using preforking), there used to
|
204
203
|
be trouble when using SimpleCov with it, but that has apparently been
|
205
204
|
resolved with a specific configuration strategy. See <a
|
206
|
-
href="https://github.com/
|
205
|
+
href="https://github.com/simplecov-ruby/simplecov/issues/42#issuecomment-4440284">this</a>
|
207
206
|
comment.
|
208
207
|
</td>
|
209
208
|
<td>
|
210
|
-
<a href="https://github.com/
|
209
|
+
<a href="https://github.com/simplecov-ruby/simplecov/issues/42#issuecomment-4440284">#42</a>
|
211
210
|
</td>
|
212
211
|
</tr>
|
213
212
|
<tr>
|
@@ -218,7 +217,7 @@ to use SimpleCov with them. Here's an overview of the known ones:
|
|
218
217
|
<a href="#want-to-use-spring-with-simplecov">See section below.</a>
|
219
218
|
</td>
|
220
219
|
<td>
|
221
|
-
<a href="https://github.com/
|
220
|
+
<a href="https://github.com/simplecov-ruby/simplecov/issues/381">#381</a>
|
222
221
|
</td>
|
223
222
|
</tr>
|
224
223
|
<tr>
|
@@ -231,7 +230,7 @@ to use SimpleCov with them. Here's an overview of the known ones:
|
|
231
230
|
(Dec 11th, 2011) should have this problem resolved.
|
232
231
|
</td>
|
233
232
|
<td>
|
234
|
-
<a href="https://github.com/
|
233
|
+
<a href="https://github.com/simplecov-ruby/simplecov/issues/45">#45</a> &
|
235
234
|
<a href="https://github.com/test-unit/test-unit/pull/12">test-unit/test-unit#12</a>
|
236
235
|
</td>
|
237
236
|
</tr>
|
@@ -294,7 +293,6 @@ information to be lost.
|
|
294
293
|
Add branch coverage measurement statistics to your results. Supported in CRuby versions 2.5+.
|
295
294
|
|
296
295
|
```ruby
|
297
|
-
# or in configure or just SimpleCov.enable_coverage :branch
|
298
296
|
SimpleCov.start do
|
299
297
|
enable_coverage :branch
|
300
298
|
end
|
@@ -340,6 +338,34 @@ Hence, we recommend looking at both metrics together. Branch coverage might also
|
|
340
338
|
overall metric to look at - while you might be missing only 10% of your lines that might
|
341
339
|
account for 50% of your branches for instance.
|
342
340
|
|
341
|
+
## Primary Coverage
|
342
|
+
|
343
|
+
By default, the primary coverage type is `line`. To set the primary coverage to something else, use the following:
|
344
|
+
|
345
|
+
```ruby
|
346
|
+
# or in configure SimpleCov.primary_coverage :branch
|
347
|
+
SimpleCov.start do
|
348
|
+
enable_coverage :branch
|
349
|
+
primary_coverage :branch
|
350
|
+
end
|
351
|
+
```
|
352
|
+
|
353
|
+
Primary coverage determines what will come in first all output, and the type of coverage to check if you don't specify the type of coverage when customizing exit behavior (`SimpleCov.minimum_coverage 90`).
|
354
|
+
|
355
|
+
Note that coverage must first be enabled for non-default coverage types.
|
356
|
+
|
357
|
+
## Coverage for eval
|
358
|
+
|
359
|
+
You can measure coverage for code that is evaluated by `Kernel#eval`. Supported in CRuby versions 3.2+.
|
360
|
+
|
361
|
+
```ruby
|
362
|
+
SimpleCov.start do
|
363
|
+
enable_coverage_for_eval
|
364
|
+
end
|
365
|
+
```
|
366
|
+
|
367
|
+
This is typically useful for ERB. Set `ERB#filename=` to make it possible for SimpleCov to trace the original .erb source file.
|
368
|
+
|
343
369
|
## Filters
|
344
370
|
|
345
371
|
Filters can be used to remove selected files from your coverage data. By default, a filter is applied that removes all
|
@@ -429,7 +455,7 @@ end
|
|
429
455
|
# :nocov:
|
430
456
|
```
|
431
457
|
|
432
|
-
The name of the token can be changed to your liking. [Learn more about the nocov feature.]( https://github.com/
|
458
|
+
The name of the token can be changed to your liking. [Learn more about the nocov feature.]( https://github.com/simplecov-ruby/simplecov/blob/main/features/config_nocov_token.feature)
|
433
459
|
|
434
460
|
**Note:** You shouldn't have to use the nocov token to skip private methods that are being included in your coverage. If
|
435
461
|
you appropriately test the public interface of your classes and objects you should automatically get full coverage of
|
@@ -440,7 +466,7 @@ your private methods.
|
|
440
466
|
By default, SimpleCov filters everything outside of the `SimpleCov.root` directory. However, sometimes you may want
|
441
467
|
to include coverage reports for things you include as a gem, for example a Rails Engine.
|
442
468
|
|
443
|
-
Here's an example by [@lsaffie](https://github.com/lsaffie) from [#221](https://github.com/
|
469
|
+
Here's an example by [@lsaffie](https://github.com/lsaffie) from [#221](https://github.com/simplecov-ruby/simplecov/issues/221)
|
444
470
|
that shows how you can achieve just that:
|
445
471
|
|
446
472
|
```ruby
|
@@ -614,6 +640,53 @@ namespace :coverage do
|
|
614
640
|
end
|
615
641
|
```
|
616
642
|
|
643
|
+
## Running simplecov against subprocesses
|
644
|
+
|
645
|
+
`SimpleCov.enable_for_subprocesses` will allow SimpleCov to observe subprocesses starting using `Process.fork`.
|
646
|
+
This modifies ruby's core Process.fork method so that SimpleCov can see into it, appending `" (subprocess #{pid})"`
|
647
|
+
to the `SimpleCov.command_name`, with results that can be merged together using SimpleCov's merging feature.
|
648
|
+
|
649
|
+
To configure this, use `.at_fork`.
|
650
|
+
|
651
|
+
```ruby
|
652
|
+
SimpleCov.enable_for_subprocesses true
|
653
|
+
SimpleCov.at_fork do |pid|
|
654
|
+
# This needs a unique name so it won't be ovewritten
|
655
|
+
SimpleCov.command_name "#{SimpleCov.command_name} (subprocess: #{pid})"
|
656
|
+
# be quiet, the parent process will be in charge of output and checking coverage totals
|
657
|
+
SimpleCov.print_error_status = false
|
658
|
+
SimpleCov.formatter SimpleCov::Formatter::SimpleFormatter
|
659
|
+
SimpleCov.minimum_coverage 0
|
660
|
+
# start
|
661
|
+
SimpleCov.start
|
662
|
+
end
|
663
|
+
```
|
664
|
+
|
665
|
+
NOTE: SimpleCov must have already been started before `Process.fork` was called.
|
666
|
+
|
667
|
+
### Running simplecov against spawned subprocesses
|
668
|
+
|
669
|
+
Perhaps you're testing a ruby script with `PTY.spawn` or `Open3.popen`, or `Process.spawn` or etc.
|
670
|
+
SimpleCov can cover this too.
|
671
|
+
|
672
|
+
Add a .simplecov_spawn.rb file to your project root
|
673
|
+
```ruby
|
674
|
+
# .simplecov_spawn.rb
|
675
|
+
require 'simplecov' # this will also pick up whatever config is in .simplecov
|
676
|
+
# so ensure it just contains configuration, and doesn't call SimpleCov.start.
|
677
|
+
SimpleCov.command_name 'spawn' # As this is not for a test runner directly, script doesn't have a pre-defined base command_name
|
678
|
+
SimpleCov.at_fork.call(Process.pid) # Use the per-process setup described previously
|
679
|
+
SimpleCov.start # only now can we start.
|
680
|
+
```
|
681
|
+
Then, instead of calling your script directly, like:
|
682
|
+
```ruby
|
683
|
+
PTY.spawn('my_script.rb') do # ...
|
684
|
+
```
|
685
|
+
Use bin/ruby to require the new .simplecov_spawn file, then your script
|
686
|
+
```ruby
|
687
|
+
PTY.spawn('ruby -r./.simplecov_spawn my_script.rb') do # ...
|
688
|
+
```
|
689
|
+
|
617
690
|
## Running coverage only on demand
|
618
691
|
|
619
692
|
The Ruby STDLIB Coverage library that SimpleCov builds upon is *very* fast (on a ~10 min Rails test suite, the speed
|
@@ -739,30 +812,36 @@ to help ensure coverage is relatively consistent, rather than being skewed by pa
|
|
739
812
|
|
740
813
|
```ruby
|
741
814
|
SimpleCov.minimum_coverage_by_file 80
|
815
|
+
# same as above (the default is to check line coverage by file)
|
816
|
+
SimpleCov.minimum_coverage_by_file line: 80
|
817
|
+
# check for a minimum line coverage by file of 90% and minimum 80% branch coverage
|
818
|
+
SimpleCov.minimum_coverage_by_file line: 90, branch: 80
|
742
819
|
```
|
743
820
|
|
744
|
-
(not yet supported for branch coverage)
|
745
|
-
|
746
821
|
### Maximum coverage drop
|
747
822
|
|
748
823
|
You can define the maximum coverage drop percentage at once. SimpleCov will return non-zero if exceeded.
|
749
824
|
|
750
825
|
```ruby
|
751
826
|
SimpleCov.maximum_coverage_drop 5
|
827
|
+
# same as above (the default is to check line drop)
|
828
|
+
SimpleCov.maximum_coverage_drop line: 5
|
829
|
+
# check for a maximum line drop of 5% and maximum 10% branch drop
|
830
|
+
SimpleCov.maximum_coverage_drop line: 5, branch: 10
|
752
831
|
```
|
753
832
|
|
754
|
-
(not yet supported for branch coverage)
|
755
|
-
|
756
833
|
### Refuse dropping coverage
|
757
834
|
|
758
835
|
You can also entirely refuse dropping coverage between test runs:
|
759
836
|
|
760
837
|
```ruby
|
761
838
|
SimpleCov.refuse_coverage_drop
|
839
|
+
# same as above (the default is to only refuse line drop)
|
840
|
+
SimpleCov.refuse_coverage_drop :line
|
841
|
+
# refuse drop for line and branch
|
842
|
+
SimpleCov.refuse_coverage_drop :line, :branch
|
762
843
|
```
|
763
844
|
|
764
|
-
(not yet supported for branch coverage)
|
765
|
-
|
766
845
|
## Using your own formatter
|
767
846
|
|
768
847
|
You can use your own formatter with:
|
@@ -771,21 +850,37 @@ You can use your own formatter with:
|
|
771
850
|
SimpleCov.formatter = SimpleCov::Formatter::HTMLFormatter
|
772
851
|
```
|
773
852
|
|
774
|
-
|
775
|
-
|
853
|
+
Calling `SimpleCov.result.format!` will be invoked with `SimpleCov::Formatter::YourFormatter.new.format(result)`,
|
854
|
+
and `result` is an instance of `SimpleCov::Result`. Do whatever your wish with that!
|
776
855
|
|
777
856
|
|
778
857
|
## Using multiple formatters
|
779
858
|
|
780
|
-
As of SimpleCov 0.9, you can specify multiple result formats
|
859
|
+
As of SimpleCov 0.9, you can specify multiple result formats. Formatters besides the default HTML formatter require separate gems, however.
|
781
860
|
|
782
861
|
```ruby
|
862
|
+
require "simplecov-html"
|
863
|
+
|
783
864
|
SimpleCov.formatters = SimpleCov::Formatter::MultiFormatter.new([
|
784
865
|
SimpleCov::Formatter::HTMLFormatter,
|
785
866
|
SimpleCov::Formatter::CSVFormatter,
|
786
867
|
])
|
787
868
|
```
|
788
869
|
|
870
|
+
## JSON formatter
|
871
|
+
|
872
|
+
SimpleCov is packaged with a separate gem called [simplecov_json_formatter](https://github.com/codeclimate-community/simplecov_json_formatter) that provides you with a JSON formatter, this formatter could be useful for different use cases, such as for CI consumption or for reporting to external services.
|
873
|
+
|
874
|
+
In order to use it you will need to manually load the installed gem like so:
|
875
|
+
|
876
|
+
```ruby
|
877
|
+
require "simplecov_json_formatter"
|
878
|
+
SimpleCov.formatter = SimpleCov::Formatter::JSONFormatter
|
879
|
+
```
|
880
|
+
|
881
|
+
> _Note:_ In case you plan to report your coverage results to CodeClimate services, know that SimpleCov will automatically use the
|
882
|
+
> JSON formatter along with the HTML formatter when the `CC_TEST_REPORTER_ID` variable is present in the environment.
|
883
|
+
|
789
884
|
## Available formatters, editor integrations and hosted services
|
790
885
|
|
791
886
|
* [Open Source formatter and integration plugins for SimpleCov](doc/alternate-formatters.md)
|
@@ -794,7 +889,7 @@ SimpleCov.formatters = SimpleCov::Formatter::MultiFormatter.new([
|
|
794
889
|
|
795
890
|
## Ruby version compatibility
|
796
891
|
|
797
|
-
SimpleCov is built in [Continuous Integration] on Ruby 2.
|
892
|
+
SimpleCov is built in [Continuous Integration] on Ruby 2.7+ as well as JRuby 9.3+.
|
798
893
|
|
799
894
|
Note for JRuby => You need to pass JRUBY_OPTS="--debug" or create .jrubyrc and add debug.fullTrace=true
|
800
895
|
|
@@ -809,7 +904,7 @@ with them, you'll find that it often misreports coverage with the default config
|
|
809
904
|
issue. Don't despair!
|
810
905
|
|
811
906
|
One solution is to [explicitly call eager
|
812
|
-
load](https://github.com/
|
907
|
+
load](https://github.com/simplecov-ruby/simplecov/issues/381#issuecomment-347651728)
|
813
908
|
in your `test_helper.rb` / `spec_helper.rb` after calling `SimpleCov.start`.
|
814
909
|
|
815
910
|
```ruby
|
@@ -868,7 +963,7 @@ Everyone participating in this project's development, issue trackers and other c
|
|
868
963
|
|
869
964
|
## Contributing
|
870
965
|
|
871
|
-
See the [contributing guide](https://github.com/
|
966
|
+
See the [contributing guide](https://github.com/simplecov-ruby/simplecov/blob/main/CONTRIBUTING.md).
|
872
967
|
|
873
968
|
## Kudos
|
874
969
|
|
data/doc/alternate-formatters.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
## Alternate coverage report formatters
|
2
2
|
|
3
3
|
The community around simplecov provides a whole bunch of alternate formatters beyond the official
|
4
|
-
[simplecov-html](https://github.com/
|
4
|
+
[simplecov-html](https://github.com/simplecov-ruby/simplecov-html) gem.
|
5
5
|
|
6
6
|
If you have built or found one that is missing here, please send a Pull Request for this document!
|
7
7
|
|
@@ -15,6 +15,11 @@ A formatter that generates a coverage badge for use in your project's readme usi
|
|
15
15
|
|
16
16
|
A formatter that generates a small coverage badge for use in your project's readme using the SVG.
|
17
17
|
|
18
|
+
#### [simplecov_badger](https://github.com/traels-it/simplecov_badger)
|
19
|
+
*by traels.it*
|
20
|
+
|
21
|
+
A formatter that uploads your coverage to a server, that will then host a SVG badge of the score. No need to have the badge stored in repository.
|
22
|
+
|
18
23
|
#### [simplecov-cobertura](https://github.com/dashingrocket/simplecov-cobertura)
|
19
24
|
*by Jesse Bowes*
|
20
25
|
|
@@ -55,7 +60,12 @@ A formatter that prints the coverage of the file under test when you run a singl
|
|
55
60
|
|
56
61
|
t_wada AA formatter for SimpleCov
|
57
62
|
|
58
|
-
#### [simplecov-
|
63
|
+
#### [simplecov-tailwindcss](https://github.com/chiefpansancolt/simplecov-tailwindcss)
|
64
|
+
*by [Chiefpansancolt](https://github.com/chiefpansancolt)*
|
65
|
+
|
66
|
+
A TailwindCSS & TailwindUI Designed HTML formatter with clean and easy search of files with a tabular left Navigation.
|
67
|
+
|
68
|
+
#### [simplecov-material](https://github.com/chiefpansancolt/simplecov-material)
|
59
69
|
*by [Chiefpansancolt](https://github.com/chiefpansancolt)*
|
60
70
|
|
61
71
|
A Material Designed HTML formatter with clean and easy search of files with a tabular left Navigation.
|
data/doc/commercial-services.md
CHANGED
@@ -4,6 +4,11 @@ There is a bunch of services that offer integration with your existing CI pipeli
|
|
4
4
|
reports. Please note these are not associated with the SimpleCov project itself, so please report problems with
|
5
5
|
these integrations with their respective owners.
|
6
6
|
|
7
|
+
#### [Codacy](https://github.com/codacy/codacy-coverage-reporter)
|
8
|
+
*by [Codacy](https://www.codacy.com/)*
|
9
|
+
|
10
|
+
Upload coverage reports to [codacy.com](https://www.codacy.com/), a hosted (or self-hosted) software quality analysis platform that also includes coverage reporting.
|
11
|
+
|
7
12
|
#### [codeclimate](https://github.com/codeclimate/ruby-test-reporter)
|
8
13
|
*by [Code Climate](https://codeclimate.com/)*
|
9
14
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# How minitest plugins. See https://github.com/
|
3
|
+
# How minitest plugins. See https://github.com/simplecov-ruby/simplecov/pull/756 for why we need this.
|
4
4
|
# https://github.com/seattlerb/minitest#writing-extensions
|
5
5
|
module Minitest
|
6
6
|
def self.plugin_simplecov_init(_options)
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
require "fileutils"
|
4
4
|
require "docile"
|
5
|
-
|
5
|
+
require_relative "formatter/multi_formatter"
|
6
6
|
|
7
7
|
module SimpleCov
|
8
8
|
#
|
@@ -10,7 +10,7 @@ module SimpleCov
|
|
10
10
|
# defined here are usable from SimpleCov directly. Please check out
|
11
11
|
# SimpleCov documentation for further info.
|
12
12
|
#
|
13
|
-
module Configuration
|
13
|
+
module Configuration
|
14
14
|
attr_writer :filters, :groups, :formatter, :print_error_status
|
15
15
|
|
16
16
|
#
|
@@ -22,6 +22,7 @@ module SimpleCov
|
|
22
22
|
def root(root = nil)
|
23
23
|
return @root if defined?(@root) && root.nil?
|
24
24
|
|
25
|
+
@coverage_path = nil # invalidate cache
|
25
26
|
@root = File.expand_path(root || Dir.getwd)
|
26
27
|
end
|
27
28
|
|
@@ -190,12 +191,59 @@ module SimpleCov
|
|
190
191
|
# end
|
191
192
|
#
|
192
193
|
def at_exit(&block)
|
193
|
-
return
|
194
|
+
return Proc.new unless running || block_given?
|
194
195
|
|
195
196
|
@at_exit = block if block_given?
|
196
197
|
@at_exit ||= proc { SimpleCov.result.format! }
|
197
198
|
end
|
198
199
|
|
200
|
+
# gets or sets the enabled_for_subprocess configuration
|
201
|
+
# when true, this will inject SimpleCov code into Process.fork
|
202
|
+
def enable_for_subprocesses(value = nil)
|
203
|
+
return @enable_for_subprocesses if defined?(@enable_for_subprocesses) && value.nil?
|
204
|
+
|
205
|
+
@enable_for_subprocesses = value || false
|
206
|
+
end
|
207
|
+
|
208
|
+
# gets the enabled_for_subprocess configuration
|
209
|
+
def enabled_for_subprocesses?
|
210
|
+
enable_for_subprocesses
|
211
|
+
end
|
212
|
+
|
213
|
+
#
|
214
|
+
# Gets or sets the behavior to start a new forked Process.
|
215
|
+
#
|
216
|
+
# By default, it will add " (Process #{pid})" to the command_name, and start SimpleCov in quiet mode
|
217
|
+
#
|
218
|
+
# Configure with:
|
219
|
+
#
|
220
|
+
# SimpleCov.at_fork do |pid|
|
221
|
+
# SimpleCov.start do
|
222
|
+
# # This needs a unique name so it won't be ovewritten
|
223
|
+
# SimpleCov.command_name "#{SimpleCov.command_name} (subprocess: #{pid})"
|
224
|
+
# # be quiet, the parent process will be in charge of using the regular formatter and checking coverage totals
|
225
|
+
# SimpleCov.print_error_status = false
|
226
|
+
# SimpleCov.formatter SimpleCov::Formatter::SimpleFormatter
|
227
|
+
# SimpleCov.minimum_coverage 0
|
228
|
+
# # start
|
229
|
+
# SimpleCov.start
|
230
|
+
# end
|
231
|
+
# end
|
232
|
+
#
|
233
|
+
def at_fork(&block)
|
234
|
+
@at_fork = block if block_given?
|
235
|
+
@at_fork ||= lambda { |pid|
|
236
|
+
# This needs a unique name so it won't be ovewritten
|
237
|
+
SimpleCov.command_name "#{SimpleCov.command_name} (subprocess: #{pid})"
|
238
|
+
# be quiet, the parent process will be in charge of using the regular formatter and checking coverage totals
|
239
|
+
SimpleCov.print_error_status = false
|
240
|
+
SimpleCov.formatter SimpleCov::Formatter::SimpleFormatter
|
241
|
+
SimpleCov.minimum_coverage 0
|
242
|
+
# start
|
243
|
+
SimpleCov.start
|
244
|
+
}
|
245
|
+
end
|
246
|
+
|
199
247
|
#
|
200
248
|
# Returns the project name - currently assuming the last dirname in
|
201
249
|
# the SimpleCov.root is this.
|
@@ -242,15 +290,20 @@ module SimpleCov
|
|
242
290
|
def minimum_coverage(coverage = nil)
|
243
291
|
return @minimum_coverage ||= {} unless coverage
|
244
292
|
|
245
|
-
coverage = {
|
246
|
-
|
247
|
-
coverage
|
248
|
-
minimum_possible_coverage_exceeded("minimum_coverage") if percent && percent > 100
|
249
|
-
end
|
293
|
+
coverage = {primary_coverage => coverage} if coverage.is_a?(Numeric)
|
294
|
+
|
295
|
+
raise_on_invalid_coverage(coverage, "minimum_coverage")
|
250
296
|
|
251
297
|
@minimum_coverage = coverage
|
252
298
|
end
|
253
299
|
|
300
|
+
def raise_on_invalid_coverage(coverage, coverage_setting)
|
301
|
+
coverage.each_key { |criterion| raise_if_criterion_disabled(criterion) }
|
302
|
+
coverage.each_value do |percent|
|
303
|
+
minimum_possible_coverage_exceeded(coverage_setting) if percent && percent > 100
|
304
|
+
end
|
305
|
+
end
|
306
|
+
|
254
307
|
#
|
255
308
|
# Defines the maximum coverage drop at once allowed for the testsuite to pass.
|
256
309
|
# SimpleCov will return non-zero if the coverage decreases by more than this threshold.
|
@@ -258,7 +311,13 @@ module SimpleCov
|
|
258
311
|
# Default is 100% (disabled)
|
259
312
|
#
|
260
313
|
def maximum_coverage_drop(coverage_drop = nil)
|
261
|
-
@maximum_coverage_drop ||=
|
314
|
+
return @maximum_coverage_drop ||= {} unless coverage_drop
|
315
|
+
|
316
|
+
coverage_drop = {primary_coverage => coverage_drop} if coverage_drop.is_a?(Numeric)
|
317
|
+
|
318
|
+
raise_on_invalid_coverage(coverage_drop, "maximum_coverage_drop")
|
319
|
+
|
320
|
+
@maximum_coverage_drop = coverage_drop
|
262
321
|
end
|
263
322
|
|
264
323
|
#
|
@@ -269,16 +328,23 @@ module SimpleCov
|
|
269
328
|
# Default is 0% (disabled)
|
270
329
|
#
|
271
330
|
def minimum_coverage_by_file(coverage = nil)
|
272
|
-
|
273
|
-
|
331
|
+
return @minimum_coverage_by_file ||= {} unless coverage
|
332
|
+
|
333
|
+
coverage = {primary_coverage => coverage} if coverage.is_a?(Numeric)
|
334
|
+
|
335
|
+
raise_on_invalid_coverage(coverage, "minimum_coverage_by_file")
|
336
|
+
|
337
|
+
@minimum_coverage_by_file = coverage
|
274
338
|
end
|
275
339
|
|
276
340
|
#
|
277
341
|
# Refuses any coverage drop. That is, coverage is only allowed to increase.
|
278
342
|
# SimpleCov will return non-zero if the coverage decreases.
|
279
343
|
#
|
280
|
-
def refuse_coverage_drop
|
281
|
-
|
344
|
+
def refuse_coverage_drop(*criteria)
|
345
|
+
criteria = coverage_criteria if criteria.empty?
|
346
|
+
|
347
|
+
maximum_coverage_drop(criteria.map { |c| [c, 0] }.to_h)
|
282
348
|
end
|
283
349
|
|
284
350
|
#
|
@@ -325,7 +391,7 @@ module SimpleCov
|
|
325
391
|
# @param [Symbol] criterion
|
326
392
|
#
|
327
393
|
def coverage_criterion(criterion = nil)
|
328
|
-
return @coverage_criterion ||=
|
394
|
+
return @coverage_criterion ||= primary_coverage unless criterion
|
329
395
|
|
330
396
|
raise_if_criterion_unsupported(criterion)
|
331
397
|
|
@@ -338,8 +404,17 @@ module SimpleCov
|
|
338
404
|
coverage_criteria << criterion
|
339
405
|
end
|
340
406
|
|
407
|
+
def primary_coverage(criterion = nil)
|
408
|
+
if criterion.nil?
|
409
|
+
@primary_coverage ||= DEFAULT_COVERAGE_CRITERION
|
410
|
+
else
|
411
|
+
raise_if_criterion_disabled(criterion)
|
412
|
+
@primary_coverage = criterion
|
413
|
+
end
|
414
|
+
end
|
415
|
+
|
341
416
|
def coverage_criteria
|
342
|
-
@coverage_criteria ||= Set[
|
417
|
+
@coverage_criteria ||= Set[primary_coverage]
|
343
418
|
end
|
344
419
|
|
345
420
|
def coverage_criterion_enabled?(criterion)
|
@@ -365,7 +440,26 @@ module SimpleCov
|
|
365
440
|
end
|
366
441
|
end
|
367
442
|
|
368
|
-
|
443
|
+
def branch_coverage_supported?
|
444
|
+
coverage_start_arguments_supported? && RUBY_ENGINE != "jruby"
|
445
|
+
end
|
446
|
+
|
447
|
+
def coverage_for_eval_supported?
|
448
|
+
require "coverage"
|
449
|
+
defined?(Coverage.supported?) && Coverage.supported?(:eval)
|
450
|
+
end
|
451
|
+
|
452
|
+
def coverage_for_eval_enabled?
|
453
|
+
@coverage_for_eval_enabled ||= false
|
454
|
+
end
|
455
|
+
|
456
|
+
def enable_coverage_for_eval
|
457
|
+
if coverage_for_eval_supported?
|
458
|
+
@coverage_for_eval_enabled = true
|
459
|
+
else
|
460
|
+
warn "Coverage for eval is not available; Use Ruby 3.2.0 or later"
|
461
|
+
end
|
462
|
+
end
|
369
463
|
|
370
464
|
private
|
371
465
|
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "simplecov-html"
|
4
|
+
module SimpleCov
|
5
|
+
module Formatter
|
6
|
+
class << self
|
7
|
+
def from_env(env)
|
8
|
+
formatters = [SimpleCov::Formatter::HTMLFormatter]
|
9
|
+
|
10
|
+
# When running under a CI that uses CodeClimate, JSON output is expected
|
11
|
+
if env.fetch("CC_TEST_REPORTER_ID", nil)
|
12
|
+
require "simplecov_json_formatter"
|
13
|
+
formatters.push(SimpleCov::Formatter::JSONFormatter)
|
14
|
+
end
|
15
|
+
|
16
|
+
formatters
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/simplecov/defaults.rb
CHANGED
@@ -1,17 +1,20 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# Load default formatter gem
|
4
|
-
require "simplecov-html"
|
5
4
|
require "pathname"
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
5
|
+
require_relative "default_formatter"
|
6
|
+
require_relative "profiles/root_filter"
|
7
|
+
require_relative "profiles/test_frameworks"
|
8
|
+
require_relative "profiles/bundler_filter"
|
9
|
+
require_relative "profiles/hidden_filter"
|
10
|
+
require_relative "profiles/rails"
|
11
11
|
|
12
12
|
# Default configuration
|
13
13
|
SimpleCov.configure do
|
14
|
-
formatter SimpleCov::Formatter::
|
14
|
+
formatter SimpleCov::Formatter::MultiFormatter.new(
|
15
|
+
SimpleCov::Formatter.from_env(ENV)
|
16
|
+
)
|
17
|
+
|
15
18
|
load_profile "bundler_filter"
|
16
19
|
load_profile "hidden_filter"
|
17
20
|
# Exclude files outside of SimpleCov.root
|
@@ -28,7 +31,7 @@ at_exit do
|
|
28
31
|
end
|
29
32
|
|
30
33
|
# Autoload config from ~/.simplecov if present
|
31
|
-
|
34
|
+
require_relative "load_global_config"
|
32
35
|
|
33
36
|
# Autoload config from .simplecov if present
|
34
37
|
# Recurse upwards until we find .simplecov or reach the root directory
|