simplecov 0.15.1 → 0.16.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (135) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +17 -1
  3. data/CONTRIBUTING.md +12 -9
  4. data/ISSUE_TEMPLATE.md +23 -0
  5. data/README.md +41 -14
  6. data/doc/alternate-formatters.md +10 -0
  7. data/lib/simplecov.rb +91 -0
  8. data/lib/simplecov/command_guesser.rb +2 -0
  9. data/lib/simplecov/configuration.rb +2 -0
  10. data/lib/simplecov/defaults.rb +9 -80
  11. data/lib/simplecov/exit_codes.rb +2 -0
  12. data/lib/simplecov/file_list.rb +2 -0
  13. data/lib/simplecov/filter.rb +3 -1
  14. data/lib/simplecov/formatter.rb +2 -0
  15. data/lib/simplecov/formatter/multi_formatter.rb +2 -0
  16. data/lib/simplecov/formatter/simple_formatter.rb +2 -0
  17. data/lib/simplecov/jruby_fix.rb +2 -0
  18. data/lib/simplecov/last_run.rb +2 -0
  19. data/lib/simplecov/lines_classifier.rb +19 -3
  20. data/lib/simplecov/load_global_config.rb +2 -0
  21. data/lib/simplecov/no_defaults.rb +2 -0
  22. data/lib/simplecov/profiles.rb +2 -0
  23. data/lib/simplecov/profiles/bundler_filter.rb +5 -0
  24. data/lib/simplecov/profiles/rails.rb +18 -0
  25. data/lib/simplecov/profiles/root_filter.rb +10 -0
  26. data/lib/simplecov/profiles/test_frameworks.rb +8 -0
  27. data/lib/simplecov/railtie.rb +2 -0
  28. data/lib/simplecov/railties/tasks.rake +2 -0
  29. data/lib/simplecov/raw_coverage.rb +2 -0
  30. data/lib/simplecov/result.rb +2 -0
  31. data/lib/simplecov/result_merger.rb +2 -0
  32. data/lib/simplecov/source_file.rb +3 -1
  33. data/lib/simplecov/version.rb +3 -1
  34. metadata +22 -118
  35. data/.gitignore +0 -31
  36. data/.rspec +0 -3
  37. data/.rubocop.yml +0 -88
  38. data/.travis.yml +0 -29
  39. data/.yardopts +0 -1
  40. data/Gemfile +0 -38
  41. data/MIT-LICENSE +0 -20
  42. data/Rakefile +0 -39
  43. data/cucumber.yml +0 -13
  44. data/features/config_autoload.feature +0 -46
  45. data/features/config_command_name.feature +0 -45
  46. data/features/config_coverage_dir.feature +0 -33
  47. data/features/config_deactivate_merging.feature +0 -42
  48. data/features/config_formatters.feature +0 -77
  49. data/features/config_merge_timeout.feature +0 -39
  50. data/features/config_nocov_token.feature +0 -79
  51. data/features/config_profiles.feature +0 -44
  52. data/features/config_project_name.feature +0 -27
  53. data/features/config_styles.feature +0 -121
  54. data/features/config_tracked_files.feature +0 -29
  55. data/features/config_tracked_files_relevant_lines.feature +0 -31
  56. data/features/cucumber_basic.feature +0 -29
  57. data/features/maximum_coverage_drop.feature +0 -89
  58. data/features/merging_test_unit_and_rspec.feature +0 -44
  59. data/features/minimum_coverage.feature +0 -59
  60. data/features/refuse_coverage_drop.feature +0 -95
  61. data/features/rspec_basic.feature +0 -32
  62. data/features/rspec_fails_on_initialization.feature +0 -14
  63. data/features/rspec_groups_and_filters_basic.feature +0 -29
  64. data/features/rspec_groups_and_filters_complex.feature +0 -37
  65. data/features/rspec_groups_using_filter_class.feature +0 -41
  66. data/features/rspec_without_simplecov.feature +0 -20
  67. data/features/skipping_code_blocks_manually.feature +0 -70
  68. data/features/step_definitions/html_steps.rb +0 -44
  69. data/features/step_definitions/simplecov_steps.rb +0 -68
  70. data/features/step_definitions/transformers.rb +0 -13
  71. data/features/step_definitions/web_steps.rb +0 -64
  72. data/features/support/aruba_freedom_patch.rb +0 -53
  73. data/features/support/env.rb +0 -50
  74. data/features/test_unit_basic.feature +0 -34
  75. data/features/test_unit_groups_and_filters_basic.feature +0 -29
  76. data/features/test_unit_groups_and_filters_complex.feature +0 -35
  77. data/features/test_unit_groups_using_filter_class.feature +0 -40
  78. data/features/test_unit_without_simplecov.feature +0 -20
  79. data/features/unicode_compatiblity.feature +0 -67
  80. data/simplecov.gemspec +0 -27
  81. data/spec/1_8_fallbacks_spec.rb +0 -31
  82. data/spec/command_guesser_spec.rb +0 -48
  83. data/spec/config_loader_spec.rb +0 -14
  84. data/spec/configuration_spec.rb +0 -35
  85. data/spec/defaults_spec.rb +0 -41
  86. data/spec/deleted_source_spec.rb +0 -12
  87. data/spec/faked_project/Gemfile +0 -6
  88. data/spec/faked_project/Rakefile +0 -8
  89. data/spec/faked_project/cucumber.yml +0 -13
  90. data/spec/faked_project/features/step_definitions/my_steps.rb +0 -22
  91. data/spec/faked_project/features/support/env.rb +0 -12
  92. data/spec/faked_project/features/test_stuff.feature +0 -6
  93. data/spec/faked_project/lib/faked_project.rb +0 -11
  94. data/spec/faked_project/lib/faked_project/framework_specific.rb +0 -18
  95. data/spec/faked_project/lib/faked_project/meta_magic.rb +0 -24
  96. data/spec/faked_project/lib/faked_project/some_class.rb +0 -28
  97. data/spec/faked_project/lib/faked_project/untested_class.rb +0 -11
  98. data/spec/faked_project/spec/faked_spec.rb +0 -11
  99. data/spec/faked_project/spec/forking_spec.rb +0 -8
  100. data/spec/faked_project/spec/meta_magic_spec.rb +0 -15
  101. data/spec/faked_project/spec/some_class_spec.rb +0 -13
  102. data/spec/faked_project/spec/spec_helper.rb +0 -11
  103. data/spec/faked_project/test/faked_test.rb +0 -11
  104. data/spec/faked_project/test/meta_magic_test.rb +0 -13
  105. data/spec/faked_project/test/some_class_test.rb +0 -15
  106. data/spec/faked_project/test/test_helper.rb +0 -12
  107. data/spec/file_list_spec.rb +0 -50
  108. data/spec/filters_spec.rb +0 -202
  109. data/spec/fixtures/app/controllers/sample_controller.rb +0 -10
  110. data/spec/fixtures/app/models/user.rb +0 -10
  111. data/spec/fixtures/deleted_source_sample.rb +0 -15
  112. data/spec/fixtures/frameworks/rspec_bad.rb +0 -9
  113. data/spec/fixtures/frameworks/rspec_good.rb +0 -9
  114. data/spec/fixtures/frameworks/testunit_bad.rb +0 -9
  115. data/spec/fixtures/frameworks/testunit_good.rb +0 -9
  116. data/spec/fixtures/iso-8859.rb +0 -3
  117. data/spec/fixtures/never.rb +0 -2
  118. data/spec/fixtures/resultset1.rb +0 -4
  119. data/spec/fixtures/resultset2.rb +0 -4
  120. data/spec/fixtures/sample.rb +0 -16
  121. data/spec/fixtures/skipped.rb +0 -4
  122. data/spec/fixtures/skipped_and_executed.rb +0 -8
  123. data/spec/fixtures/utf-8.rb +0 -3
  124. data/spec/helper.rb +0 -26
  125. data/spec/last_run_spec.rb +0 -48
  126. data/spec/lines_classifier_spec.rb +0 -103
  127. data/spec/multi_formatter_spec.rb +0 -20
  128. data/spec/raw_coverage_spec.rb +0 -92
  129. data/spec/result_merger_spec.rb +0 -171
  130. data/spec/result_spec.rb +0 -209
  131. data/spec/return_codes_spec.rb +0 -34
  132. data/spec/simplecov_spec.rb +0 -109
  133. data/spec/source_file_line_spec.rb +0 -155
  134. data/spec/source_file_spec.rb +0 -145
  135. data/spec/support/fail_rspec_on_ruby_warning.rb +0 -75
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA256:
3
- metadata.gz: f8f001c1d4f9343c21eee5371b68f31a56caf35b752a08a662115418176a6156
4
- data.tar.gz: 519eaaee340436685bc0c31a61d9fc1356072e1d39d573bce8049afe79332252
2
+ SHA1:
3
+ metadata.gz: 47d20d0dc990b18c8ac6bcc24755bb66521230c3
4
+ data.tar.gz: 22c23ddd73f1052aa525905f82f7545f63207ee7
5
5
  SHA512:
6
- metadata.gz: 94a6c0d8f0245befdf662d339bae1b2e0d4a077d3591764f9c215f06453f9e86a40127d3fe5f7488875c470caf8743d19307352e72eaff6f5dfc2c657a828622
7
- data.tar.gz: eb674773b777504acba00508c7cc62f2e0f1451fb26d1a06463a822130e2cceeda4a8aba964569579becd62b7951f5968dbdd351549143cc81a69e1628923cad
6
+ metadata.gz: 320807d6f5176f76cb38f7fcbc6eb1e59b2e0cffcd4eb28bcf804f0eaf824b5a44926345f0516ae40a091ec866ad8e8aff43aed8536b5812bffabe5b6d2bc005
7
+ data.tar.gz: cf2c3e9a80d843f3970b3a0ac9ab5e21e81a18ea1ae306cebe74bc7f77bf6263115a1b6405547d26f608a574ab7a8d1da901d9d9a8524edee0e5a19241cd932d
@@ -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 classigied as irrelevant. See [#605](https://github.com/colszowka/simplecov/pull/605) (thanks @odlp)
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)
@@ -2,19 +2,21 @@
2
2
 
3
3
  You can report issues at https://github.com/colszowka/simplecov/issues
4
4
 
5
- Search existing issues for your problem, chances are someone else already reported it.
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 Github.
42
+ * Send me a pull request on GitHub.
41
43
 
42
44
  ## Running Individual Tests
43
45
 
44
- This project uses Test::Unit. Individual tests can be run like this:
46
+ This project uses RSpec and Cucumber. Individual tests can be run like this:
45
47
 
46
48
  ```bash
47
- ruby -I test path/to/test.rb
49
+ bundle exec rspec path/to/test.rb
50
+ bundle exec cucumber path/to/test.feature
48
51
  ```
@@ -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 Github, too][simplecov-html].
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', :require => false, :group => :test
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 4 or earlier, use the following configuration:
636
- # Disable Rails's static asset server (Apache or nginx will already do this)
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).
@@ -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
 
@@ -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
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  #
2
4
  # Helper that tries to find out what test suite is running (for SimpleCov.command_name)
3
5
  #
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "fileutils"
2
4
  require "docile"
3
5
  require "simplecov/formatter/multi_formatter"
@@ -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
- SimpleCov.profiles.define "root_filter" do
6
- # Exclude all files outside of simplecov root
7
- root_filter = nil
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 # rubocop:disable Metrics/BlockLength
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
- @exit_status = if $! # was an exception thrown?
58
- # if it was a SystemExit, use the accompanying status
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