Project

General

Profile

Actions

Bug #19360

closed

Enabling coverage with `-r` option isn't sufficient to intercept top level script.

Added by ioquatix (Samuel Williams) over 1 year ago. Updated about 1 year ago.


Description

For some reason, Ruby's coverage library doesn't work when the file is loaded from the command line. In the below example, test2.rb loads test.rb. If you run test2.rb with coverage enabled, it will report coverage for test.rb but not test2.rb. If you run test.rb directly, no coverage is reported.

samuel@aiko ~/P/i/autocoverage> ruby -r "./autocoverage.rb" test.rb
Hello World
{}
samuel@aiko ~/P/i/autocoverage> ruby -r "./autocoverage.rb" test2.rb
Hello World
{"/home/samuel/Projects/ioquatix/autocoverage/test.rb"=>{:lines=>[1, 1, nil, nil, 1], :branches=>{}, :methods=>{[Object, :main, 1, 0, 3, 3]=>1}}}

The same problem affects simplecov.

ruby -r "./simplecov.rb" test.rb
... similar results in coverage directory ...

See https://github.com/ioquatix/autocoverage for a complete reproduction.

Updated by ioquatix (Samuel Williams) over 1 year ago

  • Status changed from Open to Closed
  • Backport changed from 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN to 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: REQUIRED

I've merged this fix. I would like this backported to 3.2 if possible, because it's blocking correct coverage computation and I don't want to wait a year to be able to use this fix.

Updated by naruse (Yui NARUSE) about 1 year ago

  • Backport changed from 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: REQUIRED to 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: DONE

ruby_3_2 fee5b8f263211faef10ed9f3e43c1e8b34548bbd merged revision(s) 2c93c554019ebdc394d3c51c6d925620d3005f84,f5ea43a2e61789357e9c4b374b4bc6756abeae17.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0