Class: Henitai::StaticFilter
- Inherits:
-
Object
- Object
- Henitai::StaticFilter
- Defined in:
- lib/henitai/static_filter.rb,
sig/henitai.rbs
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
-
#apply(mutants, config) ⇒ Array[Mutant]
This method is the gate-level filter orchestrator.
- #coverage_lines_by_file(path = DEFAULT_COVERAGE_REPORT_PATH) ⇒ Hash[String, Array[Integer]]
- #coverage_lines_for(config) ⇒ Hash[String, Array[Integer]]
-
#initialize(coverage_report_reader: CoverageReportReader.new, skip_directives: MutationSkipDirectives.new) ⇒ StaticFilter
constructor
A new instance of StaticFilter.
- #test_lines_by_file(path = DEFAULT_PER_TEST_COVERAGE_REPORT_PATH) ⇒ Hash[String, Hash[String, Array[Integer]]]
Constructor Details
#initialize(coverage_report_reader: CoverageReportReader.new, skip_directives: MutationSkipDirectives.new) ⇒ StaticFilter
Returns a new instance of StaticFilter.
12 13 14 15 16 |
# File 'lib/henitai/static_filter.rb', line 12 def initialize(coverage_report_reader: CoverageReportReader.new, skip_directives: MutationSkipDirectives.new) @coverage_report_reader = coverage_report_reader @skip_directives = skip_directives end |
Instance Method Details
#apply(mutants, config) ⇒ Array[Mutant]
This method is the gate-level filter orchestrator.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/henitai/static_filter.rb', line 19 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) || skip_directive_mutant?(mutant) 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) ⇒ Hash[String, Array[Integer]]
57 58 59 |
# File 'lib/henitai/static_filter.rb', line 57 def coverage_lines_by_file(path = DEFAULT_COVERAGE_REPORT_PATH) coverage_report_reader.coverage_lines_by_file(path) end |
#coverage_lines_for(config) ⇒ Hash[String, Array[Integer]]
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/henitai/static_filter.rb', line 37 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) per_test_lines = coverage_lines_from_test_lines( test_lines_by_file(per_test_coverage_report_path) ) return per_test_lines if coverage_lines.empty? # Merge per-test coverage into the standard coverage map. # Standard coverage may be incomplete when child processes fork before # all files are loaded; per-test coverage widens the result set. per_test_lines.each_with_object(coverage_lines) do |(file, lines), merged| merged[file] = ((merged[file] || []) + lines).uniq.sort end end |
#test_lines_by_file(path = DEFAULT_PER_TEST_COVERAGE_REPORT_PATH) ⇒ Hash[String, Hash[String, Array[Integer]]]
61 62 63 |
# File 'lib/henitai/static_filter.rb', line 61 def test_lines_by_file(path = DEFAULT_PER_TEST_COVERAGE_REPORT_PATH) coverage_report_reader.test_lines_by_file(path) end |