simplecov 0.15.1 → 0.18.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (147) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +74 -1
  3. data/CODE_OF_CONDUCT.md +76 -0
  4. data/CONTRIBUTING.md +12 -9
  5. data/ISSUE_TEMPLATE.md +23 -0
  6. data/{MIT-LICENSE → LICENSE} +0 -0
  7. data/README.md +205 -104
  8. data/doc/alternate-formatters.md +20 -0
  9. data/lib/simplecov.rb +246 -52
  10. data/lib/simplecov/combine.rb +30 -0
  11. data/lib/simplecov/combine/branches_combiner.rb +32 -0
  12. data/lib/simplecov/combine/files_combiner.rb +25 -0
  13. data/lib/simplecov/combine/lines_combiner.rb +43 -0
  14. data/lib/simplecov/combine/results_combiner.rb +60 -0
  15. data/lib/simplecov/command_guesser.rb +8 -3
  16. data/lib/simplecov/configuration.rb +79 -8
  17. data/lib/simplecov/defaults.rb +12 -81
  18. data/lib/simplecov/exit_codes.rb +2 -0
  19. data/lib/simplecov/file_list.rb +32 -3
  20. data/lib/simplecov/filter.rb +5 -2
  21. data/lib/simplecov/formatter.rb +2 -0
  22. data/lib/simplecov/formatter/multi_formatter.rb +4 -2
  23. data/lib/simplecov/formatter/simple_formatter.rb +6 -4
  24. data/lib/simplecov/last_run.rb +4 -0
  25. data/lib/simplecov/lines_classifier.rb +21 -5
  26. data/lib/simplecov/load_global_config.rb +2 -0
  27. data/lib/simplecov/no_defaults.rb +2 -0
  28. data/lib/simplecov/profiles.rb +11 -7
  29. data/lib/simplecov/profiles/bundler_filter.rb +5 -0
  30. data/lib/simplecov/profiles/hidden_filter.rb +5 -0
  31. data/lib/simplecov/profiles/rails.rb +18 -0
  32. data/lib/simplecov/profiles/root_filter.rb +10 -0
  33. data/lib/simplecov/profiles/test_frameworks.rb +8 -0
  34. data/lib/simplecov/result.rb +23 -4
  35. data/lib/simplecov/result_adapter.rb +30 -0
  36. data/lib/simplecov/result_merger.rb +14 -11
  37. data/lib/simplecov/simulate_coverage.rb +29 -0
  38. data/lib/simplecov/source_file.rb +222 -110
  39. data/lib/simplecov/source_file/branch.rb +106 -0
  40. data/lib/simplecov/source_file/line.rb +72 -0
  41. data/lib/simplecov/useless_results_remover.rb +16 -0
  42. data/lib/simplecov/version.rb +3 -1
  43. metadata +44 -162
  44. data/.gitignore +0 -31
  45. data/.rspec +0 -3
  46. data/.rubocop.yml +0 -88
  47. data/.travis.yml +0 -29
  48. data/.yardopts +0 -1
  49. data/Gemfile +0 -38
  50. data/Rakefile +0 -39
  51. data/cucumber.yml +0 -13
  52. data/features/config_autoload.feature +0 -46
  53. data/features/config_command_name.feature +0 -45
  54. data/features/config_coverage_dir.feature +0 -33
  55. data/features/config_deactivate_merging.feature +0 -42
  56. data/features/config_formatters.feature +0 -77
  57. data/features/config_merge_timeout.feature +0 -39
  58. data/features/config_nocov_token.feature +0 -79
  59. data/features/config_profiles.feature +0 -44
  60. data/features/config_project_name.feature +0 -27
  61. data/features/config_styles.feature +0 -121
  62. data/features/config_tracked_files.feature +0 -29
  63. data/features/config_tracked_files_relevant_lines.feature +0 -31
  64. data/features/cucumber_basic.feature +0 -29
  65. data/features/maximum_coverage_drop.feature +0 -89
  66. data/features/merging_test_unit_and_rspec.feature +0 -44
  67. data/features/minimum_coverage.feature +0 -59
  68. data/features/refuse_coverage_drop.feature +0 -95
  69. data/features/rspec_basic.feature +0 -32
  70. data/features/rspec_fails_on_initialization.feature +0 -14
  71. data/features/rspec_groups_and_filters_basic.feature +0 -29
  72. data/features/rspec_groups_and_filters_complex.feature +0 -37
  73. data/features/rspec_groups_using_filter_class.feature +0 -41
  74. data/features/rspec_without_simplecov.feature +0 -20
  75. data/features/skipping_code_blocks_manually.feature +0 -70
  76. data/features/step_definitions/html_steps.rb +0 -44
  77. data/features/step_definitions/simplecov_steps.rb +0 -68
  78. data/features/step_definitions/transformers.rb +0 -13
  79. data/features/step_definitions/web_steps.rb +0 -64
  80. data/features/support/aruba_freedom_patch.rb +0 -53
  81. data/features/support/env.rb +0 -50
  82. data/features/test_unit_basic.feature +0 -34
  83. data/features/test_unit_groups_and_filters_basic.feature +0 -29
  84. data/features/test_unit_groups_and_filters_complex.feature +0 -35
  85. data/features/test_unit_groups_using_filter_class.feature +0 -40
  86. data/features/test_unit_without_simplecov.feature +0 -20
  87. data/features/unicode_compatiblity.feature +0 -67
  88. data/lib/simplecov/jruby_fix.rb +0 -42
  89. data/lib/simplecov/railtie.rb +0 -7
  90. data/lib/simplecov/railties/tasks.rake +0 -11
  91. data/lib/simplecov/raw_coverage.rb +0 -39
  92. data/simplecov.gemspec +0 -27
  93. data/spec/1_8_fallbacks_spec.rb +0 -31
  94. data/spec/command_guesser_spec.rb +0 -48
  95. data/spec/config_loader_spec.rb +0 -14
  96. data/spec/configuration_spec.rb +0 -35
  97. data/spec/defaults_spec.rb +0 -41
  98. data/spec/deleted_source_spec.rb +0 -12
  99. data/spec/faked_project/Gemfile +0 -6
  100. data/spec/faked_project/Rakefile +0 -8
  101. data/spec/faked_project/cucumber.yml +0 -13
  102. data/spec/faked_project/features/step_definitions/my_steps.rb +0 -22
  103. data/spec/faked_project/features/support/env.rb +0 -12
  104. data/spec/faked_project/features/test_stuff.feature +0 -6
  105. data/spec/faked_project/lib/faked_project.rb +0 -11
  106. data/spec/faked_project/lib/faked_project/framework_specific.rb +0 -18
  107. data/spec/faked_project/lib/faked_project/meta_magic.rb +0 -24
  108. data/spec/faked_project/lib/faked_project/some_class.rb +0 -28
  109. data/spec/faked_project/lib/faked_project/untested_class.rb +0 -11
  110. data/spec/faked_project/spec/faked_spec.rb +0 -11
  111. data/spec/faked_project/spec/forking_spec.rb +0 -8
  112. data/spec/faked_project/spec/meta_magic_spec.rb +0 -15
  113. data/spec/faked_project/spec/some_class_spec.rb +0 -13
  114. data/spec/faked_project/spec/spec_helper.rb +0 -11
  115. data/spec/faked_project/test/faked_test.rb +0 -11
  116. data/spec/faked_project/test/meta_magic_test.rb +0 -13
  117. data/spec/faked_project/test/some_class_test.rb +0 -15
  118. data/spec/faked_project/test/test_helper.rb +0 -12
  119. data/spec/file_list_spec.rb +0 -50
  120. data/spec/filters_spec.rb +0 -202
  121. data/spec/fixtures/app/controllers/sample_controller.rb +0 -10
  122. data/spec/fixtures/app/models/user.rb +0 -10
  123. data/spec/fixtures/deleted_source_sample.rb +0 -15
  124. data/spec/fixtures/frameworks/rspec_bad.rb +0 -9
  125. data/spec/fixtures/frameworks/rspec_good.rb +0 -9
  126. data/spec/fixtures/frameworks/testunit_bad.rb +0 -9
  127. data/spec/fixtures/frameworks/testunit_good.rb +0 -9
  128. data/spec/fixtures/iso-8859.rb +0 -3
  129. data/spec/fixtures/never.rb +0 -2
  130. data/spec/fixtures/resultset1.rb +0 -4
  131. data/spec/fixtures/resultset2.rb +0 -4
  132. data/spec/fixtures/sample.rb +0 -16
  133. data/spec/fixtures/skipped.rb +0 -4
  134. data/spec/fixtures/skipped_and_executed.rb +0 -8
  135. data/spec/fixtures/utf-8.rb +0 -3
  136. data/spec/helper.rb +0 -26
  137. data/spec/last_run_spec.rb +0 -48
  138. data/spec/lines_classifier_spec.rb +0 -103
  139. data/spec/multi_formatter_spec.rb +0 -20
  140. data/spec/raw_coverage_spec.rb +0 -92
  141. data/spec/result_merger_spec.rb +0 -171
  142. data/spec/result_spec.rb +0 -209
  143. data/spec/return_codes_spec.rb +0 -34
  144. data/spec/simplecov_spec.rb +0 -109
  145. data/spec/source_file_line_spec.rb +0 -155
  146. data/spec/source_file_spec.rb +0 -145
  147. data/spec/support/fail_rspec_on_ruby_warning.rb +0 -75
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module SimpleCov
2
4
  module ExitCodes
