simplecov 0.6.0 → 0.22.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (131) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +163 -80
  3. data/LICENSE +1 -1
  4. data/README.md +776 -277
  5. data/doc/alternate-formatters.md +71 -0
  6. data/doc/commercial-services.md +25 -0
  7. data/doc/editor-integration.md +18 -0
  8. data/lib/minitest/simplecov_plugin.rb +15 -0
  9. data/lib/simplecov/combine/branches_combiner.rb +32 -0
  10. data/lib/simplecov/combine/files_combiner.rb +24 -0
  11. data/lib/simplecov/combine/lines_combiner.rb +43 -0
  12. data/lib/simplecov/combine/results_combiner.rb +60 -0
  13. data/lib/simplecov/combine.rb +30 -0
  14. data/lib/simplecov/command_guesser.rb +53 -38
  15. data/lib/simplecov/configuration.rb +478 -193
  16. data/lib/simplecov/coverage_statistics.rb +56 -0
  17. data/lib/simplecov/default_formatter.rb +20 -0
  18. data/lib/simplecov/defaults.rb +40 -44
  19. data/lib/simplecov/exit_codes/exit_code_handling.rb +29 -0
  20. data/lib/simplecov/exit_codes/maximum_coverage_drop_check.rb +83 -0
  21. data/lib/simplecov/exit_codes/minimum_coverage_by_file_check.rb +54 -0
  22. data/lib/simplecov/exit_codes/minimum_overall_coverage_check.rb +53 -0
  23. data/lib/simplecov/exit_codes.rb +15 -0
  24. data/lib/simplecov/file_list.rb +112 -36
  25. data/lib/simplecov/filter.rb +54 -4
  26. data/lib/simplecov/formatter/multi_formatter.rb +32 -0
  27. data/lib/simplecov/formatter/simple_formatter.rb +21 -15
  28. data/lib/simplecov/formatter.rb +4 -1
  29. data/lib/simplecov/last_run.rb +28 -0
  30. data/lib/simplecov/lines_classifier.rb +48 -0
  31. data/lib/simplecov/load_global_config.rb +8 -0
  32. data/lib/simplecov/no_defaults.rb +4 -0
  33. data/lib/simplecov/process.rb +19 -0
  34. data/lib/simplecov/profiles/bundler_filter.rb +5 -0
  35. data/lib/simplecov/profiles/hidden_filter.rb +5 -0
  36. data/lib/simplecov/profiles/rails.rb +18 -0
  37. data/lib/simplecov/profiles/root_filter.rb +10 -0
  38. data/lib/simplecov/profiles/test_frameworks.rb +8 -0
  39. data/lib/simplecov/profiles.rb +35 -0
  40. data/lib/simplecov/result.rb +33 -64
  41. data/lib/simplecov/result_adapter.rb +30 -0
  42. data/lib/simplecov/result_merger.rb +178 -64
  43. data/lib/simplecov/simulate_coverage.rb +29 -0
  44. data/lib/simplecov/source_file/branch.rb +84 -0
  45. data/lib/simplecov/source_file/line.rb +72 -0
  46. data/lib/simplecov/source_file.rb +304 -123
  47. data/lib/simplecov/useless_results_remover.rb +18 -0
  48. data/lib/simplecov/version.rb +4 -2
  49. data/lib/simplecov.rb +396 -49
  50. metadata +81 -242
  51. data/.gitignore +0 -30
  52. data/.rvmrc +0 -1
  53. data/.travis.yml +0 -13
  54. data/Gemfile +0 -9
  55. data/Rakefile +0 -16
  56. data/cucumber.yml +0 -13
  57. data/features/config_adapters.feature +0 -44
  58. data/features/config_autoload.feature +0 -46
  59. data/features/config_command_name.feature +0 -33
  60. data/features/config_coverage_dir.feature +0 -20
  61. data/features/config_deactivate_merging.feature +0 -42
  62. data/features/config_merge_timeout.feature +0 -38
  63. data/features/config_nocov_token.feature +0 -79
  64. data/features/config_project_name.feature +0 -27
  65. data/features/config_styles.feature +0 -93
  66. data/features/cucumber_basic.feature +0 -29
  67. data/features/merging_test_unit_and_rspec.feature +0 -44
  68. data/features/rspec_basic.feature +0 -31
  69. data/features/rspec_fails_on_initialization.feature +0 -14
  70. data/features/rspec_groups_and_filters_basic.feature +0 -29
  71. data/features/rspec_groups_and_filters_complex.feature +0 -35
  72. data/features/rspec_groups_using_filter_class.feature +0 -40
  73. data/features/rspec_without_simplecov.feature +0 -20
  74. data/features/skipping_code_blocks_manually.feature +0 -70
  75. data/features/step_definitions/html_steps.rb +0 -45
  76. data/features/step_definitions/simplecov_steps.rb +0 -61
  77. data/features/step_definitions/transformers.rb +0 -13
  78. data/features/step_definitions/web_steps.rb +0 -64
  79. data/features/support/env.rb +0 -26
  80. data/features/test_unit_basic.feature +0 -34
  81. data/features/test_unit_groups_and_filters_basic.feature +0 -29
  82. data/features/test_unit_groups_and_filters_complex.feature +0 -35
  83. data/features/test_unit_groups_using_filter_class.feature +0 -40
  84. data/features/test_unit_without_simplecov.feature +0 -20
  85. data/features/unicode_compatiblity.feature +0 -67
  86. data/lib/simplecov/adapters.rb +0 -29
  87. data/lib/simplecov/merge_helpers.rb +0 -39
  88. data/lib/simplecov/railtie.rb +0 -7
  89. data/lib/simplecov/railties/tasks.rake +0 -11
  90. data/simplecov.gemspec +0 -28
  91. data/test/faked_project/Gemfile +0 -6
  92. data/test/faked_project/Rakefile +0 -8
  93. data/test/faked_project/cucumber.yml +0 -13
  94. data/test/faked_project/features/step_definitions/my_steps.rb +0 -23
  95. data/test/faked_project/features/support/env.rb +0 -12
  96. data/test/faked_project/features/test_stuff.feature +0 -6
  97. data/test/faked_project/lib/faked_project/framework_specific.rb +0 -18
  98. data/test/faked_project/lib/faked_project/meta_magic.rb +0 -24
  99. data/test/faked_project/lib/faked_project/some_class.rb +0 -29
  100. data/test/faked_project/lib/faked_project.rb +0 -11
  101. data/test/faked_project/spec/faked_spec.rb +0 -11
  102. data/test/faked_project/spec/meta_magic_spec.rb +0 -10
  103. data/test/faked_project/spec/some_class_spec.rb +0 -10
  104. data/test/faked_project/spec/spec_helper.rb +0 -15
  105. data/test/faked_project/test/faked_test.rb +0 -11
  106. data/test/faked_project/test/meta_magic_test.rb +0 -13
  107. data/test/faked_project/test/some_class_test.rb +0 -15
  108. data/test/faked_project/test/test_helper.rb +0 -16
  109. data/test/fixtures/app/controllers/sample_controller.rb +0 -10
  110. data/test/fixtures/app/models/user.rb +0 -10
  111. data/test/fixtures/deleted_source_sample.rb +0 -15
  112. data/test/fixtures/frameworks/rspec_bad.rb +0 -9
  113. data/test/fixtures/frameworks/rspec_good.rb +0 -9
  114. data/test/fixtures/frameworks/testunit_bad.rb +0 -9
  115. data/test/fixtures/frameworks/testunit_good.rb +0 -9
  116. data/test/fixtures/resultset1.rb +0 -4
  117. data/test/fixtures/resultset2.rb +0 -5
  118. data/test/fixtures/sample.rb +0 -16
  119. data/test/fixtures/utf-8.rb +0 -3
  120. data/test/helper.rb +0 -35
  121. data/test/shoulda_macros.rb +0 -29
  122. data/test/test_1_8_fallbacks.rb +0 -33
  123. data/test/test_command_guesser.rb +0 -21
  124. data/test/test_deleted_source.rb +0 -16
  125. data/test/test_file_list.rb +0 -24
  126. data/test/test_filters.rb +0 -80
  127. data/test/test_merge_helpers.rb +0 -107
  128. data/test/test_result.rb +0 -147
  129. data/test/test_return_codes.rb +0 -39
  130. data/test/test_source_file.rb +0 -86
  131. data/test/test_source_file_line.rb +0 -110
