Class: SimpleCov::FileList
- Inherits:
-
Object
- Object
- SimpleCov::FileList
- Extended by:
- Forwardable
- Includes:
- Enumerable, Enumerable[SimpleCov::SourceFile]
- Defined in:
- lib/simplecov/file_list.rb,
sig/simplecov.rbs
Overview
An Enumerable of SourceFile instances with aggregate coverage helpers. Aggregate readers return nil when the corresponding criterion was not enabled for the run.
Instance Method Summary collapse
- #branch_covered_percent ⇒ Float?
- #compute_coverage_statistics ⇒ Hash[criterion, CoverageStatistics]
-
#compute_coverage_statistics_by_file ⇒ Hash[criterion, Array[CoverageStatistics]]
Seed the result hash with one entry per criterion the user enabled — so an empty FileList (e.g. a group with no files) still yields the right shape — then fold each file's stats into the matching bucket.
- #count {|arg0| ... } ⇒ Object
-
#coverage_statistics(criterion = nil) ⇒ Object
The per-criterion coverage statistics across all files.
- #coverage_statistics_by_file ⇒ Hash[criterion, Array[CoverageStatistics]]
-
#covered_branches ⇒ Integer?
Return total count of covered branches.
-
#covered_lines ⇒ Integer?
Returns the count of lines that have coverage.
-
#covered_methods ⇒ Integer?
Return total count of covered methods.
-
#covered_percent(criterion = :line) ⇒ Float?
The coverage across all files in percent, for the given criterion (line by default).
-
#covered_percentages ⇒ Array[Float?]
Computes the coverage based upon lines covered and lines missed for each file Returns an array with all coverage percentages.
-
#covered_strength(criterion = :line) ⇒ Float?
The strength (average hits per relevant unit) for the given criterion (line by default).
-
#each {|arg0| ... } ⇒ Object
Delegated to the underlying Array.
- #empty? ⇒ Boolean
-
#enabled_criteria_for_reporting ⇒ Array[criterion]
:line(or its:oneshot_linesynonym) is reported when either criterion is enabled; the JRuby-gated branch/method criteria are reported when they pass their own engine-support check. -
#initialize(files) ⇒ FileList
constructor
A new instance of FileList.
-
#least_covered_file ⇒ String?
Finds the least covered file and returns that file's name, or nil for an empty list (e.g. a fully filtered result).
- #length ⇒ Integer
-
#lines_of_code ⇒ Integer?
Returns the overall amount of relevant lines of code across all files in this list.
- #map ⇒ void
- #method_covered_percent ⇒ Float?
-
#missed_branches ⇒ Integer?
Return total count of covered branches.
-
#missed_lines ⇒ Integer?
Returns the count of lines that have been missed.
-
#missed_methods ⇒ Integer?
Return total count of missed methods.
-
#never_lines ⇒ Integer
Returns the count of lines that are not relevant for coverage.
- #size ⇒ Integer
-
#skipped_lines ⇒ Integer
Returns the count of skipped lines.
- #to_a ⇒ Array[SourceFile]
- #to_ary ⇒ Array[SourceFile]
-
#total_branches ⇒ Integer?
Return total count of branches in all files.
-
#total_methods ⇒ Integer?
Return total count of methods in all files.
Constructor Details
#initialize(files) ⇒ FileList
Returns a new instance of FileList.
22 23 24 |
# File 'lib/simplecov/file_list.rb', line 22 def initialize(files) @files = files end |
Instance Method Details
#branch_covered_percent ⇒ Float?
107 108 109 |
# File 'lib/simplecov/file_list.rb', line 107 def branch_covered_percent coverage_statistics[:branch]&.percent end |
#compute_coverage_statistics ⇒ Hash[criterion, CoverageStatistics]
151 152 153 |
# File 'lib/simplecov/file_list.rb', line 151 def compute_coverage_statistics coverage_statistics_by_file.transform_values { |stats| CoverageStatistics.from(stats) } end |
#compute_coverage_statistics_by_file ⇒ Hash[criterion, Array[CoverageStatistics]]
Seed the result hash with one entry per criterion the user
enabled — so an empty FileList (e.g. a group with no files) still
yields the right shape — then fold each file's stats into the
matching bucket. SourceFile#coverage_statistics always reports
all three criteria; FileList is the layer that filters to the
enabled set so disabled criteria don't surface in totals, JSON,
or the HTML report.
139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/simplecov/file_list.rb', line 139 def compute_coverage_statistics_by_file seed = enabled_criteria_for_reporting.to_h do |criterion| bucket = [] #: Array[CoverageStatistics] [criterion, bucket] end @files.each_with_object(seed) do |file, together| file.coverage_statistics.each do |criterion, stats| together[criterion] << stats if together.key?(criterion) end end end |
#count ⇒ Integer #count(arg0) ⇒ Integer #count ⇒ Integer
881 882 883 |
# File 'sig/simplecov.rbs', line 881
def count: () -> Integer
| (untyped) -> Integer
| () { (SourceFile) -> boolish } -> Integer
|
#coverage_statistics ⇒ Hash[criterion, CoverageStatistics] #coverage_statistics(arg0) ⇒ CoverageStatistics?
The per-criterion coverage statistics across all files. With no argument
returns the {line:, branch:, method:} Hash; pass a criterion symbol
(:line / :branch / :method) to get that one CoverageStatistics.
29 30 31 32 |
# File 'lib/simplecov/file_list.rb', line 29 def coverage_statistics(criterion = nil) stats = (@coverage_statistics ||= compute_coverage_statistics) criterion ? stats[criterion] : stats end |
#coverage_statistics_by_file ⇒ Hash[criterion, Array[CoverageStatistics]]
34 35 36 |
# File 'lib/simplecov/file_list.rb', line 34 def coverage_statistics_by_file @coverage_statistics_by_file ||= compute_coverage_statistics_by_file end |
#covered_branches ⇒ Integer?
Return total count of covered branches
98 99 100 |
# File 'lib/simplecov/file_list.rb', line 98 def covered_branches coverage_statistics[:branch]&.covered end |
#covered_lines ⇒ Integer?
Returns the count of lines that have coverage
39 40 41 |
# File 'lib/simplecov/file_list.rb', line 39 def covered_lines coverage_statistics[:line]&.covered end |
#covered_methods ⇒ Integer?
Return total count of covered methods
117 118 119 |
# File 'lib/simplecov/file_list.rb', line 117 def covered_methods coverage_statistics[:method]&.covered end |
#covered_percent(criterion = :line) ⇒ Float?
The coverage across all files in percent, for the given criterion (line by default). Returns nil if the criterion was not measured.
81 82 83 |
# File 'lib/simplecov/file_list.rb', line 81 def covered_percent(criterion = :line) coverage_statistics(criterion)&.percent end |
#covered_percentages ⇒ Array[Float?]
Computes the coverage based upon lines covered and lines missed for each file Returns an array with all coverage percentages
60 61 62 |
# File 'lib/simplecov/file_list.rb', line 60 def covered_percentages map(&:covered_percent) end |
#covered_strength(criterion = :line) ⇒ Float?
The strength (average hits per relevant unit) for the given criterion (line by default).
88 89 90 |
# File 'lib/simplecov/file_list.rb', line 88 def covered_strength(criterion = :line) coverage_statistics(criterion)&.strength end |
#each ⇒ void #each ⇒ Enumerator[SourceFile, untyped]
Delegated to the underlying Array.
876 877 |
# File 'sig/simplecov.rbs', line 876
def each: () { (SourceFile) -> void } -> void
| () -> Enumerator[SourceFile, untyped]
|
#empty? ⇒ Boolean
884 |
# File 'sig/simplecov.rbs', line 884
def empty?: () -> bool
|
#enabled_criteria_for_reporting ⇒ Array[criterion]
:line (or its :oneshot_line synonym) is reported when either
criterion is enabled; the JRuby-gated branch/method criteria are
reported when they pass their own engine-support check.
158 159 160 161 162 163 164 |
# File 'lib/simplecov/file_list.rb', line 158 def enabled_criteria_for_reporting criteria = [] #: Array[SimpleCov::criterion] criteria << :line if SimpleCov.line_coverage? criteria << :branch if SimpleCov.branch_coverage? criteria << :method if SimpleCov.method_coverage? criteria end |
#least_covered_file ⇒ String?
Finds the least covered file and returns that file's name, or nil for an empty list (e.g. a fully filtered result).
66 67 68 69 70 71 |
# File 'lib/simplecov/file_list.rb', line 66 def least_covered_file # `covered_percent` is nil only for an unmeasured criterion, and :line # is always measured, so the `|| 0.0` arm never fires at runtime; it # exists to satisfy min_by's Comparable requirement. min_by { |file| file.covered_percent || 0.0 }&.filename end |
#length ⇒ Integer
879 |
# File 'sig/simplecov.rbs', line 879
def length: () -> Integer
|
#lines_of_code ⇒ Integer?
Returns the overall amount of relevant lines of code across all files in this list
74 75 76 |
# File 'lib/simplecov/file_list.rb', line 74 def lines_of_code coverage_statistics[:line]&.total end |
#map ⇒ void
This method returns an undefined value.
880 |
# File 'sig/simplecov.rbs', line 880
def map: [U] () { (SourceFile) -> U } -> Array[U]
|
#method_covered_percent ⇒ Float?
126 127 128 |
# File 'lib/simplecov/file_list.rb', line 126 def method_covered_percent coverage_statistics[:method]&.percent end |
#missed_branches ⇒ Integer?
Return total count of covered branches
103 104 105 |
# File 'lib/simplecov/file_list.rb', line 103 def missed_branches coverage_statistics[:branch]&.missed end |
#missed_lines ⇒ Integer?
Returns the count of lines that have been missed
44 45 46 |
# File 'lib/simplecov/file_list.rb', line 44 def missed_lines coverage_statistics[:line]&.missed end |
#missed_methods ⇒ Integer?
Return total count of missed methods
122 123 124 |
# File 'lib/simplecov/file_list.rb', line 122 def missed_methods coverage_statistics[:method]&.missed end |
#never_lines ⇒ Integer
Returns the count of lines that are not relevant for coverage
49 50 51 |
# File 'lib/simplecov/file_list.rb', line 49 def never_lines sum { |f| f.never_lines.size } end |
#size ⇒ Integer
878 |
# File 'sig/simplecov.rbs', line 878
def size: () -> Integer
|
#skipped_lines ⇒ Integer
Returns the count of skipped lines
54 55 56 |
# File 'lib/simplecov/file_list.rb', line 54 def skipped_lines sum { |f| f.skipped_lines.size } end |
#to_a ⇒ Array[SourceFile]
885 |
# File 'sig/simplecov.rbs', line 885
def to_a: () -> Array[SourceFile]
|
#to_ary ⇒ Array[SourceFile]
886 |
# File 'sig/simplecov.rbs', line 886
def to_ary: () -> Array[SourceFile]
|
#total_branches ⇒ Integer?
Return total count of branches in all files
93 94 95 |
# File 'lib/simplecov/file_list.rb', line 93 def total_branches coverage_statistics[:branch]&.total end |
#total_methods ⇒ Integer?
Return total count of methods in all files
112 113 114 |
# File 'lib/simplecov/file_list.rb', line 112 def total_methods coverage_statistics[:method]&.total end |