merge revision(s) 0d6263bd416338a339651fb97fe4d62701704c4b: [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>
This commit is contained in:
parent
1c68aae91f
commit
b1b6752fbe
@ -9783,7 +9783,7 @@ iseq_compile_each0(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *const no
|
|||||||
if (nd_fl_newline(node)) {
|
if (nd_fl_newline(node)) {
|
||||||
int event = RUBY_EVENT_LINE;
|
int event = RUBY_EVENT_LINE;
|
||||||
ISEQ_COMPILE_DATA(iseq)->last_line = line;
|
ISEQ_COMPILE_DATA(iseq)->last_line = line;
|
||||||
if (ISEQ_COVERAGE(iseq) && ISEQ_LINE_COVERAGE(iseq)) {
|
if (line > 0 && ISEQ_COVERAGE(iseq) && ISEQ_LINE_COVERAGE(iseq)) {
|
||||||
event |= RUBY_EVENT_COVERAGE_LINE;
|
event |= RUBY_EVENT_COVERAGE_LINE;
|
||||||
}
|
}
|
||||||
ADD_TRACE(ret, event);
|
ADD_TRACE(ret, event);
|
||||||
|
@ -2786,7 +2786,7 @@ pm_compile_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *const ret,
|
|||||||
int event = RUBY_EVENT_LINE;
|
int event = RUBY_EVENT_LINE;
|
||||||
|
|
||||||
ISEQ_COMPILE_DATA(iseq)->last_line = lineno;
|
ISEQ_COMPILE_DATA(iseq)->last_line = lineno;
|
||||||
if (ISEQ_COVERAGE(iseq) && ISEQ_LINE_COVERAGE(iseq)) {
|
if (lineno > 0 && ISEQ_COVERAGE(iseq) && ISEQ_LINE_COVERAGE(iseq)) {
|
||||||
event |= RUBY_EVENT_COVERAGE_LINE;
|
event |= RUBY_EVENT_COVERAGE_LINE;
|
||||||
}
|
}
|
||||||
ADD_TRACE(ret, event);
|
ADD_TRACE(ret, event);
|
||||||
|
@ -181,6 +181,23 @@ class TestCoverage < Test::Unit::TestCase
|
|||||||
end;
|
end;
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_eval_negative_lineno
|
||||||
|
assert_in_out_err(["-rcoverage"], <<-"end;", ["[1, 1, 1]"], [])
|
||||||
|
Coverage.start(eval: true, lines: true)
|
||||||
|
|
||||||
|
eval(<<-RUBY, TOPLEVEL_BINDING, "test.rb", -2)
|
||||||
|
p # -2 # Not subject to measurement
|
||||||
|
p # -1 # Not subject to measurement
|
||||||
|
p # 0 # Not subject to measurement
|
||||||
|
p # 1 # Subject to measurement
|
||||||
|
p # 2 # Subject to measurement
|
||||||
|
p # 3 # Subject to measurement
|
||||||
|
RUBY
|
||||||
|
|
||||||
|
p Coverage.result["test.rb"][:lines]
|
||||||
|
end;
|
||||||
|
end
|
||||||
|
|
||||||
def test_coverage_supported
|
def test_coverage_supported
|
||||||
assert Coverage.supported?(:lines)
|
assert Coverage.supported?(:lines)
|
||||||
assert Coverage.supported?(:oneshot_lines)
|
assert Coverage.supported?(:oneshot_lines)
|
||||||
|
1
thread.c
1
thread.c
@ -5589,6 +5589,7 @@ update_line_coverage(VALUE data, const rb_trace_arg_t *trace_arg)
|
|||||||
VALUE lines = RARRAY_AREF(coverage, COVERAGE_INDEX_LINES);
|
VALUE lines = RARRAY_AREF(coverage, COVERAGE_INDEX_LINES);
|
||||||
if (lines) {
|
if (lines) {
|
||||||
long line = rb_sourceline() - 1;
|
long line = rb_sourceline() - 1;
|
||||||
|
VM_ASSERT(line >= 0);
|
||||||
long count;
|
long count;
|
||||||
VALUE num;
|
VALUE num;
|
||||||
void rb_iseq_clear_event_flags(const rb_iseq_t *iseq, size_t pos, rb_event_flag_t reset);
|
void rb_iseq_clear_event_flags(const rb_iseq_t *iseq, size_t pos, rb_event_flag_t reset);
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
# define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR
|
# define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR
|
||||||
#define RUBY_VERSION_TEENY 8
|
#define RUBY_VERSION_TEENY 8
|
||||||
#define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR
|
#define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR
|
||||||
#define RUBY_PATCHLEVEL 145
|
#define RUBY_PATCHLEVEL 146
|
||||||
|
|
||||||
#include "ruby/version.h"
|
#include "ruby/version.h"
|
||||||
#include "ruby/internal/abi.h"
|
#include "ruby/internal/abi.h"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user