Module: SimpleCov::CLI::Report
| Relationships & Source Files | |
| Defined in: | lib/simplecov/cli/report.rb |
Overview
simplecov report [--input PATH] — pretty-print the overall
totals row plus per-group totals from a JSONFormatter
coverage.json. Same numbers as the HTML report's totals row, for
contexts where opening a browser isn't an option (CI logs, ssh
sessions, terminal-only workflows).
Constant Summary
-
SECTIONS =
# File 'lib/simplecov/cli/report.rb', line 14[%w[Line lines], %w[Branch branches], %w[Method methods]].freeze
Class Method Summary
- .collect_section(totals) mod_func
- .emit_json(stdout, data) mod_func
- .emit_section(stdout, display, section, color) mod_func
- .emit_text(stdout, data, color) mod_func
- .emit_totals(stdout, label, totals, color) mod_func
- .load_data(input, stderr) mod_func
- .parse(args) mod_func
- .run(args, stdout:, stderr:) mod_func
Class Method Details
.collect_section(totals) (mod_func)
[ GitHub ]# File 'lib/simplecov/cli/report.rb', line 74
def collect_section(totals) SECTIONS.each_with_object({}) do |(_, key), out| section = totals[key] next unless section.is_a?(Hash) && section["total"].to_i.positive? out[key] = {"percent" => section["percent"], "covered" => section["covered"], "total" => section["total"]} end end
.emit_json(stdout, data) (mod_func)
[ GitHub ]# File 'lib/simplecov/cli/report.rb', line 68
def emit_json(stdout, data) payload = {"All Files" => collect_section(data.fetch("total", {}))} data.fetch("groups", {}).each { |name, group| payload[name] = collect_section(group) } stdout.puts(JSON.pretty_generate(payload)) end
.emit_section(stdout, display, section, color) (mod_func)
[ GitHub ]# File 'lib/simplecov/cli/report.rb', line 58
def emit_section(stdout, display, section, color) return unless section.is_a?(Hash) && section["total"].to_i.positive? stdout.puts(format(" %<label>-7s %<pct>s (%<covered>d / %<total>d)", label: "#{display}:", pct: SimpleCov::Color.colorize_percent(section["percent"].to_f, enabled: color), covered: section["covered"] || 0, total: section["total"] || 0)) end
.emit_text(stdout, data, color) (mod_func)
[ GitHub ]# File 'lib/simplecov/cli/report.rb', line 47
def emit_text(stdout, data, color) emit_totals(stdout, "All Files", data.fetch("total", {}), color) data.fetch("groups", {}).each { |name, group| emit_totals(stdout, name, group, color) } end
.emit_totals(stdout, label, totals, color) (mod_func)
[ GitHub ]# File 'lib/simplecov/cli/report.rb', line 52
def emit_totals(stdout, label, totals, color) stdout.puts(label) SECTIONS.each { |display, key| emit_section(stdout, display, totals[key], color) } stdout.puts end
.load_data(input, stderr) (mod_func)
[ GitHub ]# File 'lib/simplecov/cli/report.rb', line 40
def load_data(input, stderr) return JSON.parse(File.read(input)) if File.exist?(input) stderr.puts("simplecov report: #{input} not found") nil end
.parse(args) (mod_func)
[ GitHub ]# File 'lib/simplecov/cli/report.rb', line 30
def parse(args) opts = {input: SimpleCov::CLI.default_input, json: false, no_color: false} OptionParser.new do |o| o.on("--input PATH") { |v| opts[:input] = v } o.on("--json") { opts[:json] = true } o.on("--no-color") { opts[:no_color] = true } end.parse(args) opts end