From: mame@... Date: 2016-03-27T06:43:37+00:00 Subject: [ruby-core:74602] [Ruby trunk Bug#12220] Why does Coverage keep previously-loaded files as empty arrays? Issue #12220 has been updated by Yusuke Endoh. Tsuyoshi Sawada wrote: > Yusuke Endoh wrote: > >the first implementation actually did completely remove the key-value pairs when `Coverage.result` is called, as eregon requested. > > I can't find what eregon's request is. Heh, you said "my interpretation is that Benoit Daloze wants the key-value pairs to be removed when the value is an empty array". My interpretation is the same. > >Did you read #4796? > > I may have not understood it. But, isn't returning an empty array meaningless (unless the file is empty)? If `set.rb` is to be returned in the result but has not been called, it should return an array filled with `nil` or `0`: Your request is a duplicate of #9572. In that ticket, Sam Rawlins said "I'm not really in favor of knowingly reporting inaccurate data on restart". I agree with him. In addition, now there is a better API, `Coverage.peek_result`, to calculate a coverage difference. Currently I have no motivation to change the behavior of `Coverage.result`. -- Yusuke Endoh ---------------------------------------- Bug #12220: Why does Coverage keep previously-loaded files as empty arrays? https://bugs.ruby-lang.org/issues/12220#change-57730 * Author: Benoit Daloze * Status: Open * Priority: Normal * Assignee: Yusuke Endoh * ruby -v: ruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-linux] * Backport: 2.1: UNKNOWN, 2.2: UNKNOWN, 2.3: UNKNOWN ---------------------------------------- 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? -- https://bugs.ruby-lang.org/ Unsubscribe: