Project

General

Profile

Actions

Bug #12220

closed

Why does Coverage keep previously-loaded files as empty arrays?

Added by Eregon (Benoit Daloze) about 8 years ago. Updated almost 8 years ago.

Status:
Closed
Target version:
-
ruby -v:
ruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-linux]
[ruby-core:74596]

Description

For instance,

ruby -e 'require "coverage"; Coverage.start; require "set"; Coverage.result; Coverage.start; require "tmpdir"; p Coverage.result'
{".../lib/ruby/2.2.0/set.rb"=>[],
".../lib/ruby/2.2.0/tmpdir.rb"=>[nil, nil, nil, nil, nil, nil, 1, 1, ...]}

So Coverage.result stops coverage but also does some cleaning up.
I think the most intuitive would be that the coverage Hash would be reset to be empty, but instead it's filled with empty arrays.

As an example, this makes it fairly awkward to test and it enforces irreversible global state (https://github.com/ruby/spec/pull/219).
I also do not see how this would be useful for coverage libraries.

Is there a reason for this behavior?
If not, would it be OK to clear the Hash when calling #result?


Files

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0