simplecov 0.22.0 → 1.3.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/LICENSE +1 -1
- data/README.md +173 -875
- data/exe/simplecov +8 -0
- data/lib/minitest/simplecov_plugin.rb +18 -7
- data/lib/simplecov/atomic_file.rb +67 -0
- data/lib/simplecov/autostart.rb +9 -0
- data/lib/simplecov/baseline/parser.rb +58 -0
- data/lib/simplecov/baseline.rb +170 -0
- data/lib/simplecov/cli/affected/changed_files.rb +57 -0
- data/lib/simplecov/cli/affected/selection.rb +117 -0
- data/lib/simplecov/cli/affected.rb +148 -0
- data/lib/simplecov/cli/annotations.rb +166 -0
- data/lib/simplecov/cli/badge/svg.rb +70 -0
- data/lib/simplecov/cli/badge.rb +62 -0
- data/lib/simplecov/cli/clean.rb +86 -0
- data/lib/simplecov/cli/command_helpers.rb +91 -0
- data/lib/simplecov/cli/completions/scripts.rb +114 -0
- data/lib/simplecov/cli/completions.rb +83 -0
- data/lib/simplecov/cli/coverage.rb +83 -0
- data/lib/simplecov/cli/coverage_file.rb +109 -0
- data/lib/simplecov/cli/dead_code/output.rb +100 -0
- data/lib/simplecov/cli/dead_code.rb +139 -0
- data/lib/simplecov/cli/diff/output.rb +45 -0
- data/lib/simplecov/cli/diff.rb +115 -0
- data/lib/simplecov/cli/dotfile.rb +156 -0
- data/lib/simplecov/cli/git.rb +41 -0
- data/lib/simplecov/cli/history/output.rb +135 -0
- data/lib/simplecov/cli/history.rb +67 -0
- data/lib/simplecov/cli/merge.rb +115 -0
- data/lib/simplecov/cli/open.rb +45 -0
- data/lib/simplecov/cli/patch/changed_lines.rb +149 -0
- data/lib/simplecov/cli/patch/output.rb +151 -0
- data/lib/simplecov/cli/patch.rb +175 -0
- data/lib/simplecov/cli/ratchet/output.rb +44 -0
- data/lib/simplecov/cli/ratchet.rb +83 -0
- data/lib/simplecov/cli/report.rb +91 -0
- data/lib/simplecov/cli/run.rb +35 -0
- data/lib/simplecov/cli/serve/report_preparer.rb +30 -0
- data/lib/simplecov/cli/serve/static_file_handler.rb +128 -0
- data/lib/simplecov/cli/serve.rb +88 -0
- data/lib/simplecov/cli/show/annotator.rb +87 -0
- data/lib/simplecov/cli/show/sweep.rb +36 -0
- data/lib/simplecov/cli/show.rb +133 -0
- data/lib/simplecov/cli/status/facts.rb +87 -0
- data/lib/simplecov/cli/status.rb +93 -0
- data/lib/simplecov/cli/tests/redundancy.rb +78 -0
- data/lib/simplecov/cli/tests.rb +148 -0
- data/lib/simplecov/cli/uncovered/misses.rb +33 -0
- data/lib/simplecov/cli/uncovered.rb +127 -0
- data/lib/simplecov/cli/usage.rb +153 -0
- data/lib/simplecov/cli/watch/live_report.rb +73 -0
- data/lib/simplecov/cli/watch/narrator.rb +55 -0
- data/lib/simplecov/cli/watch/poller.rb +45 -0
- data/lib/simplecov/cli/watch/session.rb +134 -0
- data/lib/simplecov/cli/watch/test_plan.rb +43 -0
- data/lib/simplecov/cli/watch.rb +85 -0
- data/lib/simplecov/cli.rb +114 -0
- data/lib/simplecov/color.rb +65 -0
- data/lib/simplecov/combine/branches_combiner.rb +44 -21
- data/lib/simplecov/combine/coverage_accumulator.rb +175 -0
- data/lib/simplecov/combine/identity_interner.rb +27 -0
- data/lib/simplecov/combine/interned_counts.rb +28 -0
- data/lib/simplecov/combine/lines_combiner.rb +35 -29
- data/lib/simplecov/combine/methods_combiner.rb +48 -0
- data/lib/simplecov/combine/results_combiner.rb +9 -49
- data/lib/simplecov/combine.rb +0 -24
- data/lib/simplecov/command_guesser.rb +99 -42
- data/lib/simplecov/configuration/baseline.rb +31 -0
- data/lib/simplecov/configuration/coverage.rb +184 -0
- data/lib/simplecov/configuration/coverage_criteria.rb +143 -0
- data/lib/simplecov/configuration/deprecations.rb +21 -0
- data/lib/simplecov/configuration/eval_coverage.rb +37 -0
- data/lib/simplecov/configuration/filters.rb +131 -0
- data/lib/simplecov/configuration/formatting.rb +129 -0
- data/lib/simplecov/configuration/groups.rb +48 -0
- data/lib/simplecov/configuration/history.rb +44 -0
- data/lib/simplecov/configuration/ignored_entries.rb +72 -0
- data/lib/simplecov/configuration/merging.rb +197 -0
- data/lib/simplecov/configuration/missed_caps.rb +51 -0
- data/lib/simplecov/configuration/production.rb +23 -0
- data/lib/simplecov/configuration/test_tracking.rb +48 -0
- data/lib/simplecov/configuration/thresholds.rb +150 -0
- data/lib/simplecov/configuration/view_coverage.rb +37 -0
- data/lib/simplecov/configuration.rb +100 -443
- data/lib/simplecov/configuration_error.rb +5 -0
- data/lib/simplecov/context_map/union.rb +81 -0
- data/lib/simplecov/context_map.rb +187 -0
- data/lib/simplecov/coverage_json.rb +21 -0
- data/lib/simplecov/coverage_statistics.rb +24 -28
- data/lib/simplecov/coverage_violations.rb +254 -0
- data/lib/simplecov/current_run.rb +61 -0
- data/lib/simplecov/defaults.rb +20 -28
- data/lib/simplecov/deprecation.rb +63 -0
- data/lib/simplecov/directive/erb.rb +44 -0
- data/lib/simplecov/directive/haml.rb +33 -0
- data/lib/simplecov/directive/indented_template.rb +37 -0
- data/lib/simplecov/directive/slim.rb +35 -0
- data/lib/simplecov/directive/template.rb +29 -0
- data/lib/simplecov/directive.rb +152 -0
- data/lib/simplecov/exit_codes/baseline_check.rb +46 -0
- data/lib/simplecov/exit_codes/check.rb +39 -0
- data/lib/simplecov/exit_codes/exit_code_handling.rb +24 -5
- data/lib/simplecov/exit_codes/maximum_coverage_drop_check.rb +17 -67
- data/lib/simplecov/exit_codes/maximum_missed_check.rb +26 -0
- data/lib/simplecov/exit_codes/maximum_missed_per_file_check.rb +34 -0
- data/lib/simplecov/exit_codes/maximum_overall_coverage_check.rb +27 -0
- data/lib/simplecov/exit_codes/minimum_coverage_by_file_check.rb +20 -38
- data/lib/simplecov/exit_codes/minimum_coverage_by_group_check.rb +28 -0
- data/lib/simplecov/exit_codes/minimum_overall_coverage_check.rb +37 -34
- data/lib/simplecov/exit_codes.rb +26 -0
- data/lib/simplecov/exit_handling.rb +163 -0
- data/lib/simplecov/file_list.rb +63 -48
- data/lib/simplecov/filter.rb +98 -42
- data/lib/simplecov/formatter/base.rb +100 -0
- data/lib/simplecov/formatter/baseline_formatter.rb +98 -0
- data/lib/simplecov/formatter/coverage_json_writer.rb +95 -0
- data/lib/simplecov/formatter/html_formatter/public/index.html +93 -0
- data/lib/simplecov/formatter/html_formatter/viewer_data_validator.rb +153 -0
- data/lib/simplecov/formatter/html_formatter.rb +88 -0
- data/lib/simplecov/formatter/json_formatter/errors_formatter.rb +122 -0
- data/lib/simplecov/formatter/json_formatter/production_section_formatter.rb +48 -0
- data/lib/simplecov/formatter/json_formatter/result_hash_formatter.rb +132 -0
- data/lib/simplecov/formatter/json_formatter/source_file_formatter.rb +97 -0
- data/lib/simplecov/formatter/json_formatter.rb +40 -0
- data/lib/simplecov/formatter/multi_formatter.rb +8 -10
- data/lib/simplecov/formatter/simple_formatter.rb +12 -15
- data/lib/simplecov/formatter.rb +21 -1
- data/lib/simplecov/group_names.rb +33 -0
- data/lib/simplecov/history.rb +115 -0
- data/lib/simplecov/last_run.rb +16 -5
- data/lib/simplecov/lines_classifier.rb +67 -19
- data/lib/simplecov/load_global_config.rb +12 -4
- data/lib/simplecov/parallel_adapters/base.rb +50 -0
- data/lib/simplecov/parallel_adapters/generic.rb +33 -0
- data/lib/simplecov/parallel_adapters/parallel_tests.rb +72 -0
- data/lib/simplecov/parallel_adapters.rb +54 -0
- data/lib/simplecov/parallel_coordination.rb +124 -0
- data/lib/simplecov/parallel_result_merger/worker_payload.rb +33 -0
- data/lib/simplecov/parallel_result_merger.rb +171 -0
- data/lib/simplecov/process.rb +34 -12
- data/lib/simplecov/production/error.rb +11 -0
- data/lib/simplecov/production/file_sink.rb +130 -0
- data/lib/simplecov/production.rb +249 -0
- data/lib/simplecov/profiles/bundler_filter.rb +1 -1
- data/lib/simplecov/profiles/hidden_filter.rb +1 -1
- data/lib/simplecov/profiles/rails.rb +13 -10
- data/lib/simplecov/profiles/root_filter.rb +2 -5
- data/lib/simplecov/profiles/strict.rb +22 -0
- data/lib/simplecov/profiles/test_frameworks.rb +1 -4
- data/lib/simplecov/profiles.rb +26 -19
- data/lib/simplecov/report_deferral.rb +45 -0
- data/lib/simplecov/report_stamp.rb +25 -0
- data/lib/simplecov/result/filter_config.rb +19 -0
- data/lib/simplecov/result/missing_source_files_reporter.rb +48 -0
- data/lib/simplecov/result/serialization.rb +43 -0
- data/lib/simplecov/result/source_file_builder.rb +46 -0
- data/lib/simplecov/result.rb +123 -47
- data/lib/simplecov/result_adapter.rb +130 -11
- data/lib/simplecov/result_merger/contexts.rb +22 -0
- data/lib/simplecov/result_merger/legacy_format_adapter.rb +24 -0
- data/lib/simplecov/result_merger/resultset_file.rb +67 -0
- data/lib/simplecov/result_merger/resultset_run_identity.rb +65 -0
- data/lib/simplecov/result_merger/resultset_store.rb +62 -0
- data/lib/simplecov/result_merger/unloaded_files.rb +95 -0
- data/lib/simplecov/result_merger.rb +120 -124
- data/lib/simplecov/result_processing.rb +188 -0
- data/lib/simplecov/run_identity.rb +75 -0
- data/lib/simplecov/simulate_coverage.rb +72 -17
- data/lib/simplecov/source_file/branch.rb +8 -35
- data/lib/simplecov/source_file/branch_builder.rb +95 -0
- data/lib/simplecov/source_file/builder_context.rb +28 -0
- data/lib/simplecov/source_file/line.rb +17 -32
- data/lib/simplecov/source_file/line_builder.rb +37 -0
- data/lib/simplecov/source_file/method.rb +54 -0
- data/lib/simplecov/source_file/method_builder.rb +51 -0
- data/lib/simplecov/source_file/ruby_data_parser.rb +103 -0
- data/lib/simplecov/source_file/skip_chunks.rb +72 -0
- data/lib/simplecov/source_file/source_loader.rb +89 -0
- data/lib/simplecov/source_file/statistics.rb +76 -0
- data/lib/simplecov/source_file.rb +64 -260
- data/lib/simplecov/static_coverage_extractor/condition_folding.rb +155 -0
- data/lib/simplecov/static_coverage_extractor/location_conventions.rb +191 -0
- data/lib/simplecov/static_coverage_extractor/method_collector.rb +45 -0
- data/lib/simplecov/static_coverage_extractor/prism_compat.rb +46 -0
- data/lib/simplecov/static_coverage_extractor/value_position.rb +61 -0
- data/lib/simplecov/static_coverage_extractor/visitor.rb +163 -0
- data/lib/simplecov/static_coverage_extractor.rb +78 -0
- data/lib/simplecov/test_tracker/accessors.rb +34 -0
- data/lib/simplecov/test_tracker/constant_watch.rb +49 -0
- data/lib/simplecov/test_tracker/delta.rb +69 -0
- data/lib/simplecov/test_tracker/framework_hooks.rb +130 -0
- data/lib/simplecov/test_tracker.rb +162 -0
- data/lib/simplecov/unloaded_file_injector.rb +62 -0
- data/lib/simplecov/useless_results_remover.rb +17 -7
- data/lib/simplecov/version.rb +1 -1
- data/lib/simplecov/view_coverage/template_compiler.rb +83 -0
- data/lib/simplecov/view_coverage.rb +55 -0
- data/lib/simplecov-html.rb +5 -0
- data/lib/simplecov.rb +143 -394
- data/lib/simplecov_json_formatter.rb +5 -0
- data/man/simplecov.1 +354 -0
- data/sig/simplecov.rbs +1710 -0
- metadata +183 -61
- data/CHANGELOG.md +0 -191
- data/doc/alternate-formatters.md +0 -71
- data/doc/commercial-services.md +0 -25
- data/doc/editor-integration.md +0 -18
- data/lib/simplecov/combine/files_combiner.rb +0 -24
- data/lib/simplecov/default_formatter.rb +0 -20
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module SimpleCov
|
|
4
|
+
module Configuration
|
|
5
|
+
TRACK_TESTS_GRANULARITIES = %i[test file].freeze
|
|
6
|
+
|
|
7
|
+
# Enables recording of which test covered which line. Off by default:
|
|
8
|
+
# sampling coverage around every test costs run time, and the recorded map
|
|
9
|
+
# costs space in `.resultset.json`. RSpec examples and Minitest tests are
|
|
10
|
+
# wrapped automatically; other runners wrap their own units of work with
|
|
11
|
+
# `SimpleCov.track_test`. A bare `track_tests` enables, and only an explicit
|
|
12
|
+
# `track_tests false` turns it back off.
|
|
13
|
+
#
|
|
14
|
+
# `granularity` decides what one recorded context stands for: a test
|
|
15
|
+
# (`:test`, the default) or a whole test file (`:file`). File granularity is
|
|
16
|
+
# the batching lever for suites where per-test sampling costs too much.
|
|
17
|
+
def track_tests(enabled = nil, granularity: nil)
|
|
18
|
+
if granularity && !TRACK_TESTS_GRANULARITIES.include?(granularity)
|
|
19
|
+
raise ConfigurationError,
|
|
20
|
+
"Unsupported track_tests granularity #{granularity.inspect}, " \
|
|
21
|
+
"supported values are #{TRACK_TESTS_GRANULARITIES.inspect}"
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
@track_tests_granularity = granularity if granularity
|
|
25
|
+
@track_tests = enabled.nil? || enabled
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def track_tests?
|
|
29
|
+
!!@track_tests
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def track_tests_granularity
|
|
33
|
+
@track_tests_granularity || :test
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# @api private. The map is built from per-line execution count deltas, which
|
|
37
|
+
# `:oneshot_line` does not produce: a line reports only its first hit ever,
|
|
38
|
+
# so every test after the first would show no delta.
|
|
39
|
+
def validate_test_tracking!
|
|
40
|
+
return unless track_tests?
|
|
41
|
+
return if coverage_criterion_enabled?(DEFAULT_COVERAGE_CRITERION)
|
|
42
|
+
|
|
43
|
+
raise ConfigurationError,
|
|
44
|
+
"`track_tests` needs line coverage with execution counts. " \
|
|
45
|
+
"Enable it with `enable_coverage :line` (`:oneshot_line` cannot record per-test data)."
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module SimpleCov
|
|
4
|
+
module Configuration
|
|
5
|
+
def minimum_coverage(coverage = nil)
|
|
6
|
+
return @minimum_coverage ||= {} unless coverage
|
|
7
|
+
|
|
8
|
+
@minimum_coverage = normalized_threshold(coverage, "minimum_coverage")
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def raise_on_invalid_coverage(coverage, coverage_setting)
|
|
12
|
+
coverage.each_key { |criterion| raise_if_criterion_disabled(criterion) }
|
|
13
|
+
coverage.each_value do |percent|
|
|
14
|
+
minimum_possible_coverage_exceeded(coverage_setting) if percent && percent > 100
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
#
|
|
19
|
+
# The maximum overall coverage allowed for the testsuite to pass. Useful
|
|
20
|
+
# paired with `minimum_coverage` (or via `expected_coverage`) to pin
|
|
21
|
+
# coverage to an exact value, so an unexpected jump up fails the build
|
|
22
|
+
# (#187).
|
|
23
|
+
#
|
|
24
|
+
def maximum_coverage(coverage = nil)
|
|
25
|
+
return @maximum_coverage ||= {} unless coverage
|
|
26
|
+
|
|
27
|
+
@maximum_coverage = normalized_threshold(coverage, "maximum_coverage")
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def expected_coverage(coverage = nil)
|
|
31
|
+
return minimum_coverage if coverage.nil?
|
|
32
|
+
|
|
33
|
+
minimum_coverage(coverage)
|
|
34
|
+
maximum_coverage(coverage)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def maximum_coverage_drop(coverage_drop = nil)
|
|
38
|
+
return @maximum_coverage_drop ||= {} unless coverage_drop
|
|
39
|
+
|
|
40
|
+
@maximum_coverage_drop = normalized_threshold(coverage_drop, "maximum_coverage_drop")
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
#
|
|
44
|
+
# The minimum coverage per file required for the testsuite to pass.
|
|
45
|
+
# Accepts a Numeric (global threshold on the primary criterion), a
|
|
46
|
+
# Symbol-keyed Hash (per-criterion globals), or a Hash mixing Symbol keys
|
|
47
|
+
# with String / Regexp keys to declare per-path overrides (#575).
|
|
48
|
+
#
|
|
49
|
+
def minimum_coverage_by_file(coverage = nil)
|
|
50
|
+
return @minimum_coverage_by_file ||= {} unless coverage
|
|
51
|
+
|
|
52
|
+
coverage = {primary_coverage => coverage} if coverage.is_a?(Numeric)
|
|
53
|
+
defaults, overrides = partition_per_file_thresholds(coverage)
|
|
54
|
+
|
|
55
|
+
Deprecation.warn("`SimpleCov.minimum_coverage_by_file` is deprecated. " \
|
|
56
|
+
"Replace it with:\n#{per_file_coverage_replacement(defaults, overrides)}")
|
|
57
|
+
|
|
58
|
+
raise_on_invalid_coverage(defaults, "minimum_coverage_by_file")
|
|
59
|
+
overrides.each_value { |criteria| raise_on_invalid_coverage(criteria, "minimum_coverage_by_file") }
|
|
60
|
+
|
|
61
|
+
@minimum_coverage_by_file = defaults
|
|
62
|
+
@minimum_coverage_by_file_overrides = overrides
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def minimum_coverage_by_file_overrides
|
|
66
|
+
@minimum_coverage_by_file_overrides ||= {}
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def minimum_coverage_by_group(coverage = nil)
|
|
70
|
+
return @minimum_coverage_by_group ||= {} unless coverage
|
|
71
|
+
|
|
72
|
+
Deprecation.warn("`SimpleCov.minimum_coverage_by_group` is deprecated. " \
|
|
73
|
+
"Replace it with:\n#{per_group_coverage_replacement(coverage)}")
|
|
74
|
+
@minimum_coverage_by_group = coverage.to_h do |group_name, group_coverage|
|
|
75
|
+
[GroupNames.normalize(group_name), normalized_threshold(group_coverage, "minimum_coverage_by_group")]
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def refuse_coverage_drop(*criteria)
|
|
80
|
+
criteria = coverage_criteria if criteria.empty?
|
|
81
|
+
maximum_coverage_drop(criteria.to_h { |c| [c, 0] })
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
private
|
|
85
|
+
|
|
86
|
+
# A bare Numeric targets the primary criterion, and the resulting
|
|
87
|
+
# per-criterion hash is validated before it is stored.
|
|
88
|
+
def normalized_threshold(coverage, setting)
|
|
89
|
+
coverage = {primary_coverage => coverage} if coverage.is_a?(Numeric)
|
|
90
|
+
coverage.tap { |thresholds| raise_on_invalid_coverage(thresholds, setting) }
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
# Splits into Symbol-keyed criterion defaults and String/Regexp-keyed
|
|
94
|
+
# per-path overrides, normalizing Numeric override values to
|
|
95
|
+
# `{primary_coverage => N}` so downstream code has one shape to handle.
|
|
96
|
+
def partition_per_file_thresholds(coverage)
|
|
97
|
+
coverage.each_key { |key| validate_per_file_key(key) }
|
|
98
|
+
# The assertions restate what the partition predicate guarantees: Symbol
|
|
99
|
+
# keys carry per-criterion Numeric defaults, the rest are paths.
|
|
100
|
+
symbol_pairs, path_pairs = coverage.partition { |key, _| key.instance_of?(Symbol) }
|
|
101
|
+
defaults = symbol_pairs.to_h #: coverage_thresholds
|
|
102
|
+
raw = path_pairs.to_h #: Hash[String | Regexp, Numeric | coverage_thresholds]
|
|
103
|
+
overrides = raw.transform_values { |value| value.is_a?(Numeric) ? {primary_coverage => value} : value }
|
|
104
|
+
[defaults, overrides]
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def validate_per_file_key(key)
|
|
108
|
+
# Symbols have no subclasses; paths and patterns may.
|
|
109
|
+
return if key.instance_of?(Symbol) || key.is_a?(String) || key.is_a?(Regexp)
|
|
110
|
+
|
|
111
|
+
raise ConfigurationError,
|
|
112
|
+
"minimum_coverage_by_file keys must be Symbol (criterion), String, or Regexp; got #{key.inspect}"
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
def minimum_possible_coverage_exceeded(coverage_option)
|
|
116
|
+
warn "The coverage you set for #{coverage_option} is greater than 100%"
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
# Renders the `coverage` configuration equivalent to a deprecated
|
|
120
|
+
# `minimum_coverage_by_file` argument, so the deprecation warning can be
|
|
121
|
+
# copy-pasted verbatim into the user's config.
|
|
122
|
+
def per_file_coverage_replacement(defaults, overrides)
|
|
123
|
+
by_criterion = {} #: Hash[Symbol, Array[String]]
|
|
124
|
+
defaults.each { |criterion, percent| (by_criterion[criterion] ||= []) << "minimum #{percent}, per: :file" }
|
|
125
|
+
overrides.each do |target, criteria|
|
|
126
|
+
criteria.each do |criterion, percent|
|
|
127
|
+
(by_criterion[criterion] ||= []) << "minimum #{percent}, per: #{target.inspect}"
|
|
128
|
+
end
|
|
129
|
+
end
|
|
130
|
+
render_coverage_blocks(by_criterion)
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
def per_group_coverage_replacement(coverage)
|
|
134
|
+
by_criterion = {} #: Hash[Symbol, Array[String]]
|
|
135
|
+
coverage.each do |group_name, thresholds|
|
|
136
|
+
normalized = (thresholds.is_a?(Numeric) ? {primary_coverage => thresholds} : thresholds) #: coverage_thresholds
|
|
137
|
+
normalized.each do |criterion, percent|
|
|
138
|
+
(by_criterion[criterion] ||= []) << "minimum #{percent}, per: group(#{group_name.inspect})"
|
|
139
|
+
end
|
|
140
|
+
end
|
|
141
|
+
render_coverage_blocks(by_criterion)
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
def render_coverage_blocks(by_criterion)
|
|
145
|
+
by_criterion.map do |criterion, statements|
|
|
146
|
+
" coverage(#{criterion.inspect}) { #{statements.join("; ")} }"
|
|
147
|
+
end.join("\n")
|
|
148
|
+
end
|
|
149
|
+
end
|
|
150
|
+
end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module SimpleCov
|
|
4
|
+
module Configuration
|
|
5
|
+
DEFAULT_VIEW_GLOBS = %w[app/views/**/*.{erb,haml,slim}].freeze
|
|
6
|
+
|
|
7
|
+
# Reports coverage for ActionView templates, defaulting to a Rails app's
|
|
8
|
+
# views. Globs are expanded against `SimpleCov.root`, and one naming an
|
|
9
|
+
# extension no handler is registered for (as the default does whenever a
|
|
10
|
+
# project has no Haml or Slim) leaves those files out rather than reporting
|
|
11
|
+
# them as empty.
|
|
12
|
+
#
|
|
13
|
+
# Templates the suite renders are measured through eval coverage, which this
|
|
14
|
+
# enables. Templates it never renders are compiled at the end of the run so
|
|
15
|
+
# they appear at 0% instead of going missing.
|
|
16
|
+
def cover_views(*globs)
|
|
17
|
+
globs = globs.flatten.compact
|
|
18
|
+
globs = DEFAULT_VIEW_GLOBS.dup if globs.empty?
|
|
19
|
+
@view_globs = globs
|
|
20
|
+
enable_eval_coverage
|
|
21
|
+
globs
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# Nil rather than an empty Array when `cover_views` was never called, so
|
|
25
|
+
# "not asked for" stays distinguishable from "asked for, with nothing to
|
|
26
|
+
# match".
|
|
27
|
+
def view_globs
|
|
28
|
+
@view_globs
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# False when eval coverage couldn't be enabled, where `cover_views` has
|
|
32
|
+
# already warned and the templates would come back empty rather than at 0%.
|
|
33
|
+
def view_coverage?
|
|
34
|
+
!view_globs.nil? && coverage_for_eval_enabled?
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|