summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Newton <kddnewton@gmail.com>2024-04-25 08:48:20 -0400
committerKevin Newton <kddnewton@gmail.com>2024-04-26 12:25:45 -0400
commit49764869af13002b4e3002b7461ff341f3d8f5d5 (patch)
treed3f62c710c3c6d9a078c0bb2e2be43679ac9c1bc
parentaf800bef210f5cca5acdcfd874b1391d44eec29c (diff)
[PRISM] Enable coverage in top and main iseqs
-rw-r--r--iseq.c18
-rw-r--r--spec/prism.mspec11
2 files changed, 8 insertions, 21 deletions
diff --git a/iseq.c b/iseq.c
index 364ca63cf3..3a31c4ca13 100644
--- a/iseq.c
+++ b/iseq.c
@@ -862,10 +862,8 @@ ast_line_count(const VALUE vast)
}
static VALUE
-iseq_setup_coverage(VALUE coverages, VALUE path, const VALUE vast, int line_offset)
+iseq_setup_coverage(VALUE coverages, VALUE path, int line_count)
{
- int line_count = line_offset + ast_line_count(vast);
-
if (line_count >= 0) {
int len = (rb_get_coverage_mode() & COVERAGE_TARGET_ONESHOT_LINES) ? 0 : line_count;
@@ -879,19 +877,19 @@ iseq_setup_coverage(VALUE coverages, VALUE path, const VALUE vast, int line_offs
}
static inline void
-iseq_new_setup_coverage(VALUE path, const VALUE vast, int line_offset)
+iseq_new_setup_coverage(VALUE path, int line_count)
{
VALUE coverages = rb_get_coverages();
if (RTEST(coverages)) {
- iseq_setup_coverage(coverages, path, vast, line_offset);
+ iseq_setup_coverage(coverages, path, line_count);
}
}
rb_iseq_t *
rb_iseq_new_top(const VALUE vast, VALUE name, VALUE path, VALUE realpath, const rb_iseq_t *parent)
{
- iseq_new_setup_coverage(path, vast, 0);
+ iseq_new_setup_coverage(path, ast_line_count(vast));
return rb_iseq_new_with_opt(vast, name, path, realpath, 0, parent, 0,
ISEQ_TYPE_TOP, &COMPILE_OPTION_DEFAULT,
@@ -904,7 +902,7 @@ rb_iseq_new_top(const VALUE vast, VALUE name, VALUE path, VALUE realpath, const
rb_iseq_t *
pm_iseq_new_top(pm_scope_node_t *node, VALUE name, VALUE path, VALUE realpath, const rb_iseq_t *parent)
{
- // iseq_new_setup_coverage(path, ast, 0);
+ iseq_new_setup_coverage(path, (int) (node->parser->newline_list.size - 1));
return pm_iseq_new_with_opt(node, name, path, realpath, 0, parent, 0,
ISEQ_TYPE_TOP, &COMPILE_OPTION_DEFAULT);
@@ -913,7 +911,7 @@ pm_iseq_new_top(pm_scope_node_t *node, VALUE name, VALUE path, VALUE realpath, c
rb_iseq_t *
rb_iseq_new_main(const VALUE vast, VALUE path, VALUE realpath, const rb_iseq_t *parent, int opt)
{
- iseq_new_setup_coverage(path, vast, 0);
+ iseq_new_setup_coverage(path, ast_line_count(vast));
return rb_iseq_new_with_opt(vast, rb_fstring_lit("<main>"),
path, realpath, 0,
@@ -928,7 +926,7 @@ rb_iseq_new_main(const VALUE vast, VALUE path, VALUE realpath, const rb_iseq_t *
rb_iseq_t *
pm_iseq_new_main(pm_scope_node_t *node, VALUE path, VALUE realpath, const rb_iseq_t *parent, int opt)
{
- // iseq_new_setup_coverage(path, ast, 0);
+ iseq_new_setup_coverage(path, (int) (node->parser->newline_list.size - 1));
return pm_iseq_new_with_opt(node, rb_fstring_lit("<main>"),
path, realpath, 0,
@@ -941,7 +939,7 @@ rb_iseq_new_eval(const VALUE vast, VALUE name, VALUE path, VALUE realpath, int f
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, vast, first_lineno - 1);
+ iseq_setup_coverage(coverages, path, ast_line_count(vast) + first_lineno - 1);
}
}
diff --git a/spec/prism.mspec b/spec/prism.mspec
index ff84fb053d..832bba5ce5 100644
--- a/spec/prism.mspec
+++ b/spec/prism.mspec
@@ -24,17 +24,6 @@ MSpec.register(:exclude, "TracePoint.new includes multiple events when multiple
MSpec.register(:exclude, "TracePoint#path equals \"(eval at __FILE__:__LINE__)\" inside an eval for :end event")
## Library
-MSpec.register(:exclude, "Coverage.peek_result returns the result so far")
-MSpec.register(:exclude, "Coverage.peek_result second call after require returns accumulated result")
-MSpec.register(:exclude, "Coverage.result gives the covered files as a hash with arrays of count or nil")
-MSpec.register(:exclude, "Coverage.result returns results for each mode separately when enabled :all modes")
-MSpec.register(:exclude, "Coverage.result returns results for each mode separately when enabled any mode explicitly")
-MSpec.register(:exclude, "Coverage.result returns the correct results when eval coverage is enabled")
MSpec.register(:exclude, "Coverage.result returns the correct results when eval coverage is disabled")
-MSpec.register(:exclude, "Coverage.result clears counters (sets 0 values) when stop is not specified but clear: true specified")
-MSpec.register(:exclude, "Coverage.result does not clear counters when stop is not specified but clear: false specified")
-MSpec.register(:exclude, "Coverage.result does not clear counters when stop: false and clear is not specified")
-MSpec.register(:exclude, "Coverage.result clears counters (sets 0 values) when stop: false and clear: true specified")
-MSpec.register(:exclude, "Coverage.result does not clear counters when stop: false and clear: false specified")
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")