simplecov 0.18.1 → 0.19.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 +224 -169
- data/CONTRIBUTING.md +3 -3
- data/ISSUE_TEMPLATE.md +1 -1
- data/README.md +67 -20
- data/doc/alternate-formatters.md +7 -2
- data/doc/commercial-services.md +5 -0
- data/lib/minitest/simplecov_plugin.rb +15 -0
- data/lib/simplecov.rb +117 -118
- data/lib/simplecov/combine.rb +2 -2
- data/lib/simplecov/combine/branches_combiner.rb +2 -2
- data/lib/simplecov/configuration.rb +52 -3
- data/lib/simplecov/coverage_statistics.rb +5 -5
- data/lib/simplecov/defaults.rb +8 -12
- data/lib/simplecov/exit_codes.rb +5 -0
- data/lib/simplecov/exit_codes/exit_code_handling.rb +29 -0
- data/lib/simplecov/exit_codes/maximum_coverage_drop_check.rb +50 -0
- data/lib/simplecov/exit_codes/minimum_coverage_by_file_check.rb +38 -0
- data/lib/simplecov/exit_codes/minimum_overall_coverage_check.rb +53 -0
- data/lib/simplecov/filter.rb +7 -5
- data/lib/simplecov/formatter.rb +2 -2
- data/lib/simplecov/formatter/multi_formatter.rb +5 -7
- data/lib/simplecov/lines_classifier.rb +1 -1
- data/lib/simplecov/no_defaults.rb +1 -1
- data/lib/simplecov/process.rb +19 -0
- data/lib/simplecov/result.rb +14 -12
- data/lib/simplecov/result_merger.rb +2 -7
- data/lib/simplecov/source_file.rb +46 -1
- data/lib/simplecov/useless_results_remover.rb +5 -3
- data/lib/simplecov/version.rb +1 -1
- metadata +18 -10
    
        data/CONTRIBUTING.md
    CHANGED
    
    | @@ -1,6 +1,6 @@ | |
| 1 1 | 
             
            ## Reporting Issues
         | 
| 2 2 |  | 
| 3 | 
            -
            You can report issues at https://github.com/ | 
| 3 | 
            +
            You can report issues at https://github.com/simplecov-ruby/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 |  | 
| @@ -10,7 +10,7 @@ To make sure that we can help you quickly please include and check the following | |
| 10 10 | 
             
                - please ensure you are requiring and starting SimpleCov before requiring any application code.
         | 
| 11 11 | 
             
                - If running via rake, please ensure you are requiring SimpleCov at the top of your Rakefile
         | 