3
5
  SUCCESS = 0
@@ -1,28 +1,34 @@
1
- # An array of SimpleCov SourceFile instances with additional collection helper
2
- # methods for calculating coverage across them etc.
1
+ # frozen_string_literal: true
2
+
3
3
  module SimpleCov
4
+ # An array of SimpleCov SourceFile instances with additional collection helper
5
+ # methods for calculating coverage across them etc.
4
6
  class FileList < Array
5
7
  # Returns the count of lines that have coverage
6
8
  def covered_lines
7
9
  return 0.0 if empty?
10
+
8
11
  map { |f| f.covered_lines.count }.inject(:+)
9
12
  end
10
13
 
11
14
  # Returns the count of lines that have been missed
12
15
  def missed_lines
13
16
  return 0.0 if empty?
17
+
14
18
  map { |f| f.missed_lines.count }.inject(:+)
15
19
  end
16
20
 
17
21
  # Returns the count of lines that are not relevant for coverage
18
22
  def never_lines
19
23
  return 0.0 if empty?
24
+
20
25
  map { |f| f.never_lines.count }.inject(:+)
21
26
  end
22
27
 
23
28
  # Returns the count of skipped lines
24
29
  def skipped_lines
25
30
  return 0.0 if empty?
31
+
26
32
  map { |f| f.skipped_lines.count }.inject(:+)
