Class: Mutineer::Reporter

Inherits:
Object
  • Object
show all
Defined in:
lib/mutineer/reporter.rb

Overview

Renders an AggregateResult: the summary block, mutation score, and per-file survivor diffs. Stream discipline (R14): the report goes to out (stdout), diagnostics/warnings go to err (stderr), so mutineer ... > report.txt captures only the report.

source_map is { file_path => raw source string }, used to extract the containing source line for each survivor diff.

Instance Method Summary collapse

Constructor Details

#initialize(aggregate, source_map) ⇒ Reporter

Returns a new instance of Reporter.



16
17
18
19
# File 'lib/mutineer/reporter.rb', line 16

def initialize(aggregate, source_map)
  @agg = aggregate
  @source_map = source_map
end

Instance Method Details

#exit_code(threshold:) ⇒ Object

0 pass / 1 below threshold. Usage errors (exit 2) are the CLI's job.



62
63
64
65
66
67
68
69
# File 'lib/mutineer/reporter.rb', line 62

def exit_code(threshold:)
  return 0 if threshold.nil? || threshold <= 0

  score = @agg.mutation_score
  return 0 if score.nil? # no testable mutants — gate skipped (warning already emitted)

  score >= threshold ? 0 : 1
end

#human_report(out, err, threshold) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/mutineer/reporter.rb', line 43

def human_report(out, err, threshold)
  if @agg.total.zero?
    err.puts "No mutations generated — verify target files contain in-scope " \
             "operators and are reached by the suite."
    return
  end

  out.puts "Mutineer — Mutation Results"
  out.puts "========================="
  out.puts
  summary(out)
  out.puts
  score_line(out, err)

  survivors(out)
  verdict(out, threshold) if threshold && threshold.positive?
end

#report(out: $stdout, err: $stderr, threshold: 0.0, format: "human", output: nil) ⇒ Object

Single entry point (R20/R21). Branches on format ("human" | "json") and routes the rendered report to output (a file, with a stderr confirmation) or to out. Diagnostics always go to err.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/mutineer/reporter.rb', line 24

def report(out: $stdout, err: $stderr, threshold: 0.0, format: "human", output: nil)
  rendered =
    if format == "json"
      json_report
    else
      sio = StringIO.new
      human_report(sio, err, threshold)
      sio.string
    end

  if output
    abs = File.expand_path(output)
    File.write(abs, rendered)
    err.puts "Report written to #{abs}"
  else
    out.print rendered
  end
end