From: "mame (Yusuke Endoh)" <noreply@...> Date: 2022-09-17T10:15:10+00:00 Subject: [ruby-core:109938] [Ruby master Feature#19008] Introduce coverage support for `eval`. Issue #19008 has been updated by mame (Yusuke Endoh). Basically I am okay to this proposal. When I first created coverage.so, I tried to support eval. But @ko1 objected to it because the source code for eval is not retained and there is no clear need for it. But I just talked to @ko1, and he seems not to be negative about this change now. I think it is great if it works great with ERB (I don't confirm it myself, though). But note that this change would be an incompatible change. ``` $ cat t.rb require "coverage" Coverage.start load "tt.rb" p Coverage.result $ cat tt.rb eval(<<END) p 1 END $ ./local/bin/ruby t.rb 1 {"tt.rb"=>[1, nil, nil], "(eval)"=>[1]} ``` For real-world programs, `Coverage.result` would include many `"eval"=>...`. Even worse, it may refer to a wrong file: ``` $ cat tt.rb eval(<<END, nil, "notexist.rb") p 1 END $ ./local/bin/ruby t.rb 1 {"tt.rb"=>[1, nil, nil], "notexist.rb"=>[1]} ``` It could corrupt the result of an existing file: ``` $ cat tt.rb # comment line eval(<<END, nil, "tt.rb") x = 1 END $ ./local/bin/ruby t.rb {"tt.rb"=>[1, nil, 1, nil, nil]} ``` It wrongly records Line 1. Note that there is only a comment in Line 1 of tt.rb. I have no idea how it should behave when the fourth argument of eval is supplied: ``` $ cat tt.rb eval(<<END, nil, "notexist.rb", 100) x = 1 END $ ./local/bin/ruby t.rb {"tt.rb"=>[1, nil, nil], "notexist.rb"=>[nil]} ``` I'd like to hear from the users of coverage.so, like the authors of coverage tools. ---------------------------------------- Feature #19008: Introduce coverage support for `eval`. https://bugs.ruby-lang.org/issues/19008#change-99185 * Author: ioquatix (Samuel Williams) * Status: Open * Priority: Normal ---------------------------------------- I'd like to introduce coverage support for `eval`. I mostly only care about the case where an explicit path is given, and I'd even be okay to only handle the case where the line number is the default (0). https://github.com/ruby/ruby/pull/6396 This is an incredibly useful feature for computing coverage of ERB templates and other similar things. -- 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>