27
33
  end
28
34
 
@@ -34,7 +40,7 @@ module SimpleCov
34
40
 
35
41
  # Finds the least covered file and returns that file's name
36
42
  def least_covered_file
37
- sort_by(&:covered_percent).first.filename
43
+ min_by(&:covered_percent).filename
38
44
  end
39
45
 
40
46
  # Returns the overall amount of relevant lines of code across all files in this list
@@ -46,6 +52,7 @@ module SimpleCov
46
52
  # @return [Float]
47
53
  def covered_percent
48
54
  return 100.0 if empty? || lines_of_code.zero?
55
+
49
56
  Float(covered_lines * 100.0 / lines_of_code)
50
57
  end
51
58
 
@@ -53,7 +60,29 @@ module SimpleCov
53
60
  # @return [Float]
54
61
  def covered_strength
55
62
  return 0.0 if empty? || lines_of_code.zero?
63
+
56
64
  Float(map { |f| f.covered_strength * f.lines_of_code }.inject(:+) / lines_of_code)
57
65
  end
66
+
67
+ # Return total count of branches in all files
68
+ def total_branches
69
+ return 0 if empty?
70
+
71
+ map { |file| file.total_branches.count }.inject(:+)
72
+ end
73
+
74
+ # Return total count of covered branches
75
+ def covered_branches
76
+ return 0 if empty?
77
+
78
+ map { |file| file.covered_branches.count }.inject(:+)
79
+ end
80
+
81
+ # Return total count of covered branches
82
+ def missed_branches
83
+ return 0 if empty?
84
+
85
+ map { |file| file.missed_branches.count }.inject(:+)
86
+ end
58
87
  end
59
88
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module SimpleCov
2
4
  #
3
5
  # Base filter class. Inherit from this to create custom filters,
@@ -16,7 +18,7 @@ module SimpleCov
16
18
  @filter_argument = filter_argument
17
19
  end
18
20
 
19
- def matches?(_)
21
+ def matches?(_source_file)
20
22
  raise "The base filter class is not intended for direct use"
21
23
  end
22
24
 
@@ -27,6 +29,7 @@ module SimpleCov
27
29
 
28
30
  def self.build_filter(filter_argument)
29
31
  return filter_argument if filter_argument.is_a?(SimpleCov::Filter)
32
+
30
33
  class_for_argument(filter_argument).new(filter_argument)
31
34
  end
32
35
 
@@ -49,7 +52,7 @@ module SimpleCov
49
52
  # Returns true when the given source file's filename matches the
