simplecov 0.15.1 → 0.18.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (148) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +116 -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 +302 -116
  8. data/doc/alternate-formatters.md +20 -0
  9. data/lib/simplecov.rb +321 -45
  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 +24 -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 +112 -9
  17. data/lib/simplecov/coverage_statistics.rb +56 -0
  18. data/lib/simplecov/defaults.rb +13 -80
  19. data/lib/simplecov/exit_codes.rb +2 -0
  20. data/lib/simplecov/file_list.rb +68 -13
  21. data/lib/simplecov/filter.rb +5 -2
  22. data/lib/simplecov/formatter.rb +2 -0
  23. data/lib/simplecov/formatter/multi_formatter.rb +4 -2
  24. data/lib/simplecov/formatter/simple_formatter.rb +6 -4
  25. data/lib/simplecov/last_run.rb +5 -1
  26. data/lib/simplecov/lines_classifier.rb +21 -5
  27. data/lib/simplecov/load_global_config.rb +2 -0
  28. data/lib/simplecov/no_defaults.rb +2 -0
  29. data/lib/simplecov/profiles.rb +11 -7
  30. data/lib/simplecov/profiles/bundler_filter.rb +5 -0
  31. data/lib/simplecov/profiles/hidden_filter.rb +5 -0
  32. data/lib/simplecov/profiles/rails.rb +18 -0
  33. data/lib/simplecov/profiles/root_filter.rb +10 -0
  34. data/lib/simplecov/profiles/test_frameworks.rb +8 -0
  35. data/lib/simplecov/result.rb +41 -6
  36. data/lib/simplecov/result_adapter.rb +30 -0
  37. data/lib/simplecov/result_merger.rb +20 -11
  38. data/lib/simplecov/simulate_coverage.rb +29 -0
  39. data/lib/simplecov/source_file.rb +225 -126
  40. data/lib/simplecov/source_file/branch.rb +84 -0
  41. data/lib/simplecov/source_file/line.rb +72 -0
  42. data/lib/simplecov/useless_results_remover.rb +16 -0
  43. data/lib/simplecov/version.rb +3 -1
  44. metadata +43 -160
  45. data/.gitignore +0 -31
  46. data/.rspec +0 -3
  47. data/.rubocop.yml +0 -88
  48. data/.travis.yml +0 -29
  49. data/.yardopts +0 -1
  50. data/Gemfile +0 -38
  51. data/Rakefile +0 -39
  52. data/cucumber.yml +0 -13
  53. data/features/config_autoload.feature +0 -46
  54. data/features/config_command_name.feature +0 -45
  55. data/features/config_coverage_dir.feature +0 -33
  56. data/features/config_deactivate_merging.feature +0 -42
  57. data/features/config_formatters.feature +0 -77
  58. data/features/config_merge_timeout.feature +0 -39
  59. data/features/config_nocov_token.feature +0 -79
  60. data/features/config_profiles.feature +0 -44
  61. data/features/config_project_name.feature +0 -27
  62. data/features/config_styles.feature +0 -121
  63. data/features/config_tracked_files.feature +0 -29
  64. data/features/config_tracked_files_relevant_lines.feature +0 -31
  65. data/features/cucumber_basic.feature +0 -29
  66. data/features/maximum_coverage_drop.feature +0 -89
  67. data/features/merging_test_unit_and_rspec.feature +0 -44
  68. data/features/minimum_coverage.feature +0 -59
  69. data/features/refuse_coverage_drop.feature +0 -95
  70. data/features/rspec_basic.feature +0 -32
  71. data/features/rspec_fails_on_initialization.feature +0 -14
  72. data/features/rspec_groups_and_filters_basic.feature +0 -29
  73. data/features/rspec_groups_and_filters_complex.feature +0 -37
  74. data/features/rspec_groups_using_filter_class.feature +0 -41
  75. data/features/rspec_without_simplecov.feature +0 -20
  76. data/features/skipping_code_blocks_manually.feature +0 -70
  77. data/features/step_definitions/html_steps.rb +0 -44
  78. data/features/step_definitions/simplecov_steps.rb +0 -68
  79. data/features/step_definitions/transformers.rb +0 -13
  80. data/features/step_definitions/web_steps.rb +0 -64
  81. data/features/support/aruba_freedom_patch.rb +0 -53
  82. data/features/support/env.rb +0 -50
  83. data/features/test_unit_basic.feature +0 -34
  84. data/features/test_unit_groups_and_filters_basic.feature +0 -29
  85. data/features/test_unit_groups_and_filters_complex.feature +0 -35
  86. data/features/test_unit_groups_using_filter_class.feature +0 -40
  87. data/features/test_unit_without_simplecov.feature +0 -20
  88. data/features/unicode_compatiblity.feature +0 -67
  89. data/lib/simplecov/jruby_fix.rb +0 -42
  90. data/lib/simplecov/railtie.rb +0 -7
  91. data/lib/simplecov/railties/tasks.rake +0 -11
  92. data/lib/simplecov/raw_coverage.rb +0 -39
  93. data/simplecov.gemspec +0 -27
  94. data/spec/1_8_fallbacks_spec.rb +0 -31
  95. data/spec/command_guesser_spec.rb +0 -48
  96. data/spec/config_loader_spec.rb +0 -14
  97. data/spec/configuration_spec.rb +0 -35
  98. data/spec/defaults_spec.rb +0 -41
  99. data/spec/deleted_source_spec.rb +0 -12
  100. data/spec/faked_project/Gemfile +0 -6
  101. data/spec/faked_project/Rakefile +0 -8
  102. data/spec/faked_project/cucumber.yml +0 -13
  103. data/spec/faked_project/features/step_definitions/my_steps.rb +0 -22
  104. data/spec/faked_project/features/support/env.rb +0 -12
  105. data/spec/faked_project/features/test_stuff.feature +0 -6
  106. data/spec/faked_project/lib/faked_project.rb +0 -11
  107. data/spec/faked_project/lib/faked_project/framework_specific.rb +0 -18
  108. data/spec/faked_project/lib/faked_project/meta_magic.rb +0 -24
  109. data/spec/faked_project/lib/faked_project/some_class.rb +0 -28
  110. data/spec/faked_project/lib/faked_project/untested_class.rb +0 -11
  111. data/spec/faked_project/spec/faked_spec.rb +0 -11
  112. data/spec/faked_project/spec/forking_spec.rb +0 -8
  113. data/spec/faked_project/spec/meta_magic_spec.rb +0 -15
  114. data/spec/faked_project/spec/some_class_spec.rb +0 -13
  115. data/spec/faked_project/spec/spec_helper.rb +0 -11
  116. data/spec/faked_project/test/faked_test.rb +0 -11
  117. data/spec/faked_project/test/meta_magic_test.rb +0 -13
  118. data/spec/faked_project/test/some_class_test.rb +0 -15
  119. data/spec/faked_project/test/test_helper.rb +0 -12
  120. data/spec/file_list_spec.rb +0 -50
  121. data/spec/filters_spec.rb +0 -202
  122. data/spec/fixtures/app/controllers/sample_controller.rb +0 -10
  123. data/spec/fixtures/app/models/user.rb +0 -10
  124. data/spec/fixtures/deleted_source_sample.rb +0 -15
  125. data/spec/fixtures/frameworks/rspec_bad.rb +0 -9
  126. data/spec/fixtures/frameworks/rspec_good.rb +0 -9
  127. data/spec/fixtures/frameworks/testunit_bad.rb +0 -9
  128. data/spec/fixtures/frameworks/testunit_good.rb +0 -9
  129. data/spec/fixtures/iso-8859.rb +0 -3
  130. data/spec/fixtures/never.rb +0 -2
  131. data/spec/fixtures/resultset1.rb +0 -4
  132. data/spec/fixtures/resultset2.rb +0 -4
  133. data/spec/fixtures/sample.rb +0 -16
  134. data/spec/fixtures/skipped.rb +0 -4
  135. data/spec/fixtures/skipped_and_executed.rb +0 -8
  136. data/spec/fixtures/utf-8.rb +0 -3
  137. data/spec/helper.rb +0 -26
  138. data/spec/last_run_spec.rb +0 -48
  139. data/spec/lines_classifier_spec.rb +0 -103
  140. data/spec/multi_formatter_spec.rb +0 -20
  141. data/spec/raw_coverage_spec.rb +0 -92
  142. data/spec/result_merger_spec.rb +0 -171
  143. data/spec/result_spec.rb +0 -209
  144. data/spec/return_codes_spec.rb +0 -34
  145. data/spec/simplecov_spec.rb +0 -109
  146. data/spec/source_file_line_spec.rb +0 -155
  147. data/spec/source_file_spec.rb +0 -145
  148. data/spec/support/fail_rspec_on_ruby_warning.rb +0 -75
