Class: SimpleCov::FileList

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(files) ⇒ FileList

Returns a new instance of FileList.

Parameters:



22
23
24
# File 'lib/simplecov/file_list.rb', line 22

def initialize(files)
  @files = files
end

Instance Method Details

#branch_covered_percentFloat?

Returns:

  • (Float, nil)


111
112
113
# File 'lib/simplecov/file_list.rb', line 111

def branch_covered_percent
  coverage_statistics[:branch]&.percent
end

#compute_coverage_statisticsHash[criterion, CoverageStatistics]

Returns:



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_fileHash[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.

Returns:



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

#countInteger #count(arg0) ⇒ Integer #countInteger

Overloads:

  • #countInteger

    Returns:

    • (Integer)
  • #count(arg0) ⇒ Integer

    Parameters:

    • arg0 (Object)

    Returns:

    • (Integer)
  • #countInteger

    Returns:

    • (Integer)

Yields:

Yield Parameters:

Yield Returns:

  • (boolish)


823
824
825
# File 'sig/simplecov.rbs', line 823

def count: () -> Integer
| (untyped) -> Integer
| () { (SourceFile) -> boolish } -> Integer

#coverage_statisticsHash[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.

Overloads:



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_fileHash[criterion, Array[CoverageStatistics]]

Returns:



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_branchesInteger?

Return total count of covered branches

Returns:

  • (Integer, nil)


102
103
104
# File 'lib/simplecov/file_list.rb', line 102

def covered_branches
  coverage_statistics[:branch]&.covered
end

#covered_linesInteger?

Returns the count of lines that have coverage

Returns:

  • (Integer, nil)


39
40
41
# File 'lib/simplecov/file_list.rb', line 39

def covered_lines
  coverage_statistics[:line]&.covered
end

#covered_methodsInteger?

Return total count of covered methods

Returns:

  • (Integer, nil)


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.

Parameters:

  • (criterion)

Returns:

  • (Float, nil)


85
86
87
# File 'lib/simplecov/file_list.rb', line 85

def covered_percent(criterion = :line)
  coverage_statistics(criterion)&.percent
end

#covered_percentagesArray[Float?]

Computes the coverage based upon lines covered and lines missed for each file Returns an array with all coverage percentages

Returns:

  • (Array[Float?])


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).

Parameters:

  • (criterion)

Returns:

  • (Float, nil)


92
93
94
# File 'lib/simplecov/file_list.rb', line 92

def covered_strength(criterion = :line)
  coverage_statistics(criterion)&.strength
end

#eachvoid #eachEnumerator[SourceFile, untyped]

Delegated to the underlying Array.

Overloads:

  • #eachvoid

    This method returns an undefined value.

  • #eachEnumerator[SourceFile, untyped]

    Returns:

Yields:

Yield Parameters:

Yield Returns:

  • (void)


818
819
# File 'sig/simplecov.rbs', line 818

def each: () { (SourceFile) -> void } -> void
| () -> Enumerator[SourceFile, untyped]

#empty?Boolean

Returns:

  • (Boolean)


826
# File 'sig/simplecov.rbs', line 826

def empty?: () -> bool

#enabled_criteria_for_reportingArray[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.

Returns:

  • (Array[criterion])


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_fileString

Finds the least covered file and returns that file's name

Returns:

  • (String)


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

#lengthInteger

Returns:

  • (Integer)


821
# File 'sig/simplecov.rbs', line 821

def length: () -> Integer

#lines_of_codeInteger?

Returns the overall amount of relevant lines of code across all files in this list

Returns:

  • (Integer, nil)


78
79
80
# File 'lib/simplecov/file_list.rb', line 78

def lines_of_code
  coverage_statistics[:line]&.total
end

#mapvoid

This method returns an undefined value.



822
# File 'sig/simplecov.rbs', line 822

def map: [U] () { (SourceFile) -> U } -> Array[U]

#method_covered_percentFloat?

Returns:

  • (Float, nil)


130
131
132
# File 'lib/simplecov/file_list.rb', line 130

def method_covered_percent
  coverage_statistics[:method]&.percent
end

#missed_branchesInteger?

Return total count of covered branches

Returns:

  • (Integer, nil)


107
108
109
# File 'lib/simplecov/file_list.rb', line 107

def missed_branches
  coverage_statistics[:branch]&.missed
end

#missed_linesInteger?

Returns the count of lines that have been missed

Returns:

  • (Integer, nil)


44
45
46
# File 'lib/simplecov/file_list.rb', line 44

def missed_lines
  coverage_statistics[:line]&.missed
end

#missed_methodsInteger?

Return total count of missed methods

Returns:

  • (Integer, nil)


126
127
128
# File 'lib/simplecov/file_list.rb', line 126

def missed_methods
  coverage_statistics[:method]&.missed
end

#never_linesInteger, Float

0.0 when the list is empty, an Integer sum otherwise.

Returns:

  • (Integer, Float)


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

#sizeInteger

Returns:

  • (Integer)


820
# File 'sig/simplecov.rbs', line 820

def size: () -> Integer

#skipped_linesInteger, Float

Returns the count of skipped lines

Returns:

  • (Integer, Float)


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_aArray[SourceFile]

Returns:



827
# File 'sig/simplecov.rbs', line 827

def to_a: () -> Array[SourceFile]

#to_aryArray[SourceFile]

Returns:



828
# File 'sig/simplecov.rbs', line 828

def to_ary: () -> Array[SourceFile]

#total_branchesInteger?

Return total count of branches in all files

Returns:

  • (Integer, nil)


97
98
99
# File 'lib/simplecov/file_list.rb', line 97

def total_branches
  coverage_statistics[:branch]&.total
end

#total_methodsInteger?

Return total count of methods in all files

Returns:

  • (Integer, nil)


116
117
118
# File 'lib/simplecov/file_list.rb', line 116

def total_methods
  coverage_statistics[:method]&.total
end