50
53
  # string configured when initializing this Filter with StringFilter.new('somestring)
51
54
  def matches?(source_file)
52
- (source_file.project_filename =~ /#{filter_argument}/)
55
+ source_file.project_filename.include?(filter_argument)
53
56
  end
54
57
  end
55
58
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module SimpleCov
2
4
  # TODO: Documentation on how to build your own formatters
3
5
  module Formatter
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module SimpleCov
2
4
  module Formatter
3
5
  class MultiFormatter
@@ -6,8 +8,8 @@ module SimpleCov
6
8
  formatters.map do |formatter|
7
9
  begin
8
10
  formatter.new.format(result)
9
- rescue => e
10
- STDERR.puts("Formatter #{formatter} failed with #{e.class}: #{e.message} (#{e.backtrace.first})")
11
+ rescue StandardError => e
12
+ warn("Formatter #{formatter} failed with #{e.class}: #{e.message} (#{e.backtrace.first})")
11
13
  nil
12
14
  end
13
15
  end
@@ -1,12 +1,14 @@
1
- #
2
- # A ridiculously simple formatter for SimpleCov results.
3
- #
1
+ # frozen_string_literal: true
2
+
4
3
  module SimpleCov
5
4
  module Formatter
5
+ #
6
+ # A ridiculously simple formatter for SimpleCov results.
7
+ #
6
8
  class SimpleFormatter
7
9
  # Takes a SimpleCov::Result and generates a string out of it
8
10
  def format(result)
9
- output = "".dup
11
+ output = +""
10
12
  result.groups.each do |name, files|
11
13
  output << "Group: #{name}\n"
12
14
  output << "=" * 40
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "json"
2
4
 
3
5
  module SimpleCov
@@ -9,8 +11,10 @@ module SimpleCov
9
11
 
10
12
  def read
11
13
  return nil unless File.exist?(last_run_path)
14
+
12
15
  json = File.read(last_run_path)
13
16
  return nil if json.strip.empty?
17
+
14
18
  JSON.parse(json)
15
19
  end
16
20
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module SimpleCov
2
4
  # Classifies whether lines are relevant for code coverage analysis.
3
5
  # Comments & whitespace lines, and :nocov: token blocks, are considered not relevant.
@@ -6,22 +8,36 @@ module SimpleCov
6
8
  RELEVANT = 0
7
9
  NOT_RELEVANT = nil
8
10
 
9
- WHITESPACE_LINE = /^\s*$/
10
- COMMENT_LINE = /^\s*#/
11
+ WHITESPACE_LINE = /^\s*$/.freeze
12
+ COMMENT_LINE = /^\s*#/.freeze
11
13
  WHITESPACE_OR_COMMENT_LINE = Regexp.union(WHITESPACE_LINE, COMMENT_LINE)
12
14
 
13
15
  def self.no_cov_line
14
- /^(\s*)#(\s*)(\:#{SimpleCov.nocov_token}\:)/
16
+ /^(\s*)#(\s*)(\:#{SimpleCov.nocov_token}\:)/o
17
+ end
18
+
19
+ def self.no_cov_line?(line)
20
+ line =~ no_cov_line
21
+ rescue ArgumentError
22
+ # E.g., line contains an invalid byte sequence in UTF-8
23
+ false
24
+ end
25
+
26
+ def self.whitespace_line?(line)
27
+ line =~ WHITESPACE_OR_COMMENT_LINE
28
+ rescue ArgumentError
29
+ # E.g., line contains an invalid byte sequence in UTF-8
30
+ false
15
31
  end
16
32
 
17
33
  def classify(lines)
18
34
  skipping = false
19
35
 
20
36
  lines.map do |line|
21
- if line =~ self.class.no_cov_line
37
+ if self.class.no_cov_line?(line)
22
38
  skipping = !skipping
23
39
  NOT_RELEVANT
24
- elsif skipping || line =~ WHITESPACE_OR_COMMENT_LINE
40
+ elsif skipping || self.class.whitespace_line?(line)
25
41
  NOT_RELEVANT
26
42
  else
27
43
  RELEVANT
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "etc"
2
4
  home_dir = (ENV["HOME"] && File.expand_path("~")) || Etc.getpwuid.dir || (ENV["USER"] && File.expand_path("~#{ENV['USER']}"))
3
5
  if home_dir
@@ -1,2 +1,4 @@
1
+ # frozen_string_literal: true
2
+
1
3
  ENV["SIMPLECOV_NO_DEFAULTS"] = "yes, no defaults"
2
4
  require "simplecov"
@@ -1,11 +1,13 @@
1
- #
2
- # Profiles are SimpleCov configuration procs that can be easily
3
- # loaded using SimpleCov.start :rails and defined using
4
- # SimpleCov.profiles.define :foo do
5
- # # SimpleCov configuration here, same as in SimpleCov.configure
6
- # end
7
- #
1
+ # frozen_string_literal: true
2
+
8
3
  module SimpleCov
4
+ #
5
+ # Profiles are SimpleCov configuration procs that can be easily
6
+ # loaded using SimpleCov.start :rails and defined using
7
+ # SimpleCov.profiles.define :foo do
8
+ # # SimpleCov configuration here, same as in SimpleCov.configure
9
+ # end
10
+ #
9
11
  class Profiles < Hash
10
12
  #
11
13
  # Define a SimpleCov profile:
@@ -16,6 +18,7 @@ module SimpleCov
16
18
  def define(name, &blk)
17
19
  name = name.to_sym
18
20
  raise "SimpleCov Profile '#{name}' is already defined" unless self[name].nil?
21
+
19
22
  self[name] = blk
20
23
  end
21
24
 
@@ -25,6 +28,7 @@ module SimpleCov
25
28
  def load(name)
26
29
  name = name.to_sym
27
30
  raise "Could not find SimpleCov Profile called '#{name}'" unless key?(name)
31
+
28
32
  SimpleCov.configure(&self[name])
29
33
  end
30
34
  end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ SimpleCov.profiles.define "bundler_filter" do
4
+ add_filter "/vendor/bundle/"
5
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ SimpleCov.profiles.define "hidden_filter" do
4
+ add_filter %r{^/\..*}
5
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ SimpleCov.profiles.define "rails" do
4
+ load_profile "test_frameworks"
5
+
6
+ add_filter %r{^/config/}
7
+ add_filter %r{^/db/}
8
+
9
+ add_group "Controllers", "app/controllers"
10
+ add_group "Channels", "app/channels"
11
+ add_group "Models", "app/models"
12
+ add_group "Mailers", "app/mailers"
13
+ add_group "Helpers", "app/helpers"
14
+ add_group "Jobs", %w[app/jobs app/workers]
15
+ add_group "Libraries", "lib/"
16
+
17
+ track_files "{app,lib}/**/*.rb"
18
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ SimpleCov.profiles.define "root_filter" do
4
+ # Exclude all files outside of simplecov root
5
+ root_filter = nil
6
+ add_filter do |src|
7
+ root_filter ||= /\A#{Regexp.escape(SimpleCov.root + File::SEPARATOR)}/io
8
+ src.filename !~ root_filter
9
+ end
10
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ SimpleCov.profiles.define "test_frameworks" do
4
+ add_filter "/test/"
5
+ add_filter "/features/"
6
+ add_filter "/spec/"
7
+ add_filter "/autotest/"
8
+ end
@@ -1,9 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "digest/sha1"
2
4
  require "forwardable"
3
5
 
4
6
  module SimpleCov
5
7
  #
6
- # A simplecov code coverage result, initialized from the Hash Ruby 1.9's built-in coverage
8
+ # A simplecov code coverage result, initialized from the Hash Ruby's built-in coverage
7
9
  # library generates (Coverage.result).
8
10
  #
9
11
  class Result
@@ -18,7 +20,7 @@ module SimpleCov
18
20
  # Explicitly set the command name that was used for this coverage result. Defaults to SimpleCov.command_name
19
21
  attr_writer :command_name
20
22
 
21
- def_delegators :files, :covered_percent, :covered_percentages, :least_covered_file, :covered_strength, :covered_lines, :missed_lines
23
+ def_delegators :files, :covered_percent, :covered_percentages, :least_covered_file, :covered_strength, :covered_lines, :missed_lines, :total_branches, :covered_branches, :missed_branches
22
24
  def_delegator :files, :lines_of_code, :total_lines
23
25
 
24
26
  # Initialize a new SimpleCov::Result from given Coverage.result (a Hash of filenames each containing an array of
@@ -26,7 +28,7 @@ module SimpleCov
26
28
  def initialize(original_result)
27
29
  @original_result = original_result.freeze
28
30
  @files = SimpleCov::FileList.new(original_result.map do |filename, coverage|
29
- SimpleCov::SourceFile.new(filename, coverage) if File.file?(filename)
31
+ SimpleCov::SourceFile.new(filename, JSON.parse(JSON.dump(coverage), :symbolize_names => true)) if File.file?(filename.to_s)
30
32
  end.compact.sort_by(&:filename))
31
33
  filter!
32
34
  end
@@ -65,12 +67,29 @@ module SimpleCov
65
67
  # Loads a SimpleCov::Result#to_hash dump
66
68
  def self.from_hash(hash)
67
69
  command_name, data = hash.first
68
- result = SimpleCov::Result.new(data["coverage"])
70
+
71
+ result = SimpleCov::Result.new(
72
+ symbolize_names_of_coverage_results(data["coverage"])
73
+ )
74
+
69
75
  result.command_name = command_name
70
76
  result.created_at = Time.at(data["timestamp"])
71
77
  result
72
78
  end
73
79
 
80
+ # Manage symbolize the keys of coverage hash.
81
+ # JSON.parse gives coverage hash with stringified keys what breaks some logics
82
+ # inside the process that expects them as symboles.
83
+ #
84
+ # @return [Hash]
85
+ def self.symbolize_names_of_coverage_results(coverage_data)
86
+ coverage_data.each_with_object({}) do |(file_name, file_coverage_result), coverage_results|
87
+ coverage_results[file_name] = file_coverage_result.each_with_object({}) do |(k, v), cov_elem|
88
+ cov_elem[k.to_sym] = v
89
+ end
90
+ end
91
+ end
92
+
74
93
  private
75
94
 
76
95
  def coverage
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SimpleCov
4
+ #
5
+ # Responsible for adapting the format of the coverage result whether it's default or with statistics
6
+ #
7
+ class ResultAdapter
8
+ attr_reader :result
9
+
10
+ def initialize(result)
11
+ @result = result
12
+ end
13
+
14
+ def self.call(*args)
15
+ new(*args).adapt
16
+ end
17
+
18
+ def adapt
19
+ return unless result
20
+
21
+ result.each_with_object({}) do |(file_name, cover_statistic), adapted_result|
22
+ if cover_statistic.is_a?(Array)
23
+ adapted_result.merge!(file_name => {:lines => cover_statistic})
24
+ else
25
+ adapted_result.merge!(file_name => cover_statistic)
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -1,11 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "json"
2
4
 
3
- #
4
- # Singleton that is responsible for caching, loading and merging
5
- # SimpleCov::Results into a single result for coverage analysis based
6
- # upon multiple test suites.
7
- #
8
5
  module SimpleCov
6
+ #
7
+ # Singleton that is responsible for caching, loading and merging
8
+ # SimpleCov::Results into a single result for coverage analysis based
9
+ # upon multiple test suites.
10
+ #
9
11
  module ResultMerger
10
12
  class << self
11
13
  # The path to the .resultset.json cache file
@@ -25,7 +27,7 @@ module SimpleCov
25
27
  if data
26
28
  begin
27
29
  JSON.parse(data) || {}
28
- rescue
30
+ rescue StandardError
29
31
  {}
30
32
  end
31
33
  else
@@ -38,8 +40,10 @@ module SimpleCov
38
40
  def stored_data
39
41
  synchronize_resultset do
40
42
  return unless File.exist?(resultset_path)
43
+
41
44
  data = File.read(resultset_path)
42
45
  return if data.nil? || data.length < 2
46
+
43
47
  data
44
48
  end
45
49
  end
@@ -53,9 +57,7 @@ module SimpleCov
53
57
  resultset.each do |command_name, data|
54
58
  result = SimpleCov::Result.from_hash(command_name => data)
55
59
  # Only add result if the timeout is above the configured threshold
56
- if (Time.now - result.created_at) < SimpleCov.merge_timeout
57
- results << result
58
- end
60
+ results << result if (Time.now - result.created_at) < SimpleCov.merge_timeout
59
61
  end
60
62
  results
61
63
  end
@@ -64,8 +66,9 @@ module SimpleCov
64
66
  # coverage data and the command_name for the result consisting of a join
65
67
  # on all source result's names
66
68
  def merge_results(*results)
67
- merged = SimpleCov::RawCoverage.merge_results(*results.map(&:original_result))
68
- result = SimpleCov::Result.new(merged)
69
+ parsed_results = JSON.parse(JSON.dump(results.map(&:original_result)), :symbolize_names => true)
70
+ combined_result = SimpleCov::Combine::ResultsCombiner.combine(*parsed_results)
71
+ result = SimpleCov::Result.new(combined_result)
69
72
  # Specify the command name
70
73
  result.command_name = results.map(&:command_name).sort.join(", ")
71
74
  result