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
Instance Method Summary collapse
- #branch_covered_percent ⇒ Float?
- #compute_coverage_statistics ⇒ Hash[criterion, CoverageStatistics]
-
#compute_coverage_statistics_by_file ⇒ Hash[criterion, Array[CoverageStatistics]]
Seeded with one entry per criterion the user enabled, so an empty FileList still yields the right shape.
- #count {|arg0| ... } ⇒ Object
-
#coverage_statistics(criterion = nil) ⇒ Object
With no argument answers the
{line:, branch:, method:}Hash, and with a criterion symbol that one CoverageStatistics. - #coverage_statistics_by_file ⇒ Hash[criterion, Array[CoverageStatistics]]
- #covered_branches ⇒ Integer?
- #covered_lines ⇒ Integer?
- #covered_methods ⇒ Integer?
-
#covered_percent(criterion = :line) ⇒ Float?
Nil if the criterion was not measured.
- #covered_percentages ⇒ Array[Float?]
-
#covered_strength(criterion = :line) ⇒ Float?
The strength (average hits per relevant unit) for the given criterion.
- #each {|arg0| ... } ⇒ Object
- #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?
Nil for an empty list, such as a fully filtered result.
- #length ⇒ Integer
- #lines_of_code ⇒ Integer?
- #map ⇒ void
- #method_covered_percent ⇒ Float?
- #missed_branches ⇒ Integer?
- #missed_lines ⇒ Integer?
- #missed_methods ⇒ Integer?
- #never_lines ⇒ Integer
- #size ⇒ Integer
- #skipped_lines ⇒ Integer
- #to_a ⇒ Array[SourceFile]
- #to_ary ⇒ Array[SourceFile]
- #total_branches ⇒ Integer?
- #total_methods ⇒ Integer?
Constructor Details
#initialize(files) ⇒ FileList
Returns a new instance of FileList.
12 13 14 |
# File 'lib/simplecov/file_list.rb', line 12 def initialize(files) @files = files end |
Instance Method Details
#branch_covered_percent ⇒ Float?
81 82 83 |
# File 'lib/simplecov/file_list.rb', line 81 def branch_covered_percent coverage_statistics[:branch]&.percent end |
#compute_coverage_statistics ⇒ Hash[criterion, CoverageStatistics]
120 121 122 |
# File 'lib/simplecov/file_list.rb', line 120 def compute_coverage_statistics coverage_statistics_by_file.transform_values { |stats| CoverageStatistics.from(stats) } end |
#compute_coverage_statistics_by_file ⇒ Hash[criterion, Array[CoverageStatistics]]
Seeded with one entry per criterion the user enabled, so an empty FileList
still yields the right shape. 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.
108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/simplecov/file_list.rb', line 108 def compute_coverage_statistics_by_file seed = enabled_criteria_for_reporting.to_h do |criterion| bucket = [] #: Array[CoverageStatistics] [criterion, bucket] end each_with_object(seed) do |file, together| file.coverage_statistics.each do |criterion, stats| together.fetch(criterion) << stats if together.key?(criterion) end end end |
#count ⇒ Integer #count(arg0) ⇒ Integer #count ⇒ Integer
756 757 758 |
# File 'sig/simplecov.rbs', line 756
def count: () -> Integer
| (untyped) -> Integer
| () { (SourceFile) -> boolish } -> Integer
|
#coverage_statistics ⇒ Hash[criterion, CoverageStatistics] #coverage_statistics(arg0) ⇒ CoverageStatistics?
With no argument answers the {line:, branch:, method:} Hash, and with a
criterion symbol that one CoverageStatistics.
18 19 20 21 |
# File 'lib/simplecov/file_list.rb', line 18 def coverage_statistics(criterion = nil) stats = (@coverage_statistics ||= compute_coverage_statistics) criterion ? stats[criterion] : stats end |
#coverage_statistics_by_file ⇒ Hash[criterion, Array[CoverageStatistics]]
23 24 25 |
# File 'lib/simplecov/file_list.rb', line 23 def coverage_statistics_by_file @coverage_statistics_by_file ||= compute_coverage_statistics_by_file end |
#covered_branches ⇒ Integer?
73 74 75 |
# File 'lib/simplecov/file_list.rb', line 73 def covered_branches coverage_statistics[:branch]&.covered end |
#covered_lines ⇒ Integer?
27 28 29 |
# File 'lib/simplecov/file_list.rb', line 27 def covered_lines coverage_statistics[:line]&.covered end |
#covered_methods ⇒ Integer?
89 90 91 |
# File 'lib/simplecov/file_list.rb', line 89 def covered_methods coverage_statistics[:method]&.covered end |
#covered_percent(criterion = :line) ⇒ Float?
Nil if the criterion was not measured.
60 61 62 |
# File 'lib/simplecov/file_list.rb', line 60 def covered_percent(criterion = :line) coverage_statistics(criterion)&.percent end |
#covered_percentages ⇒ Array[Float?]
43 44 45 |
# File 'lib/simplecov/file_list.rb', line 43 def covered_percentages map(&:covered_percent) end |
#covered_strength(criterion = :line) ⇒ Float?
The strength (average hits per relevant unit) for the given criterion.
65 66 67 |
# File 'lib/simplecov/file_list.rb', line 65 def covered_strength(criterion = :line) coverage_statistics(criterion)&.strength end |
#each ⇒ void #each ⇒ Enumerator[SourceFile, untyped]
751 752 |
# File 'sig/simplecov.rbs', line 751
def each: () { (SourceFile) -> void } -> void
| () -> Enumerator[SourceFile, untyped]
|
#empty? ⇒ Boolean
759 |
# File 'sig/simplecov.rbs', line 759
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.
127 128 129 130 131 132 133 |
# File 'lib/simplecov/file_list.rb', line 127 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?
Nil for an empty list, such as a fully filtered result.
48 49 50 51 52 53 |
# File 'lib/simplecov/file_list.rb', line 48 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
754 |
# File 'sig/simplecov.rbs', line 754
def length: () -> Integer
|
#lines_of_code ⇒ Integer?
55 56 57 |
# File 'lib/simplecov/file_list.rb', line 55 def lines_of_code coverage_statistics[:line]&.total end |
#map ⇒ void
This method returns an undefined value.
755 |
# File 'sig/simplecov.rbs', line 755
def map: [U] () { (SourceFile) -> U } -> Array[U]
|
#method_covered_percent ⇒ Float?
97 98 99 |
# File 'lib/simplecov/file_list.rb', line 97 def method_covered_percent coverage_statistics[:method]&.percent end |
#missed_branches ⇒ Integer?
77 78 79 |
# File 'lib/simplecov/file_list.rb', line 77 def missed_branches coverage_statistics[:branch]&.missed end |
#missed_lines ⇒ Integer?
31 32 33 |
# File 'lib/simplecov/file_list.rb', line 31 def missed_lines coverage_statistics[:line]&.missed end |
#missed_methods ⇒ Integer?
93 94 95 |
# File 'lib/simplecov/file_list.rb', line 93 def missed_methods coverage_statistics[:method]&.missed end |
#never_lines ⇒ Integer
35 36 37 |
# File 'lib/simplecov/file_list.rb', line 35 def never_lines sum { |f| f.never_lines.size } end |
#size ⇒ Integer
753 |
# File 'sig/simplecov.rbs', line 753
def size: () -> Integer
|
#skipped_lines ⇒ Integer
39 40 41 |
# File 'lib/simplecov/file_list.rb', line 39 def skipped_lines sum { |f| f.skipped_lines.size } end |
#to_a ⇒ Array[SourceFile]
760 |
# File 'sig/simplecov.rbs', line 760
def to_a: () -> Array[SourceFile]
|
#to_ary ⇒ Array[SourceFile]
761 |
# File 'sig/simplecov.rbs', line 761
def to_ary: () -> Array[SourceFile]
|
#total_branches ⇒ Integer?
69 70 71 |
# File 'lib/simplecov/file_list.rb', line 69 def total_branches coverage_statistics[:branch]&.total end |
#total_methods ⇒ Integer?
85 86 87 |
# File 'lib/simplecov/file_list.rb', line 85 def total_methods coverage_statistics[:method]&.total end |