
Issue #19857 has been updated by ioquatix (Samuel Williams).
When I started developing the covearge library, I decided that its target is "source files that actually exist".
I completely agree with this and I don't think that statement has any bearing on this proposal.
The measured coverage is visually observed by a human, which requires source code, and Ruby interpreter did not keep the eval'ed source code (at that time). I think that the design decision to target only source files was natural.
Makes sense.
Because the Rails view code (.erb) exists as a file, I thought that it is the target of covearge library. So I accepted #19008.
That's reasonable.
Beyond that, measuring coverage on dynamically generated code conflicts with the coverage library's initial design decision.
That's not what this PR is doing?
To be honest, I don't want to further complicate the coverage library. Frankly, its API is already very complicated. I no longer want to expand it beyond the initial design decision.
This PR addresses a real world problem I ran into. I accept the example given isn't clear. However, I'd like to discuss this at developer meeting. ---------------------------------------- Bug #19857: Eval coverage is reset after each `eval`. https://bugs.ruby-lang.org/issues/19857#change-106243 * Author: ioquatix (Samuel Williams) * Status: Rejected * Priority: Normal * Assignee: ioquatix (Samuel Williams) * Backport: 3.0: DONTNEED, 3.1: DONTNEED, 3.2: REQUIRED ---------------------------------------- It seems like `eval` based coverage is reset every time eval is invoked. ```ruby #!/usr/bin/env ruby require 'coverage' def measure(flag) c = Class.new c.class_eval(<<~RUBY, "foo.rb", 1) def foo(flag) if flag puts "foo" else puts "bar" end end RUBY return c.new.foo(flag) end Coverage.start(lines: true, eval: true) # Depending on the order of these two operations, different coverage is calculated, because the evaluation of the code is considered different, even if the content/path is the same. measure(false) measure(true) p Coverage.result ``` Further investigation is required. -- https://bugs.ruby-lang.org/