From: "ioquatix (Samuel Williams)" Date: 2022-09-18T00:01:02+00:00 Subject: [ruby-core:109942] [Ruby master Feature#19008] Introduce coverage support for `eval`. Issue #19008 has been updated by ioquatix (Samuel Williams). @mame thanks for all your feedback and edge cases. I have this working now (proof of concept). (1) How to deal with `(eval)`? We can disable coverage for `eval` called without path (current implementation). This feels like the correct behaviour for "anonymous eval". (2) `eval(..., "notexist.rb")` I am not sure this is a problem. In any case, someone can `load(path)` and then delete it, so this is essentially already a possible state. (3) `eval(..., "some_other.rb")` I think this is the expected behaviour, and is also possible if someone deletes and recreates the file. (4) If you specify a line offset, that's added to the instruction sequence line offset, so it triggers coverage for that line. Of course, if the line doesn't exist in the actual code, we can either add it (extend `lines` array) or ignore it (current implementation). I'm the author of a coverage tool (covered) and these problems already exist, because people are already writing coverage tools to intercept `eval` and compute coverage. I found some PRs in Rails which fix the above issues in the past, so people are aware of the issues w.r.t. `eval` and incorrect path/file/line offsets, and the need for `eval` in those contexts to match the same number of lines in the source file, or coverage would be incorrect. e.g. Previously in Rails, I saw something like `eval("def foo\nbar\nend")` but when I looked at it recently, it was expanded correctly, so it doesn't cause coverage bugs. If you want, I'll go looking for the PR, but it was a long time ago, so if you can trust me that this exists, it will save me some time and effort (to go searching through Rails code). ---------------------------------------- Feature #19008: Introduce coverage support for `eval`. https://bugs.ruby-lang.org/issues/19008#change-99189 * 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: