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:



461
462
463
464
# File 'lib/henitai/reporter.rb', line 461

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)


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

def io
  @io
end

Instance Method Details

#grouped_lines(mutants) ⇒ Array[String]

Parameters:

  • (Object)

Returns:

  • (Array[String])


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

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)


507
508
509
510
511
512
# File 'lib/henitai/reporter.rb', line 507

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])


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

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)


494
495
496
497
498
499
500
501
502
503
504
505
# File 'lib/henitai/reporter.rb', line 494

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)


466
467
468
# File 'lib/henitai/reporter.rb', line 466

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

#subject_label(mutant) ⇒ String

Parameters:

  • (Object)

Returns:

  • (String)


487
488
489
490
491
492
# File 'lib/henitai/reporter.rb', line 487

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)


514
515
516
517
518
# File 'lib/henitai/reporter.rb', line 514

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