From: "jeremyevans0 (Jeremy Evans)" Date: 2022-09-23T15:24:55+00:00 Subject: [ruby-core:110048] [Ruby master Feature#19008] Introduce coverage support for `eval`. Issue #19008 has been updated by jeremyevans0 (Jeremy Evans). ioquatix (Samuel Williams) wrote in #note-13: > Thanks Jeremy. > > > Your use case (ERB coverage) is apparently limited to files that aren't required. However, eval methods are used with __FILE__ on a regular basis for metaprogramming. > > My use case is general coverage, including files that are required, and include `eval`. I'm not sure why this is a problem, can you show a use case where this produces undesirable results (excepting code which is already invalid, like file and line numbers that don't make sense)? Consider this code: ```ruby class A %w'foo bar'.each do |meth| class_eval <<-RUBY, __FILE__, __LINE__+1 def #{meth}(v) if v do_#{meth}(v) else not_#{meth} end end RUBY end end ``` With `eval` coverage, you want to be sure that you can detect which `eval`ed code is covered and which is not. For example, in the above code, you would want the coverage to be able to tell you if all four branches are taken (if/else for foo and if/else for bar). Accumulating results for multiple `eval` runs into a single coverage entry does not do this. ioquatix (Samuel Williams) wrote in #note-15: > ```ruby > Coverage.start(eval_key: ->(file, line){"eval-#{file}:#{line}"}) > ``` > > What problem are you trying to solve? Current coverage tools expect the coverage result hash key is a string. This type of API would allow the user to control the hash key used. You could use it to get separate coverage per-eval (forcing all keys distinct), or to combine coverage for multiple evals (by using the same key more than once). ---------------------------------------- Feature #19008: Introduce coverage support for `eval`. https://bugs.ruby-lang.org/issues/19008#change-99298 * 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: