Class: SimpleCov::Formatter::Base
- Inherits:
-
Object
- Object
- SimpleCov::Formatter::Base
- Defined in:
- lib/simplecov/formatter/base.rb,
sig/simplecov.rbs
Overview
report to an output directory and emit the "Coverage report
generated for X to Y" status line on stderr. Subclasses implement
format.
Direct Known Subclasses
Instance Method Summary collapse
-
#displayable_output_path ⇒ String
Directory (relative to cwd when inside it) plus the subclass's
entry_point_filename, for the status line. -
#entry_point_filename ⇒ String?
Subclasses name the report's entry-point file (
index.html,coverage.json); nil leaves the bare directory in the status line. -
#initialize(silent: false, output_dir: nil) ⇒ Base
constructor
output_dirdefaults toSimpleCov.coverage_pathwhen nil. -
#message_prefix ⇒ String
Subclasses prepend a marker (e.g. "JSON ") to the summary line.
-
#output_message(result) ⇒ String
private
Emit one summary line per criterion that the run actually measured.
- #output_path ⇒ String private
- #relative_or_absolute_output_path ⇒ String private
-
#stats_line(criterion, stat) ⇒ String?
nil for branch/method criteria with nothing to measure, so the summary doesn't print "Branch coverage: 0 / 0 (100.00%)" noise.
Constructor Details
#initialize(silent: false, output_dir: nil) ⇒ Base
output_dir defaults to SimpleCov.coverage_path when nil.
19 20 21 22 |
# File 'lib/simplecov/formatter/base.rb', line 19 def initialize(silent: false, output_dir: nil) @silent = silent @output_dir = output_dir end |
Instance Method Details
#displayable_output_path ⇒ String
Directory (relative to cwd when inside it) plus the subclass's
entry_point_filename, for the status line. See issue #197.
46 47 48 49 50 |
# File 'lib/simplecov/formatter/base.rb', line 46 def displayable_output_path directory = relative_or_absolute_output_path entry_point = entry_point_filename entry_point ? File.join(directory, entry_point) : directory end |
#entry_point_filename ⇒ String?
Subclasses name the report's entry-point file (index.html,
coverage.json); nil leaves the bare directory in the status line.
68 69 70 |
# File 'lib/simplecov/formatter/base.rb', line 68 def entry_point_filename nil end |
#message_prefix ⇒ String
Subclasses prepend a marker (e.g. "JSON ") to the summary line.
29 30 31 |
# File 'lib/simplecov/formatter/base.rb', line 29 def "" end |
#output_message(result) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Emit one summary line per criterion that the run actually
measured. The header line ("Coverage report generated for X
to Y") is always first; per-criterion lines follow in the
order of result.coverage_statistics (which is the same
insertion order as SourceFile#coverage_statistics, which in
turn reflects what the user enabled).
78 79 80 81 82 |
# File 'lib/simplecov/formatter/base.rb', line 78 def (result) header = "#{}Coverage report generated for #{result.command_name} to #{displayable_output_path}" body = result.coverage_statistics.filter_map { |criterion, stat| stats_line(criterion, stat) } [header, *body].join("\n") end |
#output_path ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
33 34 35 |
# File 'lib/simplecov/formatter/base.rb', line 33 def output_path @output_dir || SimpleCov.coverage_path end |
#relative_or_absolute_output_path ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/simplecov/formatter/base.rb', line 52 def relative_or_absolute_output_path absolute = output_path relative = Pathname.new(absolute).relative_path_from(Pathname.pwd).to_s relative.start_with?("..") ? absolute : relative rescue ArgumentError # Pathname#relative_path_from raises across mixed absolute/ # relative inputs (and across Windows drives) — keep the # absolute form on any unresolvable case. output_path end |
#stats_line(criterion, stat) ⇒ String?
nil for branch/method criteria with nothing to measure, so the summary doesn't print "Branch coverage: 0 / 0 (100.00%)" noise.
88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/simplecov/formatter/base.rb', line 88 def stats_line(criterion, stat) return if criterion != :line && !stat.total.positive? percent = SimpleCov.round_coverage(stat.percent) Kernel.format( "%<label>s coverage: %<covered>d / %<total>d (%<percent>s)", label: criterion.to_s.capitalize, covered: stat.covered, total: stat.total, percent: SimpleCov::Color.colorize_percent(percent) ) end |