Skip to content

Wrong number of reported lines in Coverage API #1981

@donv

Description

@donv

JRuby does not report commented and blank lines in the coverage api. This leads to noisy and unreliable coverage reports.

Code used to reproduce:

require 'coverage'
file_name = File.expand_path('dummy.rb')
File.write(file_name, "# Comment\n\n")
puts "Line count: #{File.readlines(file_name).size}"
Coverage.start
require file_name.chomp('.rb')
result = Coverage.result
puts "Coverage: #{result}"
puts "Coverage: #{result[file_name].size}"

MRI reports 2 lines, and JRuby fails to report the file at all. JRuby should report 2 lines in the given file.

$ rvm use ruby
Using ~/.rvm/gems/ruby-2.1.2
$ ruby lines.rb 
Line count: 2
Coverage: {"/Users/uwe/workspace/TelenorGS/TelenorGS/dummy.rb"=>[nil, nil]}
Coverage: 2
$ rvm use jruby
Using /Users/uwe/.rvm/gems/jruby-1.7.15
$ ruby lines.rb 
Line count: 2
lines.rb:5 warning: tracing (e.g. set_trace_func) will not capture all events without --debug flag
Coverage: {}
NoMethodError: undefined method `size' for nil:NilClass
  (root) at lines.rb:9

Related issues:

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions