From 94d6295b2d41227b47f44b30f3e46a666b13d7f7 Mon Sep 17 00:00:00 2001 From: Kevin Newton Date: Thu, 25 Apr 2024 08:50:23 -0400 Subject: [PATCH] [PRISM] Enable coverage in eval ISEQs --- iseq.c | 11 +++++++++-- spec/prism.mspec | 1 - 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/iseq.c b/iseq.c index 3a31c4ca13..c07a320620 100644 --- a/iseq.c +++ b/iseq.c @@ -952,8 +952,15 @@ rb_iseq_t * pm_iseq_new_eval(pm_scope_node_t *node, VALUE name, VALUE path, VALUE realpath, int first_lineno, const rb_iseq_t *parent, int isolated_depth) { - return pm_iseq_new_with_opt(node, name, path, realpath, first_lineno, - parent, isolated_depth, ISEQ_TYPE_EVAL, &COMPILE_OPTION_DEFAULT); + if (rb_get_coverage_mode() & COVERAGE_TARGET_EVAL) { + VALUE coverages = rb_get_coverages(); + if (RTEST(coverages) && RTEST(path) && !RTEST(rb_hash_has_key(coverages, path))) { + iseq_setup_coverage(coverages, path, ((int) (node->parser->newline_list.size - 1)) + first_lineno - 1); + } + } + + return pm_iseq_new_with_opt(node, name, path, realpath, first_lineno, + parent, isolated_depth, ISEQ_TYPE_EVAL, &COMPILE_OPTION_DEFAULT); } static inline rb_iseq_t * diff --git a/spec/prism.mspec b/spec/prism.mspec index 832bba5ce5..a4a5a343ee 100644 --- a/spec/prism.mspec +++ b/spec/prism.mspec @@ -25,5 +25,4 @@ MSpec.register(:exclude, "TracePoint#path equals \"(eval at __FILE__:__LINE__)\" ## Library MSpec.register(:exclude, "Coverage.result returns the correct results when eval coverage is disabled") -MSpec.register(:exclude, "Coverage.start measures coverage within eval") MSpec.register(:exclude, "Socket.gethostbyaddr using an IPv6 address with an explicit address family raises SocketError when the address is not supported by the family")