@@ -0,0 +1,71 @@
1
+ ## Alternate coverage report formatters
2
+
3
+ The community around simplecov provides a whole bunch of alternate formatters beyond the official
4
+ [simplecov-html](https://github.com/simplecov-ruby/simplecov-html) gem.
5
+
6
+ If you have built or found one that is missing here, please send a Pull Request for this document!
7
+
8
+ #### [simplecov-badge](https://github.com/matthew342/simplecov-badge)
9
+ *by Matt Hale*
10
+
11
+ A formatter that generates a coverage badge for use in your project's readme using ImageMagick.
12
+
13
+ #### [simplecov-small-badge](https://github.com/marcgrimme/simplecov-small-badge)
14
+ *by Marc Grimme*
15
+
16
+ A formatter that generates a small coverage badge for use in your project's readme using the SVG.
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
+
23
+ #### [simplecov-cobertura](https://github.com/dashingrocket/simplecov-cobertura)
24
+ *by Jesse Bowes*
25
+
26
+ A formatter that generates Cobertura XML.
27
+
28
+ #### [simplecov-csv](https://github.com/fguillen/simplecov-csv)
29
+ *by Fernando Guillen*
30
+
31
+ CSV formatter for SimpleCov
32
+
33
+ #### [simplecov-erb](https://github.com/kpaulisse/simplecov-erb)
34
+ *by [Kevin Paulisse](https://github.com/kpaulisse)*
35
+
36
+ Flexible formatter that generates the output from an ERB template.
37
+
38
+ #### [simplecov-json](https://github.com/vicentllongo/simplecov-json)
39
+ *by Vicent Llongo*
40
+
41
+ JSON formatter for SimpleCov
42
+
43
+ #### [simplecov-lcov](https://github.com/fortissimo1997/simplecov-lcov)
44
+ *by fortissimo1997*
45
+
46
+ lcov formatter for SimpleCov
47
+
48
+ #### [simplecov-rcov](https://github.com/fguillen/simplecov-rcov)
49
+ *by Fernando Guillen*
50
+
51
+ "The target of this formatter is to cheat on Hudson so I can use the Ruby metrics plugin with SimpleCov."
52
+
53
+ #### [simplecov-single_file_reporter](https://github.com/grosser/simplecov-single_file_reporter)
54
+ *by [Michael Grosser](http://grosser.it)*
55
+
56
+ A formatter that prints the coverage of the file under test when you run a single test file.
57
+
58
+ #### [simplecov-t_wada](https://github.com/ysksn/simplecov-t_wada)
59
+ *by [Yosuke Kabuto](https://github.com/ysksn)*
60
+
61
+ t_wada AA formatter for SimpleCov
62
+
63
+ #### [simplecov-tailwindcss](https://github.com/chiefpansancolt/simplecov-tailwindcss)
64
+ *by [Chiefpansancolt](https://github.com/chiefpansancolt)*
65
+
66
+ A TailwindCSS & TailwindUI Designed HTML formatter with clean and easy search of files with a tabular left Navigation.
67
+
68
+ #### [simplecov-material](https://github.com/chiefpansancolt/simplecov-material)
69
+ *by [Chiefpansancolt](https://github.com/chiefpansancolt)*
70
+
71
+ A Material Designed HTML formatter with clean and easy search of files with a tabular left Navigation.
@@ -0,0 +1,25 @@
1
+ ## Commercial Services with SimpleCov integration
2
+
3
+ There is a bunch of services that offer integration with your existing CI pipeline and SimpleCov coverage
4
+ reports. Please note these are not associated with the SimpleCov project itself, so please report problems with
5
+ these integrations with their respective owners.
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
+
12
+ #### [codeclimate](https://github.com/codeclimate/ruby-test-reporter)
13
+ *by [Code Climate](https://codeclimate.com/)*
14
+
15
+ Upload coverage reports to [codeclimate.com](https://codeclimate.com/), a hosted software quality analysis and that also includes coverage reporting.
16
+
17
+ #### [codecov](https://github.com/codecov/codecov-ruby)
18
+ *by [Codecov](https://codecov.io/)*
19
+
20
+ Upload coverage reports to [codecov.io](https://codecov.io/), a hosted coverage reporting solution.
21
+
22
+ #### [coveralls](https://github.com/lemurheavy/coveralls-ruby)
23
+ *by [Coveralls](https://coveralls.io/)*
24
+
25
+ Upload coverage reports to [coveralls.io](https://coveralls.io/), a hosted coverage reporting solution.
@@ -0,0 +1,18 @@
1
+ ## Editor integration
2
+
3
+ Some editors have a graphical integration for the simplecov gem.
4
+
5
+ #### [Atom Editor: coverage](https://atom.io/packages/coverage)
6
+ *by Philip Giuliani*
7
+
8
+ Adds an overview of your current test coverage to Atom.
9
+
10
+ #### [Sublime Editor: Simple​Cov](https://packagecontrol.io/packages/SimpleCov)
11
+ *by sentience*
12
+
13
+ Adds in editor live coverage highlighting, status bar coverage information, and summary coverage information.
14
+
15
+ #### [cadre](https://github.com/nyarly/cadre)
16
+ *by Judson Lester*
17
+
18
+ Includes a formatter for Simplecov that emits a Vim script to mark up code files with coverage information.
@@ -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
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SimpleCov
4
+ module Combine
5
+ #
6
+ # Combine different branch coverage results on single file.
7
+ #
8
+ # Should be called through `SimpleCov.combine`.
9
+ module BranchesCombiner
10
+ module_function
11
+
12
+ #
13
+ # Return merged branches or the existed brach if other is missing.
14
+ #
15
+ # Branches inside files are always same if they exist, the difference only in coverage count.
16
+ # Branch coverage report for any conditional case is built from hash, it's key is a condition and
17
+ # it's body is a hash << keys from condition and value is coverage rate >>.
18
+ # ex: branches =>{ [:if, 3, 8, 6, 8, 36] => {[:then, 4, 8, 6, 8, 12] => 1, [:else, 5, 8, 6, 8, 36]=>2}, other conditions...}
19
+ # We create copy of result and update it values depending on the combined branches coverage values.
20
+ #
21
+ # @return [Hash]
22
+ #
23
+ def combine(coverage_a, coverage_b)
24
+ coverage_a.merge(coverage_b) do |_condition, branches_inside_a, branches_inside_b|
25
+ branches_inside_a.merge(branches_inside_b) do |_branch, a_count, b_count|
26
+ a_count + b_count
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SimpleCov
4
+ module Combine
5
+ #
6
+ # Handle combining two coverage results for same file
7
+ #
8
+ # Should be called through `SimpleCov.combine`.
9
+ module FilesCombiner
10
+ module_function
11
+
12
+ #
13
+ # Combines the results for 2 coverages of a file.
14
+ #
15
+ # @return [Hash]
16
+ #
17
+ def combine(coverage_a, coverage_b)
18
+ combination = {"lines" => Combine.combine(LinesCombiner, coverage_a["lines"], coverage_b["lines"])}
19
+ combination["branches"] = Combine.combine(BranchesCombiner, coverage_a["branches"], coverage_b["branches"]) if SimpleCov.branch_coverage?
20
+ combination
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SimpleCov
4
+ module Combine
5
+ #
6
+ # Combine two different lines coverage results on same file
7
+ #
8
+ # Should be called through `SimpleCov.combine`.
9
+ module LinesCombiner
10
+ module_function
11
+
12
+ def combine(coverage_a, coverage_b)
13
+ coverage_a
14
+ .zip(coverage_b)
15
+ .map do |coverage_a_val, coverage_b_val|
16
+ merge_line_coverage(coverage_a_val, coverage_b_val)
17
+ end
18
+ end
19
+
20
+ # Return depends on coverage in a specific line
21
+ #
22
+ # @param [Integer || nil] first_val
23
+ # @param [Integer || nil] second_val
24
+ #
25
+ # Logic:
26
+ #
27
+ # => nil + 0 = nil
28
+ # => nil + nil = nil
29
+ # => int + int = int
30
+ #
31
+ # @return [Integer || nil]
32
+ def merge_line_coverage(first_val, second_val)
33
+ sum = first_val.to_i + second_val.to_i
34
+
35
+ if sum.zero? && (first_val.nil? || second_val.nil?)
36
+ nil
37
+ else
38
+ sum
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SimpleCov
4
+ module Combine
5
+ # There might be reports from different kinds of tests,
6
+ # e.g. RSpec and Cucumber. We need to combine their results
7
+ # into unified one. This class does that.
8
+ # To unite the results on file basis, it leverages
9
+ # the combine of lines and branches inside each file within given results.
10
+ module ResultsCombiner
11
+ module_function
12
+
13
+ #
14
+ # Combine process explanation
15
+ # => ResultCombiner: define all present files between results and start combine on file level.
16
+ # ==> FileCombiner: collect result of next combine levels lines and branches.
17
+ # ===> LinesCombiner: combine lines results.
18
+ # ===> BranchesCombiner: combine branches results.
19
+ #
20
+ # @return [Hash]
21
+ #
22
+ def combine(*results)
23
+ results.reduce({}) do |combined_results, next_result|
24
+ combine_result_sets(combined_results, next_result)
25
+ end
26
+ end
27
+
28
+ #
29
+ # Manage combining results on files level
30
+ #
31
+ # @param [Hash] combined_results
32
+ # @param [Hash] result
33
+ #
34
+ # @return [Hash]
35
+ #
36
+ def combine_result_sets(combined_results, result)
37
+ results_files = combined_results.keys | result.keys
38
+
39
+ results_files.each_with_object({}) do |file_name, file_combination|
40
+ file_combination[file_name] = combine_file_coverage(
41
+ combined_results[file_name],
42
+ result[file_name]
43
+ )
44
+ end
45
+ end
46
+
47
+ #
48
+ # Combine two files coverage results
49
+ #
50
+ # @param [Hash] coverage_a
51
+ # @param [Hash] coverage_b
52
+ #
53
+ # @return [Hash]
54
+ #
55
+ def combine_file_coverage(coverage_a, coverage_b)
56
+ Combine.combine(Combine::FilesCombiner, coverage_a, coverage_b)
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SimpleCov
4
+ # Functionally for combining coverage results
5
+ #
6
+ module Combine
7
+ module_function
8
+
9
+ #
10
+ # Combine two coverage based on the given combiner_module.
11
+ #
12
+ # Combiners should always be called through this interface,
13
+ # as it takes care of short-circuiting of one of the coverages is nil.
14
+ #
15
+ # @return [Hash]
16
+ def combine(combiner_module, coverage_a, coverage_b)
17
+ return existing_coverage(coverage_a, coverage_b) if empty_coverage?(coverage_a, coverage_b)
18
+
19
+ combiner_module.combine(coverage_a, coverage_b)
20
+ end
21
+
22
+ def empty_coverage?(coverage_a, coverage_b)
23
+ !(coverage_a && coverage_b)
24
+ end
25
+
26
+ def existing_coverage(coverage_a, coverage_b)
27
+ coverage_a || coverage_b
28
+ end
29
+ end
30
+ end
@@ -1,49 +1,64 @@
1
- #
2
- # Helper that tries to find out what test suite is running (for SimpleCov.command_name)
3
- #
4
- module SimpleCov::CommandGuesser
5
- class << self
6
- # Storage for the original command line call that invoked the test suite.
7
- # This has got to be stored as early as possible because i.e. rake and test/unit 2
8
- # have a habit of tampering with ARGV, which makes i.e. the automatic distinction
9
- # between rails unit/functional/integration tests impossible without this cached
10
- # item.
11
- attr_accessor :original_run_command
12
-
13
- def guess
14
- from_command_line_options || from_defined_constants
15
- end
16
-
1
+ # frozen_string_literal: true
2
+
3
+ module SimpleCov
4
+ #
5
+ # Helper that tries to find out what test suite is running (for SimpleCov.command_name)
6
+ #
7
+ module CommandGuesser
8
+ class << self
9
+ # Storage for the original command line call that invoked the test suite.
10
+ # This has got to be stored as early as possible because i.e. rake and test/unit 2
11
+ # have a habit of tampering with ARGV, which makes i.e. the automatic distinction
12
+ # between rails unit/functional/integration tests impossible without this cached
13
+ # item.
14
+ attr_accessor :original_run_command
15
+
16
+ def guess
17
+ from_env || from_command_line_options || from_defined_constants
18
+ end
19
+
17
20
  private
18
-
19
- def from_command_line_options
20
- case original_run_command
21
- when /#{'test/functional/'}/
21
+
22
+ def from_env
23
+ # If being run from inside parallel_tests set the command name according to the process number
24
+ return unless ENV["PARALLEL_TEST_GROUPS"] && ENV["TEST_ENV_NUMBER"]
25
+
26
+ number = ENV["TEST_ENV_NUMBER"]
27
+ number = "1" if number.empty?
28
+ "(#{number}/#{ENV['PARALLEL_TEST_GROUPS']})"
29
+ end
30
+
31
+ def from_command_line_options
32
+ case original_run_command
33
+ when /test\/functional\//, /test\/\{.*functional.*\}\//
22
34
  "Functional Tests"
23
- when /#{'test/integration/'}/
35
+ when /test\/integration\//
24
36
  "Integration Tests"
25
- when /#{'test/'}/
37
+ when /test\//
26
38
  "Unit Tests"
39
+ when /spec/
40
+ "RSpec"
27
41
  when /cucumber/, /features/
28
42
  "Cucumber Features"
29
- when /spec/
43
+ end
44
+ end
45
+
46
+ def from_defined_constants
47
+ # If the command regexps fail, let's try checking defined constants.
48
+ if defined?(RSpec)
30
49
  "RSpec"
50
+ elsif defined?(Test::Unit)
51
+ "Unit Tests"
52
+ elsif defined?(Minitest)
53
+ "Minitest"
54
+ elsif defined?(MiniTest)
55
+ "MiniTest"
31
56
  else
32
- nil
33
- end
34
- end
35
-
36
- def from_defined_constants
37
- # If the command regexps fail, let's try checking defined constants.
38
- if defined?(RSpec)
39
- "RSpec"
40
- elsif defined?(Test::Unit)
41
- "Unit Tests"
42
- else
43
- # TODO: Provide link to docs/wiki article
44
- warn "SimpleCov failed to recognize the test framework and/or suite used. Please specify manually using SimpleCov.command_name 'Unit Tests'."
45
- 'Unknown Test Framework'
57
+ # TODO: Provide link to docs/wiki article
58
+ warn "SimpleCov failed to recognize the test framework and/or suite used. Please specify manually using SimpleCov.command_name 'Unit Tests'."
59
+ "Unknown Test Framework"
60
+ end
46
61
  end
47
62
  end
48
63
  end
49
- end
64
+ end