Feature #14888


Add trace point for eval (and related functions)

Added by ioquatix (Samuel Williams) over 4 years ago. Updated almost 4 years ago.

Target version:


I'm working on an improved coverage library for Ruby which can compute coverage of things like ERB templates where the source file is not Ruby code but is translated to Ruby code using eval.

When using the line trace point, the path is the original template file (e.g. page.erb), which is problematic because this file isn't Ruby code nor do we generally know how to handle that file.

Ideally, we capture calls to eval, including the source, line number, and path, so we can match up with the path given by the line trace point and parse the correct source/ast.

In order to do that, it would be great to have a specific trace point for eval (and related functions). Ideally, the trace point would capture all the arguments to eval so they could be processed correctly. This would allow such coverage library to correctly find the right code/AST for a given file path.

Updated by marcandre (Marc-Andre Lafortune) over 4 years ago

You can already use TracePoint to "catch" the calls to eval:

TracePoint.trace(:c_call) do |tp|
  if tp.callee_id == :eval
    p "Eval called!"

This won't give you access to the arguments though. I'm not sure there's a good reason why the arguments are not available within a TracePoint of type call or c_call, that might be a good thing to propose if it hasn't already.

Not answering your question, but given this issue and #14889, you seem to want to use TracePoint as a code coverage tool. You may want to check out DeepCover instead. We're interested in supporting some templating tools out of the box (ERB, Haml, slim) and didn't really take the time to check how difficult that would be. I remember checking ERB's API; it is very crude and would not allow it (without redoing the ERB parsing ourselves).

Updated by ioquatix (Samuel Williams) over 4 years ago

@marcandre (Marc-Andre Lafortune) I already added support for coverage of templates and it works pretty well. You need to be careful with template code generation, but for the most part it's fairly straight forward. Thanks for your detailed reply - if we could expose arguments, it would be suitable. Keep in mind, there are multiple eval functions, here is what I ended up doing:

Actions #3

Updated by nobu (Nobuyoshi Nakada) about 4 years ago

  • Status changed from Open to Assigned
  • Assignee set to ko1 (Koichi Sasada)

Updated by ko1 (Koichi Sasada) almost 4 years ago

sorry to left this ticket.

script_compiled solves it?
[Feature #15287]

Updated by ioquatix (Samuel Williams) almost 4 years ago

@ko1 (Koichi Sasada) that sounds great, I will try it out.

Updated by ioquatix (Samuel Williams) almost 4 years ago

  • Status changed from Assigned to Closed

I believe this is fixed by Feature #15287

Thanks @ko1 (Koichi Sasada)


Also available in: Atom PDF