Sha256: 242f39ea94764acee01118c98191726efa63c4f12ee81280678d912033896d9b

Contents?: true

Size: 1.21 KB

Versions: 35

Compression:

Stored size: 1.21 KB

Contents

# frozen_string_literal: true

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

35 entries across 23 versions & 3 rubygems

Version Path
tdiary-5.2.4 vendor/bundle/ruby/3.1.0/gems/simplecov-0.16.1/lib/simplecov/jruby_fix.rb
tdiary-5.2.3 vendor/bundle/ruby/3.1.0/gems/simplecov-0.16.1/lib/simplecov/jruby_fix.rb
tdiary-5.2.2 vendor/bundle/ruby/3.1.0/gems/simplecov-0.16.1/lib/simplecov/jruby_fix.rb
tdiary-5.2.1 vendor/bundle/ruby/3.1.0/gems/simplecov-0.16.1/lib/simplecov/jruby_fix.rb
tdiary-5.2.0 vendor/bundle/ruby/2.7.0/gems/simplecov-0.16.1/lib/simplecov/jruby_fix.rb
tdiary-5.2.0 vendor/bundle/ruby/3.0.0/gems/simplecov-0.16.1/lib/simplecov/jruby_fix.rb
tdiary-5.1.7 vendor/bundle/ruby/3.0.0/gems/simplecov-0.16.1/lib/simplecov/jruby_fix.rb
tdiary-5.1.7 vendor/bundle/ruby/2.7.0/gems/simplecov-0.16.1/lib/simplecov/jruby_fix.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/tdiary-5.1.5/vendor/bundle/ruby/2.7.0/gems/simplecov-0.16.1/lib/simplecov/jruby_fix.rb
tdiary-5.1.6 vendor/bundle/ruby/3.0.0/gems/simplecov-0.16.1/lib/simplecov/jruby_fix.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/tdiary-5.1.5/vendor/bundle/ruby/3.0.0/gems/tdiary-5.1.4/vendor/bundle/ruby/2.7.0/gems/simplecov-0.16.1/lib/simplecov/jruby_fix.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/tdiary-5.1.5/vendor/bundle/ruby/3.0.0/gems/simplecov-0.16.1/lib/simplecov/jruby_fix.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/simplecov-0.16.1/lib/simplecov/jruby_fix.rb
tdiary-5.1.5 vendor/bundle/ruby/2.7.0/gems/simplecov-0.16.1/lib/simplecov/jruby_fix.rb
tdiary-5.1.5 vendor/bundle/ruby/3.0.0/gems/tdiary-5.1.4/vendor/bundle/ruby/2.7.0/gems/simplecov-0.16.1/lib/simplecov/jruby_fix.rb
tdiary-5.1.5 vendor/bundle/ruby/3.0.0/gems/simplecov-0.16.1/lib/simplecov/jruby_fix.rb
tdiary-5.1.4 vendor/bundle/ruby/2.7.0/gems/simplecov-0.16.1/lib/simplecov/jruby_fix.rb
grape-extra_validators-2.0.0 vendor/bundle/ruby/2.6.0/gems/simplecov-0.17.1/lib/simplecov/jruby_fix.rb
tdiary-5.1.3 vendor/bundle/ruby/2.7.0/gems/simplecov-0.16.1/lib/simplecov/jruby_fix.rb
tdiary-5.1.3 vendor/bundle/ruby/2.6.0/gems/simplecov-0.16.1/lib/simplecov/jruby_fix.rb