Module: Coverage

Defined in:
lib/simplecov/jruby_fix.rb

Overview

Coverage for JRuby < 1.7.0 does not work correctly

- does not distinguish lines that cannot be executed
- does (partial) coverage for files loaded before `Coverage.start`.
- does not expand a path like `lib/../spec` to `spec`.

This monkey patches Coverage to address those issues

Class Method Summary collapse

Class Method Details

.__broken_result__Object



16
# File 'lib/simplecov/jruby_fix.rb', line 16

alias __broken_result__ result

.resultObject

rubocop:disable Metrics/MethodLength



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/simplecov/jruby_fix.rb', line 18

def result # rubocop:disable Metrics/MethodLength
  fixed = {}
  __broken_result__.each do |path, executed_lines|
    next unless File.file? path

    covered_lines = executed_lines.dup

    process = lambda do |node|
      if node.node_type == NodeType::NEWLINENODE
        pos = node.position
        covered_lines[pos.line] ||= 0
      end
      node.child_nodes.each(&process)
    end

    process[JRuby.parse(File.read(path), path)]

    if (first = covered_lines.detect { |x| x }) && first > 0
      fixed[File.expand_path(path)] = covered_lines
    end
  end

  fixed
end