simplecov 0.15.1 → 0.16.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +17 -1
- data/CONTRIBUTING.md +12 -9
- data/ISSUE_TEMPLATE.md +23 -0
- data/README.md +41 -14
- data/doc/alternate-formatters.md +10 -0
- data/lib/simplecov.rb +91 -0
- data/lib/simplecov/command_guesser.rb +2 -0
- data/lib/simplecov/configuration.rb +2 -0
- data/lib/simplecov/defaults.rb +9 -80
- data/lib/simplecov/exit_codes.rb +2 -0
- data/lib/simplecov/file_list.rb +2 -0
- data/lib/simplecov/filter.rb +3 -1
- data/lib/simplecov/formatter.rb +2 -0
- data/lib/simplecov/formatter/multi_formatter.rb +2 -0
- data/lib/simplecov/formatter/simple_formatter.rb +2 -0
- data/lib/simplecov/jruby_fix.rb +2 -0
- data/lib/simplecov/last_run.rb +2 -0
- data/lib/simplecov/lines_classifier.rb +19 -3
- data/lib/simplecov/load_global_config.rb +2 -0
- data/lib/simplecov/no_defaults.rb +2 -0
- data/lib/simplecov/profiles.rb +2 -0
- data/lib/simplecov/profiles/bundler_filter.rb +5 -0
- data/lib/simplecov/profiles/rails.rb +18 -0
- data/lib/simplecov/profiles/root_filter.rb +10 -0
- data/lib/simplecov/profiles/test_frameworks.rb +8 -0
- data/lib/simplecov/railtie.rb +2 -0
- data/lib/simplecov/railties/tasks.rake +2 -0
- data/lib/simplecov/raw_coverage.rb +2 -0
- data/lib/simplecov/result.rb +2 -0
- data/lib/simplecov/result_merger.rb +2 -0
- data/lib/simplecov/source_file.rb +3 -1
- data/lib/simplecov/version.rb +3 -1
- metadata +22 -118
- data/.gitignore +0 -31
- data/.rspec +0 -3
- data/.rubocop.yml +0 -88
- data/.travis.yml +0 -29
- data/.yardopts +0 -1
- data/Gemfile +0 -38
- data/MIT-LICENSE +0 -20
- data/Rakefile +0 -39
- data/cucumber.yml +0 -13
- data/features/config_autoload.feature +0 -46
- data/features/config_command_name.feature +0 -45
- data/features/config_coverage_dir.feature +0 -33
- data/features/config_deactivate_merging.feature +0 -42
- data/features/config_formatters.feature +0 -77
- data/features/config_merge_timeout.feature +0 -39
- data/features/config_nocov_token.feature +0 -79
- data/features/config_profiles.feature +0 -44
- data/features/config_project_name.feature +0 -27
- data/features/config_styles.feature +0 -121
- data/features/config_tracked_files.feature +0 -29
- data/features/config_tracked_files_relevant_lines.feature +0 -31
- data/features/cucumber_basic.feature +0 -29
- data/features/maximum_coverage_drop.feature +0 -89
- data/features/merging_test_unit_and_rspec.feature +0 -44
- data/features/minimum_coverage.feature +0 -59
- data/features/refuse_coverage_drop.feature +0 -95
- data/features/rspec_basic.feature +0 -32
- data/features/rspec_fails_on_initialization.feature +0 -14
- data/features/rspec_groups_and_filters_basic.feature +0 -29
- data/features/rspec_groups_and_filters_complex.feature +0 -37
- data/features/rspec_groups_using_filter_class.feature +0 -41
- data/features/rspec_without_simplecov.feature +0 -20
- data/features/skipping_code_blocks_manually.feature +0 -70
- data/features/step_definitions/html_steps.rb +0 -44
- data/features/step_definitions/simplecov_steps.rb +0 -68
- data/features/step_definitions/transformers.rb +0 -13
- data/features/step_definitions/web_steps.rb +0 -64
- data/features/support/aruba_freedom_patch.rb +0 -53
- data/features/support/env.rb +0 -50
- data/features/test_unit_basic.feature +0 -34
- data/features/test_unit_groups_and_filters_basic.feature +0 -29
- data/features/test_unit_groups_and_filters_complex.feature +0 -35
- data/features/test_unit_groups_using_filter_class.feature +0 -40
- data/features/test_unit_without_simplecov.feature +0 -20
- data/features/unicode_compatiblity.feature +0 -67
- data/simplecov.gemspec +0 -27
- data/spec/1_8_fallbacks_spec.rb +0 -31
- data/spec/command_guesser_spec.rb +0 -48
- data/spec/config_loader_spec.rb +0 -14
- data/spec/configuration_spec.rb +0 -35
- data/spec/defaults_spec.rb +0 -41
- data/spec/deleted_source_spec.rb +0 -12
- data/spec/faked_project/Gemfile +0 -6
- data/spec/faked_project/Rakefile +0 -8
- data/spec/faked_project/cucumber.yml +0 -13
- data/spec/faked_project/features/step_definitions/my_steps.rb +0 -22
- data/spec/faked_project/features/support/env.rb +0 -12
- data/spec/faked_project/features/test_stuff.feature +0 -6
- data/spec/faked_project/lib/faked_project.rb +0 -11
- data/spec/faked_project/lib/faked_project/framework_specific.rb +0 -18
- data/spec/faked_project/lib/faked_project/meta_magic.rb +0 -24
- data/spec/faked_project/lib/faked_project/some_class.rb +0 -28
- data/spec/faked_project/lib/faked_project/untested_class.rb +0 -11
- data/spec/faked_project/spec/faked_spec.rb +0 -11
- data/spec/faked_project/spec/forking_spec.rb +0 -8
- data/spec/faked_project/spec/meta_magic_spec.rb +0 -15
- data/spec/faked_project/spec/some_class_spec.rb +0 -13
- data/spec/faked_project/spec/spec_helper.rb +0 -11
- data/spec/faked_project/test/faked_test.rb +0 -11
- data/spec/faked_project/test/meta_magic_test.rb +0 -13
- data/spec/faked_project/test/some_class_test.rb +0 -15
- data/spec/faked_project/test/test_helper.rb +0 -12
- data/spec/file_list_spec.rb +0 -50
- data/spec/filters_spec.rb +0 -202
- data/spec/fixtures/app/controllers/sample_controller.rb +0 -10
- data/spec/fixtures/app/models/user.rb +0 -10
- data/spec/fixtures/deleted_source_sample.rb +0 -15
- data/spec/fixtures/frameworks/rspec_bad.rb +0 -9
- data/spec/fixtures/frameworks/rspec_good.rb +0 -9
- data/spec/fixtures/frameworks/testunit_bad.rb +0 -9
- data/spec/fixtures/frameworks/testunit_good.rb +0 -9
- data/spec/fixtures/iso-8859.rb +0 -3
- data/spec/fixtures/never.rb +0 -2
- data/spec/fixtures/resultset1.rb +0 -4
- data/spec/fixtures/resultset2.rb +0 -4
- data/spec/fixtures/sample.rb +0 -16
- data/spec/fixtures/skipped.rb +0 -4
- data/spec/fixtures/skipped_and_executed.rb +0 -8
- data/spec/fixtures/utf-8.rb +0 -3
- data/spec/helper.rb +0 -26
- data/spec/last_run_spec.rb +0 -48
- data/spec/lines_classifier_spec.rb +0 -103
- data/spec/multi_formatter_spec.rb +0 -20
- data/spec/raw_coverage_spec.rb +0 -92
- data/spec/result_merger_spec.rb +0 -171
- data/spec/result_spec.rb +0 -209
- data/spec/return_codes_spec.rb +0 -34
- data/spec/simplecov_spec.rb +0 -109
- data/spec/source_file_line_spec.rb +0 -155
- data/spec/source_file_spec.rb +0 -145
- data/spec/support/fail_rspec_on_ruby_warning.rb +0 -75
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 47d20d0dc990b18c8ac6bcc24755bb66521230c3
|
4
|
+
data.tar.gz: 22c23ddd73f1052aa525905f82f7545f63207ee7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 320807d6f5176f76cb38f7fcbc6eb1e59b2e0cffcd4eb28bcf804f0eaf824b5a44926345f0516ae40a091ec866ad8e8aff43aed8536b5812bffabe5b6d2bc005
|
7
|
+
data.tar.gz: cf2c3e9a80d843f3970b3a0ac9ab5e21e81a18ea1ae306cebe74bc7f77bf6263115a1b6405547d26f608a574ab7a8d1da901d9d9a8524edee0e5a19241cd932d
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,19 @@
|
|
1
|
+
0.16.0 (2018-03-15)
|
2
|
+
==========
|
3
|
+
|
4
|
+
## Enhancements
|
5
|
+
|
6
|
+
* Relax version constraint on `docile`, per SemVer
|
7
|
+
* exception that occurred on exit is available as `exit_exception`! See [#639](https://github.com/colszowka/simplecov/pull/639) (thanks @thomas07vt)
|
8
|
+
* Performance: processing results now runs from 2.5x to 3.75x faster. See [#662](https://github.com/colszowka/simplecov/pull/662) (thanks @BMorearty & @eregon)
|
9
|
+
* Decrease gem size by only shipping lib and docs
|
10
|
+
|
11
|
+
## Bugfixes
|
12
|
+
|
13
|
+
* (breaking) Stop handling string filters as regular expressions, use the dedicated regex filter if you need that behaviour. See [#616](https://github.com/colszowka/simplecov/pull/616) (thanks @yujinakayama)
|
14
|
+
* Avoid overwriting the last coverage results on unsuccessful test runs. See [#625](https://github.com/colszowka/simplecov/pull/625) (thanks @thomas07vt)
|
15
|
+
* Don't crash on invalid UTF-8 byte sequences. (thanks @BMorearty)
|
16
|
+
|
1
17
|
0.15.1 (2017-09-11) ([changes](https://github.com/colszowka/simplecov/compare/v0.15.0...v0.15.1))
|
2
18
|
=======
|
3
19
|
|
@@ -16,7 +32,7 @@
|
|
16
32
|
## Bugfixes
|
17
33
|
|
18
34
|
* Fix merging race condition when running tests in parallel and merging them. See [#570](https://github.com/colszowka/simplecov/pull/570) (thanks @jenseng)
|
19
|
-
* Fix relevant lines for unloaded files - comments, skipped code etc. are correctly
|
35
|
+
* Fix relevant lines for unloaded files - comments, skipped code etc. are correctly classified as irrelevant. See [#605](https://github.com/colszowka/simplecov/pull/605) (thanks @odlp)
|
20
36
|
* Allow using simplecov with frozen-string-literals enabled. See [#590](https://github.com/colszowka/simplecov/pull/590) (thanks @pat)
|
21
37
|
* Make sure Array Filter can use all other filter types. See [#589](https://github.com/colszowka/simplecov/pull/589) (thanks @jsteel)
|
22
38
|
* Make sure file names use `Simplecov.root` as base avoiding using full absolute project paths. See [#589](https://github.com/colszowka/simplecov/pull/589) (thanks @jsteel)
|
data/CONTRIBUTING.md
CHANGED
@@ -2,19 +2,21 @@
|
|
2
2
|
|
3
3
|
You can report issues at https://github.com/colszowka/simplecov/issues
|
4
4
|
|
5
|
-
|
5
|
+
Before you go ahead please search existing issues for your problem, chances are someone else already reported it.
|
6
6
|
|
7
|
+
To make sure that we can help you quickly please include and check the following information:
|
8
|
+
|
9
|
+
* Include how you run your tests and which testing framework or frameworks you are running.
|
10
|
+
- please ensure you are requiring and starting SimpleCov before requiring any application code.
|
11
|
+
- If running via rake, please ensure you are requiring SimpleCov at the top of your Rakefile
|
12
|
+
For example, if running via RSpec, this would be at the top of your spec_helper.
|
13
|
+
- Have you tried using a [`.simplecov` file](https://github.com/colszowka/simplecov#using-simplecov-for-centralized-config)?
|
7
14
|
* Include the SimpleCov version you are running in your report.
|
8
15
|
* If you are not running the latest version (please check), and you cannot update it,
|
9
16
|
please specify in your report why you can't update to the latest version.
|
10
17
|
* Include your `ruby -e "puts RUBY_DESCRIPTION"`.
|
11
18
|
* Please also specify the gem versions of Rails (if applicable).
|
12
19
|
* Include any other coverage gems you may be using and their versions.
|
13
|
-
* Include how you run your tests and which testing framework or frameworks you are running.
|
14
|
-
- If running via rake, please ensure you are requiring SimpleCov at the top of your Rakefile
|
15
|
-
- Otherwise, please ensure you are requiring and starting SimpleCov before requiring any application code.
|
16
|
-
For example, if running via RSpec, this would be at the top of your spec_helper.
|
17
|
-
- Have you tried using a [`.simplecov` file](https://github.com/colszowka/simplecov#using-simplecov-for-centralized-config)?
|
18
20
|
|
19
21
|
Include as much sample code as you can to help us reproduce the issue. (Inline, repo link, or gist, are fine. A failing test would help the most.)
|
20
22
|
|
@@ -37,12 +39,13 @@ If you want to contribute, please:
|
|
37
39
|
* Make your feature addition or bug fix.
|
38
40
|
* Add tests for it. This is important so I don't break it in a future version unintentionally.
|
39
41
|
* **Bonus Points** go out to anyone who also updates `CHANGELOG.md` :)
|
40
|
-
* Send me a pull request on
|
42
|
+
* Send me a pull request on GitHub.
|
41
43
|
|
42
44
|
## Running Individual Tests
|
43
45
|
|
44
|
-
This project uses
|
46
|
+
This project uses RSpec and Cucumber. Individual tests can be run like this:
|
45
47
|
|
46
48
|
```bash
|
47
|
-
|
49
|
+
bundle exec rspec path/to/test.rb
|
50
|
+
bundle exec cucumber path/to/test.feature
|
48
51
|
```
|
data/ISSUE_TEMPLATE.md
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
Howdy! Thanks for reporting an issue <3
|
2
|
+
|
3
|
+
Before you go ahead please search existing issues for your problem, chances are someone else already reported it.
|
4
|
+
|
5
|
+
To make sure that we can help you quickly please include and check the following information:
|
6
|
+
|
7
|
+
* Include how you run your tests and which testing framework or frameworks you are running.
|
8
|
+
- please ensure you are requiring and starting SimpleCov before requiring any application code.
|
9
|
+
- If running via rake, please ensure you are requiring SimpleCov at the top of your Rakefile
|
10
|
+
For example, if running via RSpec, this would be at the top of your spec_helper.
|
11
|
+
- Have you tried using a [`.simplecov` file](https://github.com/colszowka/simplecov#using-simplecov-for-centralized-config)?
|
12
|
+
* Include the SimpleCov version you are running in your report.
|
13
|
+
* If you are not running the latest version (please check), and you cannot update it,
|
14
|
+
please specify in your report why you can't update to the latest version.
|
15
|
+
* Include your `ruby -e "puts RUBY_DESCRIPTION"`.
|
16
|
+
* Please also specify the gem versions of Rails (if applicable).
|
17
|
+
* Include any other coverage gems you may be using and their versions.
|
18
|
+
|
19
|
+
Include as much sample code as you can to help us reproduce the issue. (Inline, repo link, or gist, are fine. A failing test would help the most.)
|
20
|
+
|
21
|
+
This is extremely important for narrowing down the cause of your problem.
|
22
|
+
|
23
|
+
Thanks!
|
data/README.md
CHANGED
@@ -28,7 +28,7 @@ etc. SimpleCov automatically takes care of this by caching and merging results w
|
|
28
28
|
report actually includes coverage across your test suites and thereby gives you a better picture of blank spots.
|
29
29
|
|
30
30
|
The official formatter of SimpleCov is packaged as a separate gem called [simplecov-html], but will be installed and configured
|
31
|
-
automatically when you launch SimpleCov. If you're curious, you can find it [on
|
31
|
+
automatically when you launch SimpleCov. If you're curious, you can find it [on GitHub, too][simplecov-html].
|
32
32
|
|
33
33
|
|
34
34
|
## Contact
|
@@ -47,10 +47,10 @@ Getting started
|
|
47
47
|
1. Add SimpleCov to your `Gemfile` and `bundle install`:
|
48
48
|
|
49
49
|
```ruby
|
50
|
-
gem 'simplecov', :
|
50
|
+
gem 'simplecov', require: false, group: :test
|
51
51
|
```
|
52
52
|
2. Load and launch SimpleCov **at the very top** of your `test/test_helper.rb`
|
53
|
-
(*or `spec_helper.rb`, cucumber `env.rb`, or whatever your preferred test
|
53
|
+
(*or `spec_helper.rb`, `rails_helper`, cucumber `env.rb`, or whatever your preferred test
|
54
54
|
framework uses*):
|
55
55
|
|
56
56
|
```ruby
|
@@ -246,7 +246,7 @@ If you use SimpleCov to merge multiple test suite results (e.g. Test/Unit and Cu
|
|
246
246
|
set up all your config options twice, once in `test_helper.rb` and once in `env.rb`.
|
247
247
|
|
248
248
|
To avoid this, you can place a file called `.simplecov` in your project root. You can then just leave the `require 'simplecov'` in each
|
249
|
-
test setup helper and move the `SimpleCov.start` code with all your custom config options into `.simplecov`:
|
249
|
+
test setup helper (**at the top**) and move the `SimpleCov.start` code with all your custom config options into `.simplecov`:
|
250
250
|
|
251
251
|
```ruby
|
252
252
|
# test/test_helper.rb
|
@@ -260,6 +260,7 @@ SimpleCov.start 'rails' do
|
|
260
260
|
# any custom configs like groups and filters can be here at a central place
|
261
261
|
end
|
262
262
|
```
|
263
|
+
|
263
264
|
Using `.simplecov` rather than separately requiring SimpleCov multiple times is recommended if you are merging multiple test frameworks like Cucumber and RSpec that rely on each other, as invoking SimpleCov multiple times can cause coverage information to be lost.
|
264
265
|
|
265
266
|
## Filters
|
@@ -619,7 +620,7 @@ Only Ruby 1.9+ ships with the coverage library that SimpleCov depends upon and t
|
|
619
620
|
SimpleCov is also built against Ruby 1.8 in [Continuous Integration], but this happens only to ensure that SimpleCov
|
620
621
|
does not make your test suite crash right now.
|
621
622
|
|
622
|
-
SimpleCov is built in [Continuous Integration] on Ruby 1.9.3, 2.0.0, 2.1, 2.2, 2.3, 2.4 as well as JRuby 9.1.
|
623
|
+
SimpleCov is built in [Continuous Integration] on Ruby 1.9.3, 2.0.0, 2.1, 2.2, 2.3, 2.4, 2.5 as well as JRuby 9.1.
|
623
624
|
|
624
625
|
## Want to find dead code in production?
|
625
626
|
|
@@ -632,14 +633,8 @@ If you're using [Spring](https://github.com/rails/spring) to speed up test suite
|
|
632
633
|
1. Change the following settings in `test.rb`.
|
633
634
|
|
634
635
|
```ruby
|
635
|
-
# For Rails
|
636
|
-
#
|
637
|
-
config.serve_static_files = false
|
638
|
-
config.eager_load = false
|
639
|
-
|
640
|
-
# For Rails 5, use the following configuration:
|
641
|
-
# Disable Rails's static asset server (Apache or nginx will already do this)
|
642
|
-
config.public_file_server.enabled = false
|
636
|
+
# For Rails
|
637
|
+
# Do not eager load code on boot
|
643
638
|
config.eager_load = false
|
644
639
|
```
|
645
640
|
2. Add your SimpleCov config, as you normally would, to your `spec_helper.rb`
|
@@ -655,7 +650,7 @@ If you're using [Spring](https://github.com/rails/spring) to speed up test suite
|
|
655
650
|
```
|
656
651
|
3. Run `spring rspec <path>` as normal. Remember to run `spring stop` after
|
657
652
|
making important changes to your app or its specs!
|
658
|
-
|
653
|
+
|
659
654
|
## Want to use bootsnap with SimpleCov?
|
660
655
|
|
661
656
|
As mentioned in [this issue](https://github.com/Shopify/bootsnap/issues/35) iseq
|
@@ -670,6 +665,38 @@ Bootsnap.setup(
|
|
670
665
|
)
|
671
666
|
```
|
672
667
|
|
668
|
+
## Troubleshooting
|
669
|
+
|
670
|
+
The **most common problem is that simplecov isn't required and started before everything else**. In order to track coverage for your whole application **simplecov needs to be the first one** so that it (and the underlying coverage library) can subsequently track loaded files and their usage.
|
671
|
+
|
672
|
+
If you are missing coverage for some code a simple trick is to put a puts statement in there and right after `SimpleCov.start` so you can see if the file really was loaded after simplecov was started.
|
673
|
+
|
674
|
+
```ruby
|
675
|
+
# my_code.rb
|
676
|
+
class MyCode
|
677
|
+
|
678
|
+
puts "MyCode is being loaded!"
|
679
|
+
|
680
|
+
def my_method
|
681
|
+
# ...
|
682
|
+
end
|
683
|
+
end
|
684
|
+
|
685
|
+
# spec_helper.rb/rails_helper.rb/test_helper.rb/.simplecov whatever
|
686
|
+
|
687
|
+
SimpleCov.start
|
688
|
+
puts "SimpleCov started successfully!"
|
689
|
+
```
|
690
|
+
|
691
|
+
Now when you run your test suite and you see:
|
692
|
+
|
693
|
+
```
|
694
|
+
SimpleCov started successfully!
|
695
|
+
MyCode is being loaded!
|
696
|
+
```
|
697
|
+
|
698
|
+
then it's good otherwise you likely have a problem :)
|
699
|
+
|
673
700
|
## Contributing
|
674
701
|
|
675
702
|
See the [contributing guide](https://github.com/colszowka/simplecov/blob/master/CONTRIBUTING.md).
|
data/doc/alternate-formatters.md
CHANGED
@@ -20,11 +20,21 @@ A formatter that generates Cobertura XML.
|
|
20
20
|
|
21
21
|
CSV formatter for SimpleCov
|
22
22
|
|
23
|
+
#### [simplecov-erb](https://github.com/kpaulisse/simplecov-erb)
|
24
|
+
*by [Kevin Paulisse](https://github.com/kpaulisse)*
|
25
|
+
|
26
|
+
Flexible formatter that generates the output from an ERB template.
|
27
|
+
|
23
28
|
#### [simplecov-json](https://github.com/vicentllongo/simplecov-json)
|
24
29
|
*by Vicent Llongo*
|
25
30
|
|
26
31
|
JSON formatter for SimpleCov
|
27
32
|
|
33
|
+
#### [simplecov-lcov](https://github.com/fortissimo1997/simplecov-lcov)
|
34
|
+
*by fortissimo1997*
|
35
|
+
|
36
|
+
lcov formatter for SimpleCov
|
37
|
+
|
28
38
|
#### [simplecov-rcov](https://github.com/fguillen/simplecov-rcov)
|
29
39
|
*by Fernando Guillen*
|
30
40
|
|
data/lib/simplecov.rb
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "English"
|
4
|
+
|
1
5
|
#
|
2
6
|
# Code coverage for ruby 1.9. Please check out README for a full introduction.
|
3
7
|
#
|
@@ -20,6 +24,7 @@ module SimpleCov
|
|
20
24
|
class << self
|
21
25
|
attr_accessor :running
|
22
26
|
attr_accessor :pid
|
27
|
+
attr_reader :exit_exception
|
23
28
|
|
24
29
|
#
|
25
30
|
# Sets up SimpleCov to run against your project.
|
@@ -163,6 +168,92 @@ module SimpleCov
|
|
163
168
|
def clear_result
|
164
169
|
@result = nil
|
165
170
|
end
|
171
|
+
|
172
|
+
#
|
173
|
+
# Capture the current exception if it exists
|
174
|
+
# This will get called inside the at_exit block
|
175
|
+
#
|
176
|
+
def set_exit_exception
|
177
|
+
@exit_exception = $ERROR_INFO
|
178
|
+
end
|
179
|
+
|
180
|
+
#
|
181
|
+
# Returns the exit status from the exit exception
|
182
|
+
#
|
183
|
+
def exit_status_from_exception
|
184
|
+
return SimpleCov::ExitCodes::SUCCESS unless exit_exception
|
185
|
+
|
186
|
+
if exit_exception.is_a?(SystemExit)
|
187
|
+
exit_exception.status
|
188
|
+
else
|
189
|
+
SimpleCov::ExitCodes::EXCEPTION
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
193
|
+
# @api private
|
194
|
+
#
|
195
|
+
# Called from at_exit block
|
196
|
+
#
|
197
|
+
def run_exit_tasks!
|
198
|
+
exit_status = SimpleCov.exit_status_from_exception
|
199
|
+
|
200
|
+
SimpleCov.at_exit.call
|
201
|
+
|
202
|
+
exit_status = SimpleCov.process_result(SimpleCov.result, exit_status)
|
203
|
+
|
204
|
+
# Force exit with stored status (see github issue #5)
|
205
|
+
# unless it's nil or 0 (see github issue #281)
|
206
|
+
Kernel.exit exit_status if exit_status && exit_status > 0
|
207
|
+
end
|
208
|
+
|
209
|
+
# @api private
|
210
|
+
#
|
211
|
+
# Usage:
|
212
|
+
# exit_status = SimpleCov.process_result(SimpleCov.result, exit_status)
|
213
|
+
#
|
214
|
+
def process_result(result, exit_status)
|
215
|
+
return exit_status unless SimpleCov.result? # Result has been computed
|
216
|
+
return exit_status if exit_status != SimpleCov::ExitCodes::SUCCESS # Existing errors
|
217
|
+
|
218
|
+
covered_percent = result.covered_percent.round(2)
|
219
|
+
result_exit_status = result_exit_status(result, covered_percent)
|
220
|
+
if result_exit_status == SimpleCov::ExitCodes::SUCCESS # No result errors
|
221
|
+
write_last_run(covered_percent)
|
222
|
+
end
|
223
|
+
result_exit_status
|
224
|
+
end
|
225
|
+
|
226
|
+
# @api private
|
227
|
+
#
|
228
|
+
# rubocop:disable Metrics/MethodLength
|
229
|
+
def result_exit_status(result, covered_percent)
|
230
|
+
covered_percentages = result.covered_percentages.map { |percentage| percentage.round(2) }
|
231
|
+
if covered_percent < SimpleCov.minimum_coverage
|
232
|
+
$stderr.printf("Coverage (%.2f%%) is below the expected minimum coverage (%.2f%%).\n", covered_percent, SimpleCov.minimum_coverage)
|
233
|
+
SimpleCov::ExitCodes::MINIMUM_COVERAGE
|
234
|
+
elsif covered_percentages.any? { |p| p < SimpleCov.minimum_coverage_by_file }
|
235
|
+
$stderr.printf("File (%s) is only (%.2f%%) covered. This is below the expected minimum coverage per file of (%.2f%%).\n", result.least_covered_file, covered_percentages.min, SimpleCov.minimum_coverage_by_file)
|
236
|
+
SimpleCov::ExitCodes::MINIMUM_COVERAGE
|
237
|
+
elsif (last_run = SimpleCov::LastRun.read)
|
238
|
+
coverage_diff = last_run["result"]["covered_percent"] - covered_percent
|
239
|
+
if coverage_diff > SimpleCov.maximum_coverage_drop
|
240
|
+
$stderr.printf("Coverage has dropped by %.2f%% since the last time (maximum allowed: %.2f%%).\n", coverage_diff, SimpleCov.maximum_coverage_drop)
|
241
|
+
SimpleCov::ExitCodes::MAXIMUM_COVERAGE_DROP
|
242
|
+
else
|
243
|
+
SimpleCov::ExitCodes::SUCCESS
|
244
|
+
end
|
245
|
+
else
|
246
|
+
SimpleCov::ExitCodes::SUCCESS
|
247
|
+
end
|
248
|
+
end
|
249
|
+
# rubocop:enable Metrics/MethodLength
|
250
|
+
|
251
|
+
#
|
252
|
+
# @api private
|
253
|
+
#
|
254
|
+
def write_last_run(covered_percent)
|
255
|
+
SimpleCov::LastRun.write(:result => {:covered_percent => covered_percent})
|
256
|
+
end
|
166
257
|
end
|
167
258
|
end
|
168
259
|
|
data/lib/simplecov/defaults.rb
CHANGED
@@ -1,43 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# Load default formatter gem
|
2
4
|
require "simplecov-html"
|
3
5
|
require "pathname"
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
add_filter do |src|
|
9
|
-
root_filter ||= /\A#{Regexp.escape(SimpleCov.root + File::SEPARATOR)}/io
|
10
|
-
src.filename !~ root_filter
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
SimpleCov.profiles.define "test_frameworks" do
|
15
|
-
add_filter "/test/"
|
16
|
-
add_filter "/features/"
|
17
|
-
add_filter "/spec/"
|
18
|
-
add_filter "/autotest/"
|
19
|
-
end
|
20
|
-
|
21
|
-
SimpleCov.profiles.define "bundler_filter" do
|
22
|
-
add_filter "/vendor/bundle/"
|
23
|
-
end
|
24
|
-
|
25
|
-
SimpleCov.profiles.define "rails" do
|
26
|
-
load_profile "test_frameworks"
|
27
|
-
|
28
|
-
add_filter %r{^/config/}
|
29
|
-
add_filter %r{^/db/}
|
30
|
-
|
31
|
-
add_group "Controllers", "app/controllers"
|
32
|
-
add_group "Channels", "app/channels" if defined?(ActionCable)
|
33
|
-
add_group "Models", "app/models"
|
34
|
-
add_group "Mailers", "app/mailers"
|
35
|
-
add_group "Helpers", "app/helpers"
|
36
|
-
add_group "Jobs", %w[app/jobs app/workers]
|
37
|
-
add_group "Libraries", "lib"
|
38
|
-
|
39
|
-
track_files "{app,lib}/**/*.rb"
|
40
|
-
end
|
6
|
+
require "simplecov/profiles/root_filter"
|
7
|
+
require "simplecov/profiles/test_frameworks"
|
8
|
+
require "simplecov/profiles/bundler_filter"
|
9
|
+
require "simplecov/profiles/rails"
|
41
10
|
|
42
11
|
# Default configuration
|
43
12
|
SimpleCov.configure do
|
@@ -50,52 +19,12 @@ end
|
|
50
19
|
# Gotta stash this a-s-a-p, see the CommandGuesser class and i.e. #110 for further info
|
51
20
|
SimpleCov::CommandGuesser.original_run_command = "#{$PROGRAM_NAME} #{ARGV.join(' ')}"
|
52
21
|
|
53
|
-
at_exit do
|
22
|
+
at_exit do
|
54
23
|
# If we are in a different process than called start, don't interfere.
|
55
24
|
next if SimpleCov.pid != Process.pid
|
56
25
|
|
57
|
-
|
58
|
-
|
59
|
-
# otherwise set a non-zero status representing termination by
|
60
|
-
# some other exception (see github issue 41)
|
61
|
-
$!.is_a?(SystemExit) ? $!.status : SimpleCov::ExitCodes::EXCEPTION
|
62
|
-
else
|
63
|
-
# Store the exit status of the test run since it goes away
|
64
|
-
# after calling the at_exit proc...
|
65
|
-
SimpleCov::ExitCodes::SUCCESS
|
66
|
-
end
|
67
|
-
|
68
|
-
SimpleCov.at_exit.call
|
69
|
-
|
70
|
-
if SimpleCov.result? # Result has been computed
|
71
|
-
covered_percent = SimpleCov.result.covered_percent.round(2)
|
72
|
-
covered_percentages = SimpleCov.result.covered_percentages.map { |p| p.round(2) }
|
73
|
-
|
74
|
-
if @exit_status == SimpleCov::ExitCodes::SUCCESS # No other errors
|
75
|
-
if covered_percent < SimpleCov.minimum_coverage # rubocop:disable Metrics/BlockNesting
|
76
|
-
$stderr.printf("Coverage (%.2f%%) is below the expected minimum coverage (%.2f%%).\n", covered_percent, SimpleCov.minimum_coverage)
|
77
|
-
@exit_status = SimpleCov::ExitCodes::MINIMUM_COVERAGE
|
78
|
-
elsif covered_percentages.any? { |p| p < SimpleCov.minimum_coverage_by_file } # rubocop:disable Metrics/BlockNesting
|
79
|
-
$stderr.printf("File (%s) is only (%.2f%%) covered. This is below the expected minimum coverage per file of (%.2f%%).\n", SimpleCov.result.least_covered_file, covered_percentages.min, SimpleCov.minimum_coverage_by_file)
|
80
|
-
@exit_status = SimpleCov::ExitCodes::MINIMUM_COVERAGE
|
81
|
-
elsif (last_run = SimpleCov::LastRun.read) # rubocop:disable Metrics/BlockNesting
|
82
|
-
coverage_diff = last_run["result"]["covered_percent"] - covered_percent
|
83
|
-
if coverage_diff > SimpleCov.maximum_coverage_drop # rubocop:disable Metrics/BlockNesting
|
84
|
-
$stderr.printf("Coverage has dropped by %.2f%% since the last time (maximum allowed: %.2f%%).\n", coverage_diff, SimpleCov.maximum_coverage_drop)
|
85
|
-
@exit_status = SimpleCov::ExitCodes::MAXIMUM_COVERAGE_DROP
|
86
|
-
end
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
# Don't overwrite last_run file if refuse_coverage_drop option is enabled and the coverage has dropped
|
91
|
-
unless @exit_status == SimpleCov::ExitCodes::MAXIMUM_COVERAGE_DROP
|
92
|
-
SimpleCov::LastRun.write(:result => {:covered_percent => covered_percent})
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
# Force exit with stored status (see github issue #5)
|
97
|
-
# unless it's nil or 0 (see github issue #281)
|
98
|
-
Kernel.exit @exit_status if @exit_status && @exit_status > 0
|
26
|
+
SimpleCov.set_exit_exception
|
27
|
+
SimpleCov.run_exit_tasks!
|
99
28
|
end
|
100
29
|
|
101
30
|
# Autoload config from ~/.simplecov if present
|