Sha256: 86681cce3e7406d2e551c009ec49d8c18dbc96a5e9467246fc5c25210f639193

Contents?: true

Size: 1.18 KB

Versions: 36

Compression:

Stored size: 1.18 KB

Contents

if defined?(JRUBY_VERSION) && JRUBY_VERSION.to_f < 1.7
  require "jruby"
  java_import "org.jruby.ast.NodeType"

  # 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
  module Coverage
    class << self
      alias __broken_result__ result

      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
    end
  end
end

Version data entries

36 entries across 36 versions & 10 rubygems

Version Path
dirwatch-0.0.9 vendor/bundle/ruby/2.5.0/gems/simplecov-0.13.0/lib/simplecov/jruby_fix.rb
dirwatch-0.0.8 vendor/bundle/ruby/2.5.0/gems/simplecov-0.13.0/lib/simplecov/jruby_fix.rb
tdiary-5.0.9 vendor/bundle/gems/simplecov-0.14.1/lib/simplecov/jruby_fix.rb
dirwatch-0.0.6 vendor/bundle/ruby/2.3.0/gems/simplecov-0.13.0/lib/simplecov/jruby_fix.rb
dirwatch-0.0.5 vendor/bundle/ruby/2.3.0/gems/simplecov-0.13.0/lib/simplecov/jruby_fix.rb
dirwatch-0.0.4 vendor/bundle/ruby/2.3.0/gems/simplecov-0.13.0/lib/simplecov/jruby_fix.rb
dirwatch-0.0.3 vendor/bundle/ruby/2.3.0/gems/simplecov-0.13.0/lib/simplecov/jruby_fix.rb
dirwatch-0.0.2 vendor/bundle/ruby/2.3.0/gems/simplecov-0.13.0/lib/simplecov/jruby_fix.rb
simplecov-0.15.1 lib/simplecov/jruby_fix.rb
simplecov-0.15.0 lib/simplecov/jruby_fix.rb
logstash-filter-cache-redis-0.3.1 vendor/bundle/jruby/1.9/gems/simplecov-0.14.1/lib/simplecov/jruby_fix.rb
logstash-filter-cache-redis-0.3.0 vendor/bundle/jruby/1.9/gems/simplecov-0.14.1/lib/simplecov/jruby_fix.rb
logstash-filter-cache-redis-0.2.0 vendor/bundle/jruby/1.9/gems/simplecov-0.14.1/lib/simplecov/jruby_fix.rb
logstash-filter-cache-redis-0.1.0 vendor/bundle/jruby/1.9/gems/simplecov-0.14.1/lib/simplecov/jruby_fix.rb
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/simplecov-0.14.1/lib/simplecov/jruby_fix.rb
simplecov-patched-0.14.3 lib/simplecov/jruby_fix.rb
simplecov-patched-0.14.2 lib/simplecov/jruby_fix.rb
simplecov-0.14.1 lib/simplecov/jruby_fix.rb
simplecov-0.14.0 lib/simplecov/jruby_fix.rb
simplecov-0.13.0 lib/simplecov/jruby_fix.rb