File: simulate_coverage.rb

package info (click to toggle)
ruby-simplecov 0.22.0-2
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 1,500 kB
  • sloc: ruby: 5,550; makefile: 10
file content (29 lines) | stat: -rw-r--r-- 697 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# frozen_string_literal: true

module SimpleCov
  #
  # Responsible for producing file coverage metrics.
  #
  module SimulateCoverage
  module_function

    #
    # Simulate normal file coverage report on
    # ruby 2.5 and return similar hash with lines and branches keys
    #
    # Happens when a file wasn't required but still tracked.
    #
    # @return [Hash]
    #
    def call(absolute_path)
      lines = File.foreach(absolute_path)

      {
        "lines" => LinesClassifier.new.classify(lines),
        # we don't want to parse branches ourselves...
        # requiring files can have side effects and we don't want to trigger that
        "branches" => {}
      }
    end
  end
end