Class: Henitai::StaticFilter

Inherits:
Object
  • Object
show all
Defined in:
lib/henitai/static_filter.rb

Overview

Applies static, pre-execution filtering to generated mutants.

Constant Summary collapse

DEFAULT_COVERAGE_REPORT_PATH =
CoverageReportReader::DEFAULT_COVERAGE_REPORT_PATH
DEFAULT_PER_TEST_COVERAGE_REPORT_PATH =
CoverageReportReader::DEFAULT_PER_TEST_COVERAGE_REPORT_PATH

Instance Method Summary collapse

Constructor Details

#initialize(coverage_report_reader: CoverageReportReader.new) ⇒ StaticFilter

Returns a new instance of StaticFilter.



11
12
13
# File 'lib/henitai/static_filter.rb', line 11

def initialize(coverage_report_reader: CoverageReportReader.new)
  @coverage_report_reader = coverage_report_reader
end

Instance Method Details

#apply(mutants, config) ⇒ Object

This method is the gate-level filter orchestrator.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/henitai/static_filter.rb', line 16

def apply(mutants, config)
  coverage_lines = coverage_lines_for(config)
  coverage_report_present = coverage_report_present?(config)

  Array(mutants).each do |mutant|
    next if ignored_mutant?(mutant, config)

    mark_equivalent_mutant(mutant)
    mark_no_coverage_mutant(
      mutant,
      coverage_report_present:,
      coverage_lines:
    )
  end

  mutants
end

#coverage_lines_by_file(path = DEFAULT_COVERAGE_REPORT_PATH) ⇒ Object



47
48
49
# File 'lib/henitai/static_filter.rb', line 47

def coverage_lines_by_file(path = DEFAULT_COVERAGE_REPORT_PATH)
  coverage_report_reader.coverage_lines_by_file(path)
end

#coverage_lines_for(config) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/henitai/static_filter.rb', line 34

def coverage_lines_for(config)
  coverage_report_path = coverage_report_path(config)
  per_test_coverage_report_path = per_test_coverage_report_path(config)

  coverage_lines = coverage_lines_by_file(coverage_report_path)
  coverage_lines = merge_method_coverage(coverage_lines, coverage_report_path)
  return coverage_lines unless coverage_lines.empty?

  coverage_lines_from_test_lines(
    test_lines_by_file(per_test_coverage_report_path)
  )
end

#test_lines_by_file(path = DEFAULT_PER_TEST_COVERAGE_REPORT_PATH) ⇒ Object



51
52
53
# File 'lib/henitai/static_filter.rb', line 51

def test_lines_by_file(path = DEFAULT_PER_TEST_COVERAGE_REPORT_PATH)
  coverage_report_reader.test_lines_by_file(path)
end