8000 merge revision(s) 0d6263bd416338a339651fb97fe4d62701704c4b: [Backport… · github/ruby@1b6f9cd · GitHub
[go: up one dir, main page]

Skip to content

Commit 1b6f9cd

Browse files
committed
merge revision(s) 0d6263b: [Backport #21220]
Fix coverage measurement for negative line numbers Fixes [Bug #21220] Co-Authored-By: Mike Bourgeous <mike@mikebourgeous.com> Co-Authored-By: Jean Boussier <jean.boussier@gmail.com>
1 parent 9abd48d commit 1b6f9cd

File tree

5 files changed

+21
-3
lines changed

5 files changed

+21
-3
lines changed

compile.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10643,7 +10643,7 @@ iseq_compile_each0(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *const no
1064310643
if (nd_fl_newline(node)) {
1064410644
int event = RUBY_EVENT_LINE;
1064510645
ISEQ_COMPILE_DATA(iseq)->last_line = line;
10646-
if (ISEQ_COVERAGE(iseq) && ISEQ_LINE_COVERAGE(iseq)) {
10646+
if (line > 0 && ISEQ_COVERAGE(iseq) && ISEQ_LINE_COVERAGE(iseq)) {
1064710647
event |= RUBY_EVENT_COVERAGE_LINE;
1064810648
}
1064910649
ADD_TRACE(ret, event);

prism_compile.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8599,7 +8599,7 @@ pm_compile_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *const ret,
85998599
int event = RUBY_EVENT_LINE;
86008600

86018601
ISEQ_COMPILE_DATA(iseq)->last_line = lineno;
8602-
if (ISEQ_COVERAGE(iseq) && ISEQ_LINE_COVERAGE(iseq)) {
8602+
if (lineno > 0 && ISEQ_COVERAGE(iseq) && ISEQ_LINE_COVERAGE(iseq)) {
86038603
event |= RUBY_EVENT_COVERAGE_LINE;
86048604
}
86058605
PUSH_TRACE(ret, event);

test/coverage/test_coverage.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,23 @@ def test_eval_coverage
192192
end;
193193
end
194194

195+
def test_eval_negative_lineno
196+
assert_in_out_err(ARGV, <<-"end;", ["[1, 1, 1]"], [])
197+
Coverage.start(eval: true, lines: true)
198+
199+
eval(<<-RUBY, TOPLEVEL_BINDING, "test.rb", -2)
200+
p # -2 # Not subject to measurement
201+
p # -1 # Not subject to measurement
202+
p # 0 # Not subject to measurement
203+
p # 1 # Subject to measurement
204+
p # 2 # Subject to measurement
205+
p # 3 # Subject to measurement
206+
RUBY
207+
208+
p Coverage.result["test.rb"][:lines]
209+
end;
210+
end
211+
195212
def test_coverage_supported
196213
assert Coverage.supported?(:lines)
197214
assert Coverage.supported?(:oneshot_lines)

thread.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5667,6 +5667,7 @@ update_line_coverage(VALUE data, const rb_trace_arg_t *trace_arg)
56675667
VALUE lines = RARRAY_AREF(coverage, COVERAGE_INDEX_LINES);
56685668
if (lines) {
56695669
long line = rb_sourceline() - 1;
5670+
VM_ASSERT(line >= 0);
56705671
long count;
56715672
VALUE num;
56725673
void rb_iseq_clear_event_flags(const rb_iseq_t *iseq, size_t pos, rb_event_flag_t reset);

version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR
1212
#define RUBY_VERSION_TEENY 2
1313
#define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR
14-
#define RUBY_PATCHLEVEL 31
14+
#define RUBY_PATCHLEVEL 32
1515

1616
#include "ruby/version.h"
1717
#include "ruby/internal/abi.h"

0 commit comments

Comments
 (0)
0