Class: Henitai::Reporter::DryRun

Inherits:
Base
  • Object
show all
Defined in:
lib/henitai/reporter.rb,
sig/henitai.rbs

Overview

Dry-run listing: prints the post-filter mutant set (Gates 0–3) without any execution results. Used internally by the runner for --dry-run; not part of the reporters: configuration surface.

Instance Attribute Summary collapse

Attributes inherited from Base

#config, #history_store

Instance Method Summary collapse

Methods inherited from Base

#authoritative?, #canonical_path

Constructor Details

#initialize(config:, history_store: nil, io: $stdout) ⇒ DryRun

Returns a new instance of DryRun.

Parameters:



471
472
473
474
# File 'lib/henitai/reporter.rb', line 471

def initialize(config:, history_store: nil, io: $stdout)
  super(config:, history_store:)
  @io = io
end

Instance Attribute Details

#ioObject (readonly)

Returns the value of attribute io.

Returns:

  • (Object)


482
483
484
# File 'lib/henitai/reporter.rb', line 482

def io
  @io
end

Instance Method Details

#grouped_lines(mutants) ⇒ Array[String]

Parameters:

  • (Object)

Returns:

  • (Array[String])


491
492
493
494
495
# File 'lib/henitai/reporter.rb', line 491

def grouped_lines(mutants)
  mutants.group_by { |mutant| subject_label(mutant) }.flat_map do |label, subject_mutants|
    ["", label] + subject_mutants.map { |mutant| mutant_line(mutant) }
  end
end

#ignore_reason_for(mutant) ⇒ String?

Parameters:

  • (Object)

Returns:

  • (String, nil)


517
518
519
520
521
522
# File 'lib/henitai/reporter.rb', line 517

def ignore_reason_for(mutant)
  return nil unless mutant.respond_to?(:ignore_reason)

  reason = mutant.ignore_reason
  reason ? "(#{reason})" : nil
end

#listing_lines(mutants) ⇒ Array[String]

Parameters:

  • (Object)

Returns:

  • (Array[String])


484
485
486
487
488
489
# File 'lib/henitai/reporter.rb', line 484

def listing_lines(mutants)
  header = ["Dry run: #{mutants.size} mutants (no mutants executed)"]
  return header + ["", summary_line(mutants)] if mutants.empty?

  header + grouped_lines(mutants) + ["", summary_line(mutants)]
end

#mutant_line(mutant) ⇒ String

Parameters:

  • (Object)

Returns:

  • (String)


504
505
506
507
508
509
510
511
512
513
514
515
# File 'lib/henitai/reporter.rb', line 504

def mutant_line(mutant)
  line = format(
    "  %<operator>s — %<description>s  %<file>s:%<line>d  [%<status>s]",
    operator: mutant.operator,
    description: mutant.description,
    file: mutant.location.fetch(:file),
    line: mutant.location.fetch(:start_line),
    status: mutant.status
  )
  reason = ignore_reason_for(mutant)
  reason ? "#{line} #{reason}" : line
end

#report(result) ⇒ void

This method returns an undefined value.

Parameters:

  • (Object)


476
477
478
# File 'lib/henitai/reporter.rb', line 476

def report(result)
  io.puts(listing_lines(result.mutants))
end

#subject_label(mutant) ⇒ String

Parameters:

  • (Object)

Returns:

  • (String)


497
498
499
500
501
502
# File 'lib/henitai/reporter.rb', line 497

def subject_label(mutant)
  subject = mutant.subject
  return subject.expression if subject.respond_to?(:expression) && subject.expression

  mutant.location.fetch(:file, "(unknown subject)")
end

#summary_line(mutants) ⇒ String

Parameters:

  • (Object)

Returns:

  • (String)


524
525
526
527
528
# File 'lib/henitai/reporter.rb', line 524

def summary_line(mutants)
  counts = mutants.group_by(&:status).transform_values(&:size)
  summary = counts.map { |status, count| "#{status} #{count}" }.join(" | ")
  "Summary: #{summary.empty? ? 'no mutants' : summary}"
end