class Undercover::Report

Attributes

changeset[R]
code_dir[R]
lcov[R]
loaded_files[R]
results[R]

Public Class Methods

new(changeset, opts) click to toggle source

Initializes a new Undercover::Report

@param changeset [Undercover::Changeset] @param opts [Undercover::Options]

# File lib/undercover.rb, line 31
def initialize(changeset, opts)
  @lcov = LcovParser.parse(File.open(opts.lcov))
  @code_dir = opts.path
  @changeset = changeset.update
  @loaded_files = {}
  @results = {}
end

Public Instance Methods

all_results() click to toggle source
# File lib/undercover.rb, line 72
def all_results
  results.values.map(&:to_a).flatten
end
build() click to toggle source

rubocop:disable Metrics/MethodLength, Metrics/AbcSize, Metrics/CyclomaticComplexity

# File lib/undercover.rb, line 40
def build
  changeset.each_changed_line do |filepath, line_no|
    dist_from_line_no = lambda do |res|
      return BigDecimal::INFINITY if line_no < res.first_line

      res_lines = res.first_line..res.last_line
      return BigDecimal::INFINITY unless res_lines.cover?(line_no)

      line_no - res.first_line
    end
    dist_from_line_no_sorter = lambda do |res1, res2|
      dist_from_line_no[res1] <=> dist_from_line_no[res2]
    end
    load_and_parse_file(filepath)

    next unless loaded_files[filepath]

    res = loaded_files[filepath].min(&dist_from_line_no_sorter)
    res.flag if res&.uncovered?(line_no)
    results[filepath] ||= Set.new
    results[filepath] << res
  end
  self
end
build_warnings() click to toggle source

rubocop:enable Metrics/MethodLength, Metrics/AbcSize, Metrics/CyclomaticComplexity

# File lib/undercover.rb, line 66
def build_warnings
  warn('Undercover::Report#build_warnings is deprecated! ' \
       'Please use the #flagged_results accessor instead.')
  all_results.select(&:flagged?)
end
flagged_results() click to toggle source
# File lib/undercover.rb, line 76
def flagged_results
  all_results.select(&:flagged?)
end
inspect() click to toggle source
# File lib/undercover.rb, line 80
def inspect
  "#<Undercover::Report:#{object_id} results: #{results.size}>"
end
Also aliased as: to_s
to_s()
Alias for: inspect

Private Instance Methods

load_and_parse_file(filepath) click to toggle source

rubocop:disable Metrics/MethodLength, Metrics/AbcSize

# File lib/undercover.rb, line 90
def load_and_parse_file(filepath)
  key = filepath.gsub(/^\.\//, '')
  return if loaded_files[key]

  coverage = lcov.coverage(filepath)
  return if coverage.empty?

  root_ast = Imagen::Node::Root.new.build_from_file(
    File.join(code_dir, filepath)
  )
  return if root_ast.children.empty?

  loaded_files[key] = []
  # TODO: children[0] ignores the lonely_method (see spec fixtures)!
  root_ast.children[0].find_all(->(_) { true }).each do |imagen_node|
    loaded_files[key] << Result.new(imagen_node, coverage, filepath)
  end
end