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.
- #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, Float
0.0 when the list is empty, an Integer sum otherwise.
- #size ⇒ Integer
-
#skipped_lines ⇒ Integer, Float
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?
111 112 113 |
# File 'lib/simplecov/file_list.rb', line 111 def branch_covered_percent coverage_statistics[:branch]&.percent end |
#compute_coverage_statistics ⇒ Hash[criterion, CoverageStatistics]
155 156 157 |
# File 'lib/simplecov/file_list.rb', line 155 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.
143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/simplecov/file_list.rb', line 143 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
823 824 825 |
# File 'sig/simplecov.rbs', line 823
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
102 103 104 |
# File 'lib/simplecov/file_list.rb', line 102 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
121 122 123 |
# File 'lib/simplecov/file_list.rb', line 121 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.
85 86 87 |
# File 'lib/simplecov/file_list.rb', line 85 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
64 65 66 |
# File 'lib/simplecov/file_list.rb', line 64 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).
92 93 94 |
# File 'lib/simplecov/file_list.rb', line 92 def covered_strength(criterion = :line) coverage_statistics(criterion)&.strength end |
#each ⇒ void #each ⇒ Enumerator[SourceFile, untyped]
Delegated to the underlying Array.
818 819 |
# File 'sig/simplecov.rbs', line 818
def each: () { (SourceFile) -> void } -> void
| () -> Enumerator[SourceFile, untyped]
|
#empty? ⇒ Boolean
826 |
# File 'sig/simplecov.rbs', line 826
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.
162 163 164 165 166 167 168 169 |
# File 'lib/simplecov/file_list.rb', line 162 def enabled_criteria_for_reporting criteria = [] #: Array[SimpleCov::criterion] criteria << :line if SimpleCov.coverage_criterion_enabled?(:line) || SimpleCov.coverage_criterion_enabled?(:oneshot_line) 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
69 70 71 72 73 74 75 |
# File 'lib/simplecov/file_list.rb', line 69 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 # (and the cast) exist to satisfy min_by's Comparable requirement. least_covered = min_by { |file| file.covered_percent || 0.0 } (_ = least_covered).filename end |
#length ⇒ Integer
821 |
# File 'sig/simplecov.rbs', line 821
def length: () -> Integer
|
#lines_of_code ⇒ Integer?
Returns the overall amount of relevant lines of code across all files in this list
78 79 80 |
# File 'lib/simplecov/file_list.rb', line 78 def lines_of_code coverage_statistics[:line]&.total end |
#map ⇒ void
This method returns an undefined value.
822 |
# File 'sig/simplecov.rbs', line 822
def map: [U] () { (SourceFile) -> U } -> Array[U]
|
#method_covered_percent ⇒ Float?
130 131 132 |
# File 'lib/simplecov/file_list.rb', line 130 def method_covered_percent coverage_statistics[:method]&.percent end |
#missed_branches ⇒ Integer?
Return total count of covered branches
107 108 109 |
# File 'lib/simplecov/file_list.rb', line 107 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
126 127 128 |
# File 'lib/simplecov/file_list.rb', line 126 def missed_methods coverage_statistics[:method]&.missed end |
#never_lines ⇒ Integer, Float
0.0 when the list is empty, an Integer sum otherwise.
49 50 51 52 53 |
# File 'lib/simplecov/file_list.rb', line 49 def never_lines return 0.0 if empty? sum { |f| f.never_lines.size } end |
#size ⇒ Integer
820 |
# File 'sig/simplecov.rbs', line 820
def size: () -> Integer
|
#skipped_lines ⇒ Integer, Float
Returns the count of skipped lines
56 57 58 59 60 |
# File 'lib/simplecov/file_list.rb', line 56 def skipped_lines return 0.0 if empty? sum { |f| f.skipped_lines.size } end |
#to_a ⇒ Array[SourceFile]
827 |
# File 'sig/simplecov.rbs', line 827
def to_a: () -> Array[SourceFile]
|
#to_ary ⇒ Array[SourceFile]
828 |
# File 'sig/simplecov.rbs', line 828
def to_ary: () -> Array[SourceFile]
|
#total_branches ⇒ Integer?
Return total count of branches in all files
97 98 99 |
# File 'lib/simplecov/file_list.rb', line 97 def total_branches coverage_statistics[:branch]&.total end |
#total_methods ⇒ Integer?
Return total count of methods in all files
116 117 118 |
# File 'lib/simplecov/file_list.rb', line 116 def total_methods coverage_statistics[:method]&.total end |