Module: Coverage

Defined in:
lib/rubysl/coverage/coverage.rb

Class Method Summary collapse

Class Method Details

.resultObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/rubysl/coverage/coverage.rb', line 11

def self.result
  return unless @coverage_tool

  map = @coverage_tool.stop.results

  kernel = File.dirname Rubinius::KERNEL_PATH

  coverage = Hash.new { |h, k| h[k] = [] }

  map.each do |id, attr|
    counts = attr[:counts]
    code = attr[:code]
    next unless code

    file = code.file.to_s
    next if file[0] == ?(
    file = File.join kernel, file unless file[0] == ?/

    code.lines.to_a.drop(1).each_slice(2) do |line, _|
      next unless line > 0
      next if coverage[file][line - 1]

      coverage[file][line - 1] = 0
    end

    counts.each do |ip, count|
      line = code.line_from_ip(ip)
      next unless line > 0

      coverage[file][line - 1] = count
    end
  end

  coverage.each do |file, counts|
    next unless File.exists? file

    lines = File.open(file, "r") { |f| f.lines.count }
    next unless lines > 0

    counts[lines - 1] = nil unless counts.size == lines
  end

  coverage
end

.startObject



4
5
6
7
8
9
# File 'lib/rubysl/coverage/coverage.rb', line 4

def self.start
  require 'rubinius/coverage'

  @coverage_tool = Rubinius::Coverage.new
  @coverage_tool.start
end