Class: SimpleCov::SourceFile::Statistics
- Inherits:
-
Object
- Object
- SimpleCov::SourceFile::Statistics
- Defined in:
- lib/simplecov/source_file/statistics.rb,
sig/simplecov.rbs
Overview
Builds the CoverageStatistics triple for a SourceFile regardless of which
criteria were enabled during the run: disabled or empty criteria collapse to
0/0/0 so downstream consumers don't have to special-case enable-state.
Instance Method Summary collapse
- #branch_statistics ⇒ Hash[criterion, CoverageStatistics]
- #call ⇒ Hash[criterion, CoverageStatistics]
- #coverage_statistics(covered, missed, omitted: 0, percent: nil) ⇒ CoverageStatistics
-
#initialize(source_file) ⇒ Statistics
constructor
A new instance of Statistics.
- #line_statistics ⇒ Hash[criterion, CoverageStatistics]
- #method_statistics ⇒ Hash[criterion, CoverageStatistics]
-
#unaccounted?(source_file, table) ⇒ Boolean
A file tracked but never loaded once carried no branch or method tuples at all, so an empty set meant "nobody knows", and answering the empty-set default of 100% overstated it (#902).
Constructor Details
#initialize(source_file) ⇒ Statistics
9 10 11 |
# File 'lib/simplecov/source_file/statistics.rb', line 9 def initialize(source_file) @source_file = source_file end |
Instance Method Details
#branch_statistics ⇒ Hash[criterion, CoverageStatistics]
33 34 35 36 37 38 39 40 |
# File 'lib/simplecov/source_file/statistics.rb', line 33 def branch_statistics sf = @source_file covered = sf.covered_branches missed = sf.missed_branches percent = 0.0 if covered.empty? && unaccounted?(sf, "branches") {branch: coverage_statistics(covered, missed, percent: percent)} end |
#call ⇒ Hash[criterion, CoverageStatistics]
13 14 15 16 17 18 19 |
# File 'lib/simplecov/source_file/statistics.rb', line 13 def call { **line_statistics, **branch_statistics, **method_statistics } end |
#coverage_statistics(covered, missed, omitted: 0, percent: nil) ⇒ CoverageStatistics
65 66 67 68 69 70 71 72 73 |
# File 'lib/simplecov/source_file/statistics.rb', line 65 def coverage_statistics(covered, missed, omitted: 0, percent: nil) CoverageStatistics.new( total_strength: covered.sum { |item| item.coverage.to_i }, covered: covered.size, missed: missed.size, omitted: omitted, percent: percent ) end |
#line_statistics ⇒ Hash[criterion, CoverageStatistics]
23 24 25 26 27 28 29 30 31 |
# File 'lib/simplecov/source_file/statistics.rb', line 23 def line_statistics { line: coverage_statistics( @source_file.covered_lines, @source_file.missed_lines, omitted: @source_file.never_lines.size ) } end |
#method_statistics ⇒ Hash[criterion, CoverageStatistics]
42 43 44 45 46 47 48 49 |
# File 'lib/simplecov/source_file/statistics.rb', line 42 def method_statistics sf = @source_file covered = sf.covered_methods missed = sf.missed_methods percent = 0.0 if covered.empty? && unaccounted?(sf, "methods") {method: coverage_statistics(covered, missed, percent: percent)} end |
#unaccounted?(source_file, table) ⇒ Boolean
A file tracked but never loaded once carried no branch or method tuples at all, so an empty set meant "nobody knows", and answering the empty-set default of 100% overstated it (#902). Simulation now synthesizes those tuples statically, so a file carrying a table at all, empty or not, has been accounted for: it has no branches, or a directive skipped the ones it has, and it is as covered as a loaded file with none. Only a file carrying no table for the criterion is still unaccounted for. A file with missed entries and none covered already computes to 0% either way, so only one that really has covered entries keeps its computed percentage.
61 62 63 |
# File 'lib/simplecov/source_file/statistics.rb', line 61 def unaccounted?(source_file, table) source_file.not_loaded? && source_file.coverage_data[table].nil? end |