Class: Henitai::PerTestCoverage
- Inherits:
-
Object
- Object
- Henitai::PerTestCoverage
- Defined in:
- lib/henitai/per_test_coverage.rb,
sig/henitai.rbs
Overview
Read-side view of the per-test coverage map (henitai_per_test.json): which test files reach which source lines. The single implementation of the line-intersection check, shared by test selection (PerTestCoverageSelector) and survivor verdict reuse (IncrementalFilter), so both callers always agree on what "covers" means.
Instance Attribute Summary collapse
-
#coverage_report_reader ⇒ CoverageReportReader
readonly
Returns the value of attribute coverage_report_reader.
-
#reports_dir ⇒ String
readonly
Returns the value of attribute reports_dir.
Instance Method Summary collapse
- #available? ⇒ Boolean
- #coverage_lines_for(test, mutant) ⇒ Array[Integer]
-
#covers?(test, mutant) ⇒ Boolean
True when the given test file's recorded coverage intersects the mutant's current line range.
-
#initialize(reports_dir:, coverage_report_reader: CoverageReportReader.new) ⇒ PerTestCoverage
constructor
A new instance of PerTestCoverage.
- #location_available?(mutant) ⇒ Boolean
- #map ⇒ Hash[String, Hash[String, Array[Integer]]]
- #mutant_lines(mutant) ⇒ Array[Integer]
-
#tests_covering(mutant) ⇒ Array<String>
The full-map intersection set: every test file whose covered lines intersect the mutant's current line range.
Constructor Details
#initialize(reports_dir:, coverage_report_reader: CoverageReportReader.new) ⇒ PerTestCoverage
Returns a new instance of PerTestCoverage.
10 11 12 13 |
# File 'lib/henitai/per_test_coverage.rb', line 10 def initialize(reports_dir:, coverage_report_reader: CoverageReportReader.new) @reports_dir = reports_dir @coverage_report_reader = coverage_report_reader end |
Instance Attribute Details
#coverage_report_reader ⇒ CoverageReportReader (readonly)
Returns the value of attribute coverage_report_reader.
41 42 43 |
# File 'lib/henitai/per_test_coverage.rb', line 41 def coverage_report_reader @coverage_report_reader end |
#reports_dir ⇒ String (readonly)
Returns the value of attribute reports_dir.
41 42 43 |
# File 'lib/henitai/per_test_coverage.rb', line 41 def reports_dir @reports_dir end |
Instance Method Details
#available? ⇒ Boolean
15 16 17 |
# File 'lib/henitai/per_test_coverage.rb', line 15 def available? !map.empty? end |
#coverage_lines_for(test, mutant) ⇒ Array[Integer]
51 52 53 54 |
# File 'lib/henitai/per_test_coverage.rb', line 51 def coverage_lines_for(test, mutant) source_map = map[test.to_s] || {} Array(source_map[File.(mutant.location[:file])]).uniq end |
#covers?(test, mutant) ⇒ Boolean
True when the given test file's recorded coverage intersects the mutant's current line range.
33 34 35 36 37 |
# File 'lib/henitai/per_test_coverage.rb', line 33 def covers?(test, mutant) return false unless location_available?(mutant) coverage_lines_for(test, mutant).intersect?(mutant_lines(mutant)) end |
#location_available?(mutant) ⇒ Boolean
43 44 45 46 47 48 49 |
# File 'lib/henitai/per_test_coverage.rb', line 43 def location_available?(mutant) mutant.respond_to?(:location) && mutant.location.is_a?(Hash) && mutant.location[:file] && mutant.location[:start_line] && mutant.location[:end_line] end |
#map ⇒ Hash[String, Hash[String, Array[Integer]]]
60 61 62 63 64 |
# File 'lib/henitai/per_test_coverage.rb', line 60 def map @map ||= coverage_report_reader.test_lines_by_file( File.join(reports_dir, PerTestCoverageCollector::REPORT_FILE_NAME) ) end |
#mutant_lines(mutant) ⇒ Array[Integer]
56 57 58 |
# File 'lib/henitai/per_test_coverage.rb', line 56 def mutant_lines(mutant) (mutant.location[:start_line]..mutant.location[:end_line]).to_a end |
#tests_covering(mutant) ⇒ Array<String>
The full-map intersection set: every test file whose covered lines intersect the mutant's current line range.
25 26 27 28 29 |
# File 'lib/henitai/per_test_coverage.rb', line 25 def tests_covering(mutant) return [] unless location_available?(mutant) map.keys.select { |test| covers?(test, mutant) }.sort end |