@@ -1,48 +1,19 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Load default formatter gem
2
4
  require "simplecov-html"
3
5
  require "pathname"
4
-
5
- SimpleCov.profiles.define "root_filter" do
6
- # Exclude all files outside of simplecov root
7
- root_filter = nil
8
- add_filter do |src|
9
- root_filter ||= /\A#{Regexp.escape(SimpleCov.root + File::SEPARATOR)}/io
10
- src.filename !~ root_filter
11
- end
12
- end
13
-
14
- SimpleCov.profiles.define "test_frameworks" do
15
- add_filter "/test/"
16
- add_filter "/features/"
17
- add_filter "/spec/"
18
- add_filter "/autotest/"
19
- end
20
-
21
- SimpleCov.profiles.define "bundler_filter" do
22
- add_filter "/vendor/bundle/"
23
- end
24
-
25
- SimpleCov.profiles.define "rails" do
26
- load_profile "test_frameworks"
27
-
28
- add_filter %r{^/config/}
29
- add_filter %r{^/db/}
30
-
31
- add_group "Controllers", "app/controllers"
32
- add_group "Channels", "app/channels" if defined?(ActionCable)
33
- add_group "Models", "app/models"
34
- add_group "Mailers", "app/mailers"
35
- add_group "Helpers", "app/helpers"
36
- add_group "Jobs", %w[app/jobs app/workers]
37
- add_group "Libraries", "lib"
38
-
39
- track_files "{app,lib}/**/*.rb"
40
- end
6
+ require "simplecov/profiles/root_filter"
7
+ require "simplecov/profiles/test_frameworks"
8
+ require "simplecov/profiles/bundler_filter"
9
+ require "simplecov/profiles/hidden_filter"
10
+ require "simplecov/profiles/rails"
41
11
 