| 12 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/ | 
| 13 | 
            +
                - Have you tried using a [`.simplecov` file](https://github.com/simplecov-ruby/simplecov#using-simplecov-for-centralized-config)?
         | 
| 14 14 | 
             
             * Include the SimpleCov version you are running in your report.
         | 
| 15 15 | 
             
             * If you are not running the latest version (please check), and you cannot update it,
         | 
| 16 16 | 
             
               please specify in your report why you can't update to the latest version.
         | 
| @@ -28,7 +28,7 @@ Thanks! | |
| 28 28 |  | 
| 29 29 | 
             
            To fetch & test the library for development, do:
         | 
| 30 30 |  | 
| 31 | 
            -
                $ git clone https://github.com/ | 
| 31 | 
            +
                $ git clone https://github.com/simplecov-ruby/simplecov.git
         | 
| 32 32 | 
             
                $ cd simplecov
         | 
| 33 33 | 
             
                $ bundle
         | 
| 34 34 | 
             
                $ bundle exec rake
         | 
    
        data/ISSUE_TEMPLATE.md
    CHANGED
    
    | @@ -8,7 +8,7 @@ To make sure that we can help you quickly please include and check the following | |
| 8 8 | 
             
                - please ensure you are requiring and starting SimpleCov before requiring any application code.
         | 
| 9 9 | 
             
                - If running via rake, please ensure you are requiring SimpleCov at the top of your Rakefile
         | 
| 10 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/ | 
| 11 | 
            +
                - Have you tried using a [`.simplecov` file](https://github.com/simplecov-ruby/simplecov#using-simplecov-for-centralized-config)?
         | 
| 12 12 | 
             
             * Include the SimpleCov version you are running in your report.
         | 
| 13 13 | 
             
             * If you are not running the latest version (please check), and you cannot update it,
         | 
| 14 14 | 
             
               please specify in your report why you can't update to the latest version.
         | 
    
        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.*
         | 
| @@ -167,8 +167,8 @@ to use SimpleCov with them. Here's an overview of the known ones: | |
| 167 167 | 
             
                  race conditions occur when results are merged.
         | 
| 168 168 | 
             
                </td>
         | 
| 169 169 | 
             
                <td>
         | 
| 170 | 
            -
                  <a href="https://github.com/ | 
| 171 | 
            -
                  <a href="https://github.com/ | 
| 170 | 
            +
                  <a href="https://github.com/simplecov-ruby/simplecov/issues/64">#64</a> &
         | 
| 171 | 
            +
                  <a href="https://github.com/simplecov-ruby/simplecov/pull/185">#185</a>
         | 
| 172 172 | 
             
                </td>
         | 
| 173 173 | 
             
              </tr>
         | 
| 174 174 | 
             
              <tr>
         | 
| @@ -192,7 +192,7 @@ to use SimpleCov with them. Here's an overview of the known ones: | |
| 192 192 | 
             
                  to explicitly set the output root using `SimpleCov.root('foo/bar/baz')`
         | 
| 193 193 | 
             
                </td>
         | 
| 194 194 | 
             
                <td>
         | 
| 195 | 
            -
                  <a href="https://github.com/ | 
| 195 | 
            +
                  <a href="https://github.com/simplecov-ruby/simplecov/issues/95">#95</a>
         | 
| 196 196 | 
             
                </td>
         | 
| 197 197 | 
             
              </tr>
         | 
| 198 198 | 
             
              <tr>
         | 
| @@ -203,11 +203,11 @@ to use SimpleCov with them. Here's an overview of the known ones: | |
| 203 203 | 
             
                  Because of how Spork works internally (using preforking), there used to
         | 
| 204 204 | 
             
                  be trouble when using SimpleCov with it, but that has apparently been
         | 
| 205 205 | 
             
                  resolved with a specific configuration strategy. See <a
         | 
| 206 | 
            -
                  href="https://github.com/ | 
| 206 | 
            +
                  href="https://github.com/simplecov-ruby/simplecov/issues/42#issuecomment-4440284">this</a>
         | 
| 207 207 | 
             
                  comment.
         | 
| 208 208 | 
             
                </td>
         | 
| 209 209 | 
             
                <td>
         | 
| 210 | 
            -
                  <a href="https://github.com/ | 
| 210 | 
            +
                  <a href="https://github.com/simplecov-ruby/simplecov/issues/42#issuecomment-4440284">#42</a>
         | 
| 211 211 | 
             
                </td>
         | 
| 212 212 | 
             
              </tr>
         | 
| 213 213 | 
             
              <tr>
         | 
| @@ -218,7 +218,7 @@ to use SimpleCov with them. Here's an overview of the known ones: | |
| 218 218 | 
             
                  <a href="#want-to-use-spring-with-simplecov">See section below.</a>
         | 
| 219 219 | 
             
                </td>
         | 
| 220 220 | 
             
                <td>
         | 
| 221 | 
            -
                  <a href="https://github.com/ | 
| 221 | 
            +
                  <a href="https://github.com/simplecov-ruby/simplecov/issues/381">#381</a>
         | 
| 222 222 | 
             
                </td>
         | 
| 223 223 | 
             
              </tr>
         | 
| 224 224 | 
             
              <tr>
         | 
| @@ -231,7 +231,7 @@ to use SimpleCov with them. Here's an overview of the known ones: | |
| 231 231 | 
             
                  (Dec 11th, 2011) should have this problem resolved.
         | 
| 232 232 | 
             
                </td>
         | 
| 233 233 | 
             
                <td>
         | 
| 234 | 
            -
                  <a href="https://github.com/ | 
| 234 | 
            +
                  <a href="https://github.com/simplecov-ruby/simplecov/issues/45">#45</a> &
         | 
| 235 235 | 
             
                  <a href="https://github.com/test-unit/test-unit/pull/12">test-unit/test-unit#12</a>
         | 
| 236 236 | 
             
                </td>
         | 
| 237 237 | 
             
              </tr>
         | 
| @@ -429,7 +429,7 @@ end | |
| 429 429 | 
             
            # :nocov:
         | 
| 430 430 | 
             
            ```
         | 
| 431 431 |  | 
| 432 | 
            -
            The name of the token can be changed to your liking. [Learn more about the nocov feature.]( https://github.com/ | 
| 432 | 
            +
            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 433 |  | 
| 434 434 | 
             
            **Note:** You shouldn't have to use the nocov token to skip private methods that are being included in your coverage. If
         | 
| 435 435 | 
             
            you appropriately test the public interface of your classes and objects you should automatically get full coverage of
         | 
| @@ -440,7 +440,7 @@ your private methods. | |
| 440 440 | 
             
            By default, SimpleCov filters everything outside of the `SimpleCov.root` directory. However, sometimes you may want
         | 
| 441 441 | 
             
            to include coverage reports for things you include as a gem, for example a Rails Engine.
         | 
| 442 442 |  | 
| 443 | 
            -
            Here's an example by [@lsaffie](https://github.com/lsaffie) from [#221](https://github.com/ | 
| 443 | 
            +
            Here's an example by [@lsaffie](https://github.com/lsaffie) from [#221](https://github.com/simplecov-ruby/simplecov/issues/221)
         | 
| 444 444 | 
             
            that shows how you can achieve just that:
         | 
| 445 445 |  | 
| 446 446 | 
             
            ```ruby
         | 
| @@ -614,6 +614,53 @@ namespace :coverage do | |
| 614 614 | 
             
            end
         | 
| 615 615 | 
             
            ```
         | 
| 616 616 |  | 
| 617 | 
            +
            ## Running simplecov against subprocesses
         | 
| 618 | 
            +
             | 
| 619 | 
            +
            `SimpleCov.enable_for_subprocesses` will allow SimpleCov to observe subprocesses starting using `Process.fork`.
         | 
| 620 | 
            +
            This modifies ruby's core Process.fork method so that SimpleCov can see into it, appending `" (subprocess #{pid})"`
         | 
| 621 | 
            +
            to the `SimpleCov.command_name`, with results that can be merged together using SimpleCov's merging feature.
         | 
| 622 | 
            +
             | 
| 623 | 
            +
            To configure this, use `.at_fork`.
         | 
| 624 | 
            +
             | 
| 625 | 
            +
            ```ruby
         | 
| 626 | 
            +
            SimpleCov.enable_for_subprocesses true
         | 
| 627 | 
            +
            SimpleCov.at_fork do |pid|
         | 
| 628 | 
            +
              # This needs a unique name so it won't be ovewritten
         | 
| 629 | 
            +
              SimpleCov.command_name "#{SimpleCov.command_name} (subprocess: #{pid})"
         | 
| 630 | 
            +
              # be quiet, the parent process will be in charge of output and checking coverage totals
         | 
| 631 | 
            +
              SimpleCov.print_error_status = false
         | 
| 632 | 
            +
              SimpleCov.formatter SimpleCov::Formatter::SimpleFormatter
         | 
| 633 | 
            +
              SimpleCov.minimum_coverage 0
         | 
| 634 | 
            +
              # start
         | 
| 635 | 
            +
              SimpleCov.start
         | 
| 636 | 
            +
            end
         | 
| 637 | 
            +
            ```
         | 
| 638 | 
            +
             | 
| 639 | 
            +
            NOTE: SimpleCov must have already been started before `Process.fork` was called.
         | 
| 640 | 
            +
             | 
| 641 | 
            +
            ### Running simplecov against spawned subprocesses
         | 
| 642 | 
            +
             | 
| 643 | 
            +
            Perhaps you're testing a ruby script with `PTY.spawn` or `Open3.popen`, or `Process.spawn` or etc.
         | 
| 644 | 
            +
            SimpleCov can cover this too.
         | 
| 645 | 
            +
             | 
| 646 | 
            +
            Add a .simplecov_spawn.rb file to your project root
         | 
| 647 | 
            +
            ```ruby
         | 
| 648 | 
            +
            # .simplecov_spawn.rb
         | 
| 649 | 
            +
            require 'simplecov' # this will also pick up whatever config is in .simplecov
         | 
| 650 | 
            +
                                # so ensure it just contains configuration, and doesn't call SimpleCov.start.
         | 
| 651 | 
            +
            SimpleCov.command_name 'spawn' # As this is not for a test runner directly, script doesn't have a pre-defined base command_name
         | 
| 652 | 
            +
            SimpleCov.at_fork.call(Process.pid) # Use the per-process setup described previously
         | 
| 653 | 
            +
            SimpleCov.start # only now can we start.
         | 
| 654 | 
            +
            ```
         | 
| 655 | 
            +
            Then, instead of calling your script directly, like:
         | 
| 656 | 
            +
            ```ruby
         | 
| 657 | 
            +
            PTY.spawn('my_script.rb') do # ...
         | 
| 658 | 
            +
            ```
         | 
| 659 | 
            +
            Use bin/ruby to require the new .simplecov_spawn file, then your script
         | 
| 660 | 
            +
            ```ruby
         | 
| 661 | 
            +
            PTY.spawn('ruby -r./.simplecov_spawn my_script.rb') do # ...
         | 
| 662 | 
            +
            ```
         | 
| 663 | 
            +
             | 
| 617 664 | 
             
            ## Running coverage only on demand
         | 
| 618 665 |  | 
| 619 666 | 
             
            The Ruby STDLIB Coverage library that SimpleCov builds upon is *very* fast (on a ~10 min Rails test suite, the speed
         | 
| @@ -794,7 +841,7 @@ SimpleCov.formatters = SimpleCov::Formatter::MultiFormatter.new([ | |
| 794 841 |  | 
| 795 842 | 
             
            ## Ruby version compatibility
         | 
| 796 843 |  | 
| 797 | 
            -
            SimpleCov is built in [Continuous Integration] on Ruby 2. | 
| 844 | 
            +
            SimpleCov is built in [Continuous Integration] on Ruby 2.5+ as well as JRuby 9.2+.
         | 
| 798 845 |  | 
| 799 846 | 
             
            Note for JRuby => You need to pass JRUBY_OPTS="--debug" or create .jrubyrc and add debug.fullTrace=true
         | 
| 800 847 |  | 
| @@ -809,7 +856,7 @@ with them, you'll find that it often misreports coverage with the default config | |
| 809 856 | 
             
            issue. Don't despair!
         | 
| 810 857 |  | 
| 811 858 | 
             
            One solution is to [explicitly call eager
         | 
| 812 | 
            -
            load](https://github.com/ | 
| 859 | 
            +
            load](https://github.com/simplecov-ruby/simplecov/issues/381#issuecomment-347651728)
         | 
| 813 860 | 
             
            in your `test_helper.rb` / `spec_helper.rb` after calling `SimpleCov.start`.
         | 
| 814 861 |  | 
| 815 862 | 
             
            ```ruby
         | 
| @@ -868,7 +915,7 @@ Everyone participating in this project's development, issue trackers and other c | |
| 868 915 |  | 
| 869 916 | 
             
            ## Contributing
         | 
| 870 917 |  | 
| 871 | 
            -
            See the [contributing guide](https://github.com/ | 
| 918 | 
            +
            See the [contributing guide](https://github.com/simplecov-ruby/simplecov/blob/main/CONTRIBUTING.md).
         | 
| 872 919 |  | 
| 873 920 | 
             
            ## Kudos
         | 
| 874 921 |  | 
    
        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,7 @@ 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-material(https://github.com/chiefpansancolt/simplecov-material)
         | 
| 63 | 
            +
            #### [simplecov-material](https://github.com/chiefpansancolt/simplecov-material)
         | 
| 59 64 | 
             
            *by [Chiefpansancolt](https://github.com/chiefpansancolt)*
         | 
| 60 65 |  | 
| 61 66 | 
             
            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 |  | 
| @@ -0,0 +1,15 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            # How minitest plugins. See https://github.com/simplecov-ruby/simplecov/pull/756 for why we need this.
         | 
| 4 | 
            +
            # https://github.com/seattlerb/minitest#writing-extensions
         | 
| 5 | 
            +
            module Minitest
         | 
| 6 | 
            +
              def self.plugin_simplecov_init(_options)
         | 
| 7 | 
            +
                if defined?(SimpleCov)
         | 
| 8 | 
            +
                  SimpleCov.external_at_exit = true
         | 
| 9 | 
            +
             | 
| 10 | 
            +
                  Minitest.after_run do
         | 
| 11 | 
            +
                    SimpleCov.at_exit_behavior
         | 
| 12 | 
            +
                  end
         | 
| 13 | 
            +
                end
         | 
| 14 | 
            +
              end
         | 
| 15 | 
            +
            end
         | 
    
        data/lib/simplecov.rb
    CHANGED
    
    | @@ -7,8 +7,8 @@ if defined?(JRUBY_VERSION) && defined?(JRuby) | |
| 7 7 |  | 
| 8 8 | 
             
              # @see https://github.com/jruby/jruby/issues/1196
         | 
| 9 9 | 
             
              # @see https://github.com/metricfu/metric_fu/pull/226
         | 
| 10 | 
            -
              # @see https://github.com/ | 
| 11 | 
            -
              # @see https://github.com/ | 
| 10 | 
            +
              # @see https://github.com/simplecov-ruby/simplecov/issues/420
         | 
| 11 | 
            +
              # @see https://github.com/simplecov-ruby/simplecov/issues/86
         | 
| 12 12 | 
             
              # @see https://jira.codehaus.org/browse/JRUBY-6106
         | 
| 13 13 |  | 
| 14 14 | 
             
              unless org.jruby.RubyInstanceConfig.FULL_TRACE_ENABLED
         | 
| @@ -23,9 +23,12 @@ end | |
| 23 23 | 
             
            #
         | 
| 24 24 | 
             
            module SimpleCov
         | 
| 25 25 | 
             
              class << self
         | 
| 26 | 
            -
                attr_accessor :running
         | 
| 27 | 
            -
             | 
| 28 | 
            -
                 | 
| 26 | 
            +
                attr_accessor :running, :pid
         | 
| 27 | 
            +
             | 
| 28 | 
            +
                # Basically, should we take care of at_exit behavior or something else?
         | 
| 29 | 
            +
                # Used by the minitest plugin. See lib/minitest/simplecov_plugin.rb
         | 
| 30 | 
            +
                attr_accessor :external_at_exit
         | 
| 31 | 
            +
                alias external_at_exit? external_at_exit
         | 
| 29 32 |  | 
| 30 33 | 
             
                #
         | 
| 31 34 | 
             
                # Sets up SimpleCov to run against your project.
         | 
| @@ -47,6 +50,9 @@ module SimpleCov | |
| 47 50 | 
             
                def start(profile = nil, &block)
         | 
| 48 51 | 
             
                  require "coverage"
         | 
| 49 52 | 
             
                  initial_setup(profile, &block)
         | 
| 53 | 
            +
                  require_relative "./simplecov/process" if SimpleCov.enabled_for_subprocesses?
         | 
| 54 | 
            +
                  make_parallel_tests_available
         | 
| 55 | 
            +
             | 
| 50 56 | 
             
                  @result = nil
         | 
| 51 57 | 
             
                  self.pid = Process.pid
         | 
| 52 58 |  | 
| @@ -79,13 +85,11 @@ module SimpleCov | |
| 79 85 |  | 
| 80 86 | 
             
                  results = result_filenames.flat_map do |filename|
         | 
| 81 87 | 
             
                    # Re-create each included instance of SimpleCov::Result from the stored run data.
         | 
| 82 | 
            -
                    (JSON.parse(File.read(filename)) || {}) | 
| 83 | 
            -
                      SimpleCov::Result.from_hash(command_name => coverage)
         | 
| 84 | 
            -
                    end
         | 
| 88 | 
            +
                    Result.from_hash(JSON.parse(File.read(filename)) || {})
         | 
| 85 89 | 
             
                  end
         | 
| 86 90 |  | 
| 87 91 | 
             
                  # Use the ResultMerger to produce a single, merged result, ready to use.
         | 
| 88 | 
            -
                  @result =  | 
| 92 | 
            +
                  @result = ResultMerger.merge_and_store(*results)
         | 
| 89 93 |  | 
| 90 94 | 
             
                  run_exit_tasks!
         | 
| 91 95 | 
             
                end
         | 
| @@ -98,7 +102,6 @@ module SimpleCov | |
| 98 102 | 
             
                  return @result if result?
         | 
| 99 103 |  | 
| 100 104 | 
             
                  # Collect our coverage result
         | 
| 101 | 
            -
             | 
| 102 105 | 
             
                  process_coverage_result if running
         | 
| 103 106 |  | 
| 104 107 | 
             
                  # If we're using merging of results, store the current result
         | 
| @@ -168,46 +171,71 @@ module SimpleCov | |
| 168 171 | 
             
                  @result = nil
         | 
| 169 172 | 
             
                end
         | 
| 170 173 |  | 
| 174 | 
            +
                def at_exit_behavior
         | 
| 175 | 
            +
                  # If we are in a different process than called start, don't interfere.
         | 
| 176 | 
            +
                  return if SimpleCov.pid != Process.pid
         | 
| 177 | 
            +
             | 
| 178 | 
            +
                  # If SimpleCov is no longer running then don't run exit tasks
         | 
| 179 | 
            +
                  SimpleCov.run_exit_tasks! if SimpleCov.running
         | 
| 180 | 
            +
                end
         | 
| 181 | 
            +
             | 
| 182 | 
            +
                # @api private
         | 
| 171 183 | 
             
                #
         | 
| 172 | 
            -
                #  | 
| 173 | 
            -
                # This will get called inside the at_exit block
         | 
| 184 | 
            +
                # Called from at_exit block
         | 
| 174 185 | 
             
                #
         | 
| 175 | 
            -
                def  | 
| 176 | 
            -
                   | 
| 186 | 
            +
                def run_exit_tasks!
         | 
| 187 | 
            +
                  error_exit_status = exit_status_from_exception
         | 
| 188 | 
            +
             | 
| 189 | 
            +
                  at_exit.call
         | 
| 190 | 
            +
             | 
| 191 | 
            +
                  exit_and_report_previous_error(error_exit_status) if previous_error?(error_exit_status)
         | 
| 192 | 
            +
                  process_results_and_report_error if ready_to_process_results?
         | 
| 177 193 | 
             
                end
         | 
| 178 194 |  | 
| 195 | 
            +
                #
         | 
| 196 | 
            +
                # @api private
         | 
| 179 197 | 
             
                #
         | 
| 180 198 | 
             
                # Returns the exit status from the exit exception
         | 
| 181 199 | 
             
                #
         | 
| 182 200 | 
             
                def exit_status_from_exception
         | 
| 183 | 
            -
                   | 
| 201 | 
            +
                  # Capture the current exception if it exists
         | 
| 202 | 
            +
                  @exit_exception = $ERROR_INFO
         | 
| 203 | 
            +
                  return nil unless @exit_exception
         | 
| 184 204 |  | 
| 185 | 
            -
                  if exit_exception.is_a?(SystemExit)
         | 
| 186 | 
            -
                    exit_exception.status
         | 
| 205 | 
            +
                  if @exit_exception.is_a?(SystemExit)
         | 
| 206 | 
            +
                    @exit_exception.status
         | 
| 187 207 | 
             
                  else
         | 
| 188 208 | 
             
                    SimpleCov::ExitCodes::EXCEPTION
         | 
| 189 209 | 
             
                  end
         | 
| 190 210 | 
             
                end
         | 
| 191 211 |  | 
| 192 212 | 
             
                # @api private
         | 
| 213 | 
            +
                def previous_error?(error_exit_status)
         | 
| 214 | 
            +
                  # Normally it'd be enough to check for previous error but when running test_unit
         | 
| 215 | 
            +
                  # status is 0
         | 
| 216 | 
            +
                  error_exit_status && error_exit_status != SimpleCov::ExitCodes::SUCCESS
         | 
| 217 | 
            +
                end
         | 
| 218 | 
            +
             | 
| 193 219 | 
             
                #
         | 
| 194 | 
            -
                #  | 
| 220 | 
            +
                # @api private
         | 
| 195 221 | 
             
                #
         | 
| 196 | 
            -
                 | 
| 197 | 
            -
             | 
| 198 | 
            -
             | 
| 199 | 
            -
                  exit_status | 
| 222 | 
            +
                # Thinking: Move this behavior earlier so if there was an error we do nothing?
         | 
| 223 | 
            +
                def exit_and_report_previous_error(exit_status)
         | 
| 224 | 
            +
                  warn("Stopped processing SimpleCov as a previous error not related to SimpleCov has been detected") if print_error_status
         | 
| 225 | 
            +
                  Kernel.exit(exit_status)
         | 
| 226 | 
            +
                end
         | 
| 200 227 |  | 
| 201 | 
            -
             | 
| 228 | 
            +
                # @api private
         | 
| 229 | 
            +
                def ready_to_process_results?
         | 
| 230 | 
            +
                  final_result_process? && result?
         | 
| 231 | 
            +
                end
         | 
| 202 232 |  | 
| 203 | 
            -
             | 
| 204 | 
            -
                   | 
| 205 | 
            -
                  exit_status = SimpleCov.process_result(SimpleCov.result, exit_status) if SimpleCov.result?
         | 
| 233 | 
            +
                def process_results_and_report_error
         | 
| 234 | 
            +
                  exit_status = process_result(result)
         | 
| 206 235 |  | 
| 207 236 | 
             
                  # Force exit with stored status (see github issue #5)
         | 
| 208 | 
            -
                   | 
| 209 | 
            -
             | 
| 210 | 
            -
                    $stderr.printf("SimpleCov failed with exit %<exit_status>d\n", exit_status: exit_status) if print_error_status
         | 
| 237 | 
            +
                  if exit_status.positive?
         | 
| 238 | 
            +
                    warn("SimpleCov failed with exit #{exit_status} due to a coverage related error") if print_error_status
         | 
| 211 239 | 
             
                    Kernel.exit exit_status
         | 
| 212 240 | 
             
                  end
         | 
| 213 241 | 
             
                end
         | 
| @@ -217,55 +245,29 @@ module SimpleCov | |
| 217 245 | 
             
                # Usage:
         | 
| 218 246 | 
             
                #   exit_status = SimpleCov.process_result(SimpleCov.result, exit_status)
         | 
| 219 247 | 
             
                #
         | 
| 220 | 
            -
                def process_result(result | 
| 221 | 
            -
                   | 
| 222 | 
            -
             | 
| 223 | 
            -
                   | 
| 224 | 
            -
                  result_exit_status = result_exit_status(result, covered_percent)
         | 
| 225 | 
            -
                  write_last_run(covered_percent) if result_exit_status == SimpleCov::ExitCodes::SUCCESS # No result errors
         | 
| 226 | 
            -
                  final_result_process? ? result_exit_status : SimpleCov::ExitCodes::SUCCESS
         | 
| 248 | 
            +
                def process_result(result)
         | 
| 249 | 
            +
                  result_exit_status = result_exit_status(result)
         | 
| 250 | 
            +
                  write_last_run(result) if result_exit_status == SimpleCov::ExitCodes::SUCCESS
         | 
| 251 | 
            +
                  result_exit_status
         | 
| 227 252 | 
             
                end
         | 
| 228 253 |  | 
| 229 254 | 
             
                # @api private
         | 
| 230 | 
            -
                 | 
| 231 | 
            -
                 | 
| 232 | 
            -
             | 
| 233 | 
            -
             | 
| 234 | 
            -
             | 
| 235 | 
            -
             | 
| 236 | 
            -
             | 
| 237 | 
            -
                   | 
| 238 | 
            -
                    $stderr.printf(
         | 
| 239 | 
            -
                      "File (%<file>s) is only (%<least_covered_percentage>.2f%%) covered. This is below the expected minimum coverage per file of (%<min_coverage>.2f%%).\n",
         | 
| 240 | 
            -
                      file: result.least_covered_file,
         | 
| 241 | 
            -
                      least_covered_percentage: covered_percentages.min,
         | 
| 242 | 
            -
                      min_coverage: SimpleCov.minimum_coverage_by_file
         | 
| 243 | 
            -
                    )
         | 
| 244 | 
            -
                    SimpleCov::ExitCodes::MINIMUM_COVERAGE
         | 
| 245 | 
            -
                  elsif (last_run = SimpleCov::LastRun.read)
         | 
| 246 | 
            -
                    coverage_diff = last_run[:result][:covered_percent] - covered_percent
         | 
| 247 | 
            -
                    if coverage_diff > SimpleCov.maximum_coverage_drop
         | 
| 248 | 
            -
                      $stderr.printf(
         | 
| 249 | 
            -
                        "Coverage has dropped by %<drop_percent>.2f%% since the last time (maximum allowed: %<max_drop>.2f%%).\n",
         | 
| 250 | 
            -
                        drop_percent: coverage_diff,
         | 
| 251 | 
            -
                        max_drop: SimpleCov.maximum_coverage_drop
         | 
| 252 | 
            -
                      )
         | 
| 253 | 
            -
                      SimpleCov::ExitCodes::MAXIMUM_COVERAGE_DROP
         | 
| 254 | 
            -
                    else
         | 
| 255 | 
            -
                      SimpleCov::ExitCodes::SUCCESS
         | 
| 256 | 
            -
                    end
         | 
| 257 | 
            -
                  else
         | 
| 258 | 
            -
                    SimpleCov::ExitCodes::SUCCESS
         | 
| 259 | 
            -
                  end
         | 
| 255 | 
            +
                CoverageLimits = Struct.new(:minimum_coverage, :minimum_coverage_by_file, :maximum_coverage_drop, keyword_init: true)
         | 
| 256 | 
            +
                def result_exit_status(result)
         | 
| 257 | 
            +
                  coverage_limits = CoverageLimits.new(
         | 
| 258 | 
            +
                    minimum_coverage: minimum_coverage, minimum_coverage_by_file: minimum_coverage_by_file,
         | 
| 259 | 
            +
                    maximum_coverage_drop: maximum_coverage_drop
         | 
| 260 | 
            +
                  )
         | 
| 261 | 
            +
             | 
| 262 | 
            +
                  ExitCodes::ExitCodeHandling.call(result, coverage_limits: coverage_limits)
         | 
| 260 263 | 
             
                end
         | 
| 261 | 
            -
                # rubocop:enable Metrics/MethodLength
         | 
| 262 264 |  | 
| 263 265 | 
             
                #
         | 
| 264 266 | 
             
                # @api private
         | 
| 265 267 | 
             
                #
         | 
| 266 268 | 
             
                def final_result_process?
         | 
| 267 | 
            -
                  # checking for ENV["TEST_ENV_NUMBER"] to determine if the  | 
| 268 | 
            -
                  !defined?(ParallelTests) || !ENV["TEST_ENV_NUMBER"] || ParallelTests. | 
| 269 | 
            +
                  # checking for ENV["TEST_ENV_NUMBER"] to determine if the tests are being run in parallel
         | 
| 270 | 
            +
                  !defined?(ParallelTests) || !ENV["TEST_ENV_NUMBER"] || ParallelTests.last_process?
         | 
| 269 271 | 
             
                end
         | 
| 270 272 |  | 
| 271 273 | 
             
                #
         | 
| @@ -280,8 +282,16 @@ module SimpleCov | |
| 280 282 | 
             
                #
         | 
| 281 283 | 
             
                # @api private
         | 
| 282 284 | 
             
                #
         | 
| 283 | 
            -
                def write_last_run( | 
| 284 | 
            -
                  SimpleCov::LastRun.write(result: {covered_percent: covered_percent})
         | 
| 285 | 
            +
                def write_last_run(result)
         | 
| 286 | 
            +
                  SimpleCov::LastRun.write(result: {covered_percent: round_coverage(result.covered_percent)})
         | 
| 287 | 
            +
                end
         | 
| 288 | 
            +
             | 
| 289 | 
            +
                #
         | 
| 290 | 
            +
                # @api private
         | 
| 291 | 
            +
                #
         | 
| 292 | 
            +
                # Rounding down to be extra strict, see #679
         | 
| 293 | 
            +
                def round_coverage(coverage)
         | 
| 294 | 
            +
                  coverage.floor(2)
         | 
| 285 295 | 
             
                end
         | 
| 286 296 |  | 
| 287 297 | 
             
              private
         | 
| @@ -302,7 +312,7 @@ module SimpleCov | |
| 302 312 | 
             
                  # This blog post gives a good run down of the coverage criterias introduced
         | 
| 303 313 | 
             
                  # in Ruby 2.5: https://blog.bigbinary.com/2018/04/11/ruby-2-5-supports-measuring-branch-and-method-coverages.html
         | 
| 304 314 | 
             
                  # There is also a nice writeup of the different coverage criteria made in this
         | 
| 305 | 
            -
                  # comment  https://github.com/ | 
| 315 | 
            +
                  # comment  https://github.com/simplecov-ruby/simplecov/pull/692#discussion_r281836176 :
         | 
| 306 316 | 
             
                  # Ruby < 2.5:
         | 
| 307 317 | 
             
                  # https://github.com/ruby/ruby/blob/v1_9_3_374/ext/coverage/coverage.c
         | 
| 308 318 | 
             
                  # traditional mode (Array)
         | 
| @@ -406,61 +416,50 @@ module SimpleCov | |
| 406 416 | 
             
                  @result = SimpleCov::Result.new(add_not_loaded_files(@result))
         | 
| 407 417 | 
             
                end
         | 
| 408 418 |  | 
| 409 | 
            -
                 | 
| 410 | 
            -
             | 
| 411 | 
            -
             | 
| 412 | 
            -
             | 
| 413 | 
            -
                      minimum_expected: percent,
         | 
| 414 | 
            -
                      actual: result.coverage_statistics[criterion].percent
         | 
| 415 | 
            -
                    }
         | 
| 416 | 
            -
                  end
         | 
| 419 | 
            +
                # parallel_tests isn't always available, see: https://github.com/grosser/parallel_tests/issues/772
         | 
| 420 | 
            +
                def make_parallel_tests_available
         | 
| 421 | 
            +
                  return if defined?(ParallelTests)
         | 
| 422 | 
            +
                  return unless probably_running_parallel_tests?
         | 
| 417 423 |  | 
| 418 | 
            -
                   | 
| 419 | 
            -
             | 
| 420 | 
            -
                   | 
| 424 | 
            +
                  require "parallel_tests"
         | 
| 425 | 
            +
                rescue LoadError
         | 
| 426 | 
            +
                  warn("SimpleCov guessed you were running inside parallel tests but couldn't load it. Please file a bug report with us!")
         | 
| 421 427 | 
             
                end
         | 
| 422 428 |  | 
| 423 | 
            -
                def  | 
| 424 | 
            -
                   | 
| 425 | 
            -
                    $stderr.printf(
         | 
| 426 | 
            -
                      "%<criterion>s coverage (%<covered>.2f%%) is below the expected minimum coverage (%<minimum_coverage>.2f%%).\n",
         | 
| 427 | 
            -
                      covered: violation.fetch(:actual).floor(2),
         | 
| 428 | 
            -
                      minimum_coverage: violation.fetch(:minimum_expected),
         | 
| 429 | 
            -
                      criterion: violation.fetch(:criterion).capitalize
         | 
| 430 | 
            -
                    )
         | 
| 431 | 
            -
                  end
         | 
| 429 | 
            +
                def probably_running_parallel_tests?
         | 
| 430 | 
            +
                  ENV["TEST_ENV_NUMBER"] && ENV["PARALLEL_TEST_GROUPS"]
         | 
| 432 431 | 
             
                end
         | 
| 433 432 | 
             
              end
         | 
| 434 433 | 
             
            end
         | 
| 435 434 |  | 
| 436 | 
            -
             | 
| 435 | 
            +
            # requires are down here here for a load order reason I'm not sure what it is about
         | 
| 437 436 | 
             
            require "set"
         | 
| 438 437 | 
             
            require "forwardable"
         | 
| 439 | 
            -
             | 
| 438 | 
            +
            require_relative "simplecov/configuration"
         | 
| 440 439 | 
             
            SimpleCov.extend SimpleCov::Configuration
         | 
| 441 | 
            -
             | 
| 442 | 
            -
             | 
| 443 | 
            -
             | 
| 444 | 
            -
             | 
| 445 | 
            -
             | 
| 446 | 
            -
             | 
| 447 | 
            -
             | 
| 448 | 
            -
             | 
| 449 | 
            -
             | 
| 450 | 
            -
             | 
| 451 | 
            -
             | 
| 452 | 
            -
             | 
| 453 | 
            -
             | 
| 454 | 
            -
             | 
| 455 | 
            -
             | 
| 456 | 
            -
             | 
| 457 | 
            -
             | 
| 458 | 
            -
             | 
| 459 | 
            -
             | 
| 460 | 
            -
             | 
| 461 | 
            -
             | 
| 462 | 
            -
             | 
| 463 | 
            -
             | 
| 440 | 
            +
            require_relative "simplecov/coverage_statistics"
         | 
| 441 | 
            +
            require_relative "simplecov/exit_codes"
         | 
| 442 | 
            +
            require_relative "simplecov/profiles"
         | 
| 443 | 
            +
            require_relative "simplecov/source_file/line"
         | 
| 444 | 
            +
            require_relative "simplecov/source_file/branch"
         | 
| 445 | 
            +
            require_relative "simplecov/source_file"
         | 
| 446 | 
            +
            require_relative "simplecov/file_list"
         | 
| 447 | 
            +
            require_relative "simplecov/result"
         | 
| 448 | 
            +
            require_relative "simplecov/filter"
         | 
| 449 | 
            +
            require_relative "simplecov/formatter"
         | 
| 450 | 
            +
            require_relative "simplecov/last_run"
         | 
| 451 | 
            +
            require_relative "simplecov/lines_classifier"
         | 
| 452 | 
            +
            require_relative "simplecov/result_merger"
         | 
| 453 | 
            +
            require_relative "simplecov/command_guesser"
         | 
| 454 | 
            +
            require_relative "simplecov/version"
         | 
| 455 | 
            +
            require_relative "simplecov/result_adapter"
         | 
| 456 | 
            +
            require_relative "simplecov/combine"
         | 
| 457 | 
            +
            require_relative "simplecov/combine/branches_combiner"
         | 
| 458 | 
            +
            require_relative "simplecov/combine/files_combiner"
         | 
| 459 | 
            +
            require_relative "simplecov/combine/lines_combiner"
         | 
| 460 | 
            +
            require_relative "simplecov/combine/results_combiner"
         | 
| 461 | 
            +
            require_relative "simplecov/useless_results_remover"
         | 
| 462 | 
            +
            require_relative "simplecov/simulate_coverage"
         | 
| 464 463 |  | 
| 465 464 | 
             
            # Load default config
         | 
| 466 | 
            -
             | 
| 465 | 
            +
            require_relative "simplecov/defaults" unless ENV["SIMPLECOV_NO_DEFAULTS"]
         |