Issue #12220 has been updated by Tsuyoshi Sawada.


Yusuke Endoh wrote:
> Then, you want `Coverage.result` to remove all arrays from the Hash once, keep them in back, and automatically restore an array when the corresponding code is executed?  This is the third idea to make it "intuitive" that I thought of but didn't mention.  It is so complex and I don't see any use case.

I am not sure what you mean by "keep them in back, and automatically restore". I expect `Coverage.result` to remove all arrays, period. (Or to be more direct, clear/throw out the entire hash.) `Coverage.result` should just start with a fresh new hash.

The first `Coverage.result` should return:

~~~RUBY
{"/tmp/test.rb" => [1, 0, nil]}
~~~

and if the hash/array were "kept in the back", the second `Coverage.start` would have no effect, and the second `Coverage.result` would return:

~~~RUBY
{"/tmp/test.rb" => [1, 1, nil]}
~~~

My interpretation of #4796 is that, instead, we should have:

~~~RUBY
{"/tmp/test.rb" => [0, 1, nil]}
~~~


----------------------------------------
Bug #12220: Why does Coverage keep previously-loaded files as empty arrays?
https://bugs.ruby-lang.org/issues/12220#change-57886

* 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?

---Files--------------------------------
0001-ext-coverage-coverage.c-Fully-reset-coverage-to-not-.patch (5.14 KB)


-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>