42
12
  # Default configuration
43
13
  SimpleCov.configure do
44
14
  formatter SimpleCov::Formatter::HTMLFormatter
45
15
  load_profile "bundler_filter"
16
+ load_profile "hidden_filter"
46
17
  # Exclude files outside of SimpleCov.root
47
18
  load_profile "root_filter"
48
19
  end
@@ -50,52 +21,14 @@ end
50
21
  # Gotta stash this a-s-a-p, see the CommandGuesser class and i.e. #110 for further info
51
22
  SimpleCov::CommandGuesser.original_run_command = "#{$PROGRAM_NAME} #{ARGV.join(' ')}"
52
23
 
53
- at_exit do # rubocop:disable Metrics/BlockLength
24
+ at_exit do
54
25
  # If we are in a different process than called start, don't interfere.
55
26
  next if SimpleCov.pid != Process.pid
56
27
 
57
- @exit_status = if $! # was an exception thrown?
58
- # if it was a SystemExit, use the accompanying status
59
- # otherwise set a non-zero status representing termination by
60
- # some other exception (see github issue 41)
61
- $!.is_a?(SystemExit) ? $!.status : SimpleCov::ExitCodes::EXCEPTION
62
- else
63
- # Store the exit status of the test run since it goes away
64
- # after calling the at_exit proc...
65
- SimpleCov::ExitCodes::SUCCESS
66
- end
67
-
68
- SimpleCov.at_exit.call
69
-
70
- if SimpleCov.result? # Result has been computed
71
- covered_percent = SimpleCov.result.covered_percent.round(2)
72
- covered_percentages = SimpleCov.result.covered_percentages.map { |p| p.round(2) }
73
-
74
- if @exit_status == SimpleCov::ExitCodes::SUCCESS # No other errors
75
- if covered_percent < SimpleCov.minimum_coverage # rubocop:disable Metrics/BlockNesting
76
- $stderr.printf("Coverage (%.2f%%) is below the expected minimum coverage (%.2f%%).\n", covered_percent, SimpleCov.minimum_coverage)
77
- @exit_status = SimpleCov::ExitCodes::MINIMUM_COVERAGE
78
- elsif covered_percentages.any? { |p| p < SimpleCov.minimum_coverage_by_file } # rubocop:disable Metrics/BlockNesting
79
- $stderr.printf("File (%s) is only (%.2f%%) covered. This is below the expected minimum coverage per file of (%.2f%%).\n", SimpleCov.result.least_covered_file, covered_percentages.min, SimpleCov.minimum_coverage_by_file)
80
- @exit_status = SimpleCov::ExitCodes::MINIMUM_COVERAGE
81
- elsif (last_run = SimpleCov::LastRun.read) # rubocop:disable Metrics/BlockNesting
82
- coverage_diff = last_run["result"]["covered_percent"] - covered_percent
83
- if coverage_diff > SimpleCov.maximum_coverage_drop # rubocop:disable Metrics/BlockNesting
84
- $stderr.printf("Coverage has dropped by %.2f%% since the last time (maximum allowed: %.2f%%).\n", coverage_diff, SimpleCov.maximum_coverage_drop)
85
- @exit_status = SimpleCov::ExitCodes::MAXIMUM_COVERAGE_DROP
86
- end
87
- end
88
- end
89
-
90
- # Don't overwrite last_run file if refuse_coverage_drop option is enabled and the coverage has dropped
91
- unless @exit_status == SimpleCov::ExitCodes::MAXIMUM_COVERAGE_DROP
92
- SimpleCov::LastRun.write(:result => {:covered_percent => covered_percent})
93
- end
94
- end
28
+ # If SimpleCov is no longer running then don't run exit tasks
29
+ next unless SimpleCov.running
95
30
 
96
- # Force exit with stored status (see github issue #5)
97
- # unless it's nil or 0 (see github issue #281)
98
- Kernel.exit @exit_status if @exit_status && @exit_status > 0
31
+ SimpleCov.run_exit_tasks!
99
32
  end
100
33
 
101
34
  # Autoload config from ~/.simplecov if present
@@ -111,7 +44,7 @@ loop do
111
44
  begin
112
45
  load filename
113
46
  rescue LoadError, StandardError
114
- $stderr.puts "Warning: Error occurred while trying to load #{filename}. " \
47
+ warn "Warning: Error occurred while trying to load #{filename}. " \
115
48
  "Error message: #{$!.message}"
116
49
  end
117
50
  break
@@ -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,53 @@
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
- class FileList < Array
4
+ # An array of SimpleCov SourceFile instances with additional collection helper
5
+ # methods for calculating coverage across them etc.
6
+ class FileList
7
+ include Enumerable
8
+ extend Forwardable
9
+
10
+ def_delegators :@files,
11
+ # For Enumerable
12
+ :each,
13
+ # also delegating methods implemented in Enumerable as they have
14
+ # custom Array implementations which are presumably better/more
15
+ # resource efficient
16
+ :size, :map, :count,
17
+ # surprisingly not in Enumerable
18
+ :empty?, :length,
19
+ # still act like we're kinda an array
20
+ :to_a, :to_ary
21
+
22
+ def initialize(files)
23
+ @files = files
24
+ end
25
+
26
+ def coverage_statistics
27
+ @coverage_statistics ||= compute_coverage_statistics
28
+ end
29
+
5
30
  # Returns the count of lines that have coverage
6
31
  def covered_lines
7
- return 0.0 if empty?
8
- map { |f| f.covered_lines.count }.inject(:+)
32
+ coverage_statistics[:line]&.covered
9
33
  end
10
34
 
11
35
  # Returns the count of lines that have been missed
12
36
  def missed_lines
13
- return 0.0 if empty?
14
- map { |f| f.missed_lines.count }.inject(:+)
37
+ coverage_statistics[:line]&.missed
15
38
  end
16
39
 
17
40
  # Returns the count of lines that are not relevant for coverage
18
41
  def never_lines
19
42
  return 0.0 if empty?
43
+
20
44
  map { |f| f.never_lines.count }.inject(:+)
21
45
  end
22
46
 
23
47
  # Returns the count of skipped lines
24
48
  def skipped_lines
25
49
  return 0.0 if empty?
50
+
26
51
  map { |f| f.skipped_lines.count }.inject(:+)
27
52
  end
28
53
 
@@ -34,26 +59,56 @@ module SimpleCov
34
59
 
35
60
  # Finds the least covered file and returns that file's name
36
61
  def least_covered_file
37
- sort_by(&:covered_percent).first.filename
62
+ min_by(&:covered_percent).filename
38
63
  end
39
64
 
40
65
  # Returns the overall amount of relevant lines of code across all files in this list
41
66
  def lines_of_code
42
- covered_lines + missed_lines
67
+ coverage_statistics[:line]&.total
43
68
  end
44
69
 
45
70
  # Computes the coverage based upon lines covered and lines missed
46
71
  # @return [Float]
47
72
  def covered_percent
48
- return 100.0 if empty? || lines_of_code.zero?
49
- Float(covered_lines * 100.0 / lines_of_code)
73
+ coverage_statistics[:line]&.percent
50
74
  end
51
75
 
52
76
  # Computes the strength (hits / line) based upon lines covered and lines missed
53
77
  # @return [Float]
54
78
  def covered_strength
55
- return 0.0 if empty? || lines_of_code.zero?
56
- Float(map { |f| f.covered_strength * f.lines_of_code }.inject(:+) / lines_of_code)
79
+ coverage_statistics[:line]&.strength
80
+ end
81
+
82
+ # Return total count of branches in all files
83
+ def total_branches
84
+ coverage_statistics[:branch]&.total
85
+ end
86
+
87
+ # Return total count of covered branches
88
+ def covered_branches
89
+ coverage_statistics[:branch]&.covered
90
+ end
91
+
92
+ # Return total count of covered branches
93
+ def missed_branches
94
+ coverage_statistics[:branch]&.missed
95
+ end
96
+
97
+ def branch_covered_percent
98
+ coverage_statistics[:branch]&.percent
99
+ end
100
+
101
+ private
102
+
103
+ def compute_coverage_statistics
104
+ total_coverage_statistics = @files.each_with_object(line: [], branch: []) do |file, together|
105
+ together[:line] << file.coverage_statistics[:line]
106
+ together[:branch] << file.coverage_statistics[:branch] if SimpleCov.branch_coverage?
107
+ end
108
+
109
+ coverage_statistics = {line: CoverageStatistics.from(total_coverage_statistics[:line])}
110
+ coverage_statistics[:branch] = CoverageStatistics.from(total_coverage_statistics[:branch]) if SimpleCov.branch_coverage?
111
+ coverage_statistics
57
112
  end
58
113
  end
59
114
  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,9 +11,11 @@ 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?
14
- JSON.parse(json)
17
+
18
+ JSON.parse(json, symbolize_names: true)
15
19
  end
16
20
 
17
21
  def write(json)
@@ -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