ext/coverage/coverage.c: method coverage has column info. of method def.

This change makes method coverage result have not only first lineno of
method defintion, but also code range (i.e. first lineno, first column,
last lineno, and last column).

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61026 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
mame 2017-12-05 08:56:51 +00:00
Родитель a5e02f249d
Коммит f6556c5c39
2 изменённых файлов: 23 добавлений и 20 удалений

Просмотреть файл

@ -128,7 +128,7 @@ method_coverage_i(void *vstart, void *vend, size_t stride, void *data)
for (v = (VALUE)vstart; v != (VALUE)vend; v += stride) { for (v = (VALUE)vstart; v != (VALUE)vend; v += stride) {
if (RB_TYPE_P(v, T_IMEMO) && imemo_type(v) == imemo_ment) { if (RB_TYPE_P(v, T_IMEMO) && imemo_type(v) == imemo_ment) {
const rb_method_entry_t *me = (rb_method_entry_t *) v; const rb_method_entry_t *me = (rb_method_entry_t *) v;
VALUE path = Qundef, first_lineno = Qundef; VALUE path, first_lineno, first_column, last_lineno, last_column;
VALUE data[5], ncoverage, methods; VALUE data[5], ncoverage, methods;
VALUE methods_id = ID2SYM(rb_intern("methods")); VALUE methods_id = ID2SYM(rb_intern("methods"));
VALUE klass; VALUE klass;
@ -140,6 +140,9 @@ method_coverage_i(void *vstart, void *vend, size_t stride, void *data)
} }
path = data[0]; path = data[0];
first_lineno = data[1]; first_lineno = data[1];
first_column = data[2];
last_lineno = data[3];
last_column = data[4];
if (FIX2LONG(first_lineno) <= 0) continue; if (FIX2LONG(first_lineno) <= 0) continue;
ncoverage = rb_hash_aref(ncoverages, path); ncoverage = rb_hash_aref(ncoverages, path);
if (NIL_P(ncoverage)) continue; if (NIL_P(ncoverage)) continue;
@ -148,7 +151,7 @@ method_coverage_i(void *vstart, void *vend, size_t stride, void *data)
{ {
VALUE method_id = ID2SYM(me->def->original_id); VALUE method_id = ID2SYM(me->def->original_id);
VALUE rcount = rb_hash_aref(me2counter, (VALUE) me); VALUE rcount = rb_hash_aref(me2counter, (VALUE) me);
VALUE key = rb_ary_new_from_args(3, klass, method_id, first_lineno); VALUE key = rb_ary_new_from_args(6, klass, method_id, first_lineno, first_column, last_lineno, last_column);
VALUE rcount2 = rb_hash_aref(methods, key); VALUE rcount2 = rb_hash_aref(methods, key);
if (NIL_P(rcount)) rcount = LONG2FIX(0); if (NIL_P(rcount)) rcount = LONG2FIX(0);

Просмотреть файл

@ -340,16 +340,16 @@ class TestCoverage < Test::Unit::TestCase
def test_method_coverage def test_method_coverage
result = { result = {
:methods => { :methods => {
[Object, :bar, 2] => 1, [Object, :bar, 2, 0, 3, 3] => 1,
[Object, :baz, 4] => 0, [Object, :baz, 4, 1, 4, 13] => 0,
[Object, :foo, 1] => 2, [Object, :foo, 1, 0, 1, 12] => 2,
} }
} }
assert_coverage(<<-"end;", { methods: true }, result) assert_coverage(<<~"end;", { methods: true }, result)
def foo; end def foo; end
def bar def bar
end end
def baz; end def baz; end
foo foo
foo foo
@ -360,12 +360,12 @@ class TestCoverage < Test::Unit::TestCase
def test_method_coverage_for_define_method def test_method_coverage_for_define_method
result = { result = {
:methods => { :methods => {
[Object, :bar, 2] => 1, [Object, :bar, 2, 20, 3, 1] => 1,
[Object, :baz, 4] => 0, [Object, :baz, 4, 9, 4, 11] => 0,
[Object, :foo, 1] => 2, [Object, :foo, 1, 20, 1, 22] => 2,
} }
} }
assert_coverage(<<-"end;", { methods: true }, result) assert_coverage(<<~"end;", { methods: true }, result)
define_method(:foo) {} define_method(:foo) {}
define_method(:bar) { define_method(:bar) {
} }
@ -387,7 +387,7 @@ class TestCoverage < Test::Unit::TestCase
def test_method_coverage_for_alias def test_method_coverage_for_alias
_C = DummyConstant.new("C") _C = DummyConstant.new("C")
_M = DummyConstant.new("M") _M = DummyConstant.new("M")
code = <<-"end;" code = <<~"end;"
module M module M
def foo def foo
end end
@ -403,19 +403,19 @@ class TestCoverage < Test::Unit::TestCase
result = { result = {
:methods => { :methods => {
[_C, :baz, 8] => 0, [_C, :baz, 8, 2, 9, 5] => 0,
[_M, :foo, 2] => 0, [_M, :foo, 2, 2, 3, 5] => 0,
} }
} }
assert_coverage(code, { methods: true }, result) assert_coverage(code, { methods: true }, result)
result = { result = {
:methods => { :methods => {
[_C, :baz, 8] => 12, [_C, :baz, 8, 2, 9, 5] => 12,
[_M, :foo, 2] => 3, [_M, :foo, 2, 2, 3, 5] => 3,
} }
} }
assert_coverage(code + <<-"end;", { methods: true }, result) assert_coverage(code + <<~"end;", { methods: true }, result)
obj = C.new obj = C.new
1.times { obj.foo } 1.times { obj.foo }
2.times { obj.bar } 2.times { obj.bar }
@ -427,7 +427,7 @@ class TestCoverage < Test::Unit::TestCase
def test_method_coverage_for_singleton_class def test_method_coverage_for_singleton_class
_singleton_Foo = DummyConstant.new("#<Class:Foo>") _singleton_Foo = DummyConstant.new("#<Class:Foo>")
_Foo = DummyConstant.new("Foo") _Foo = DummyConstant.new("Foo")
code = <<-"end;" code = <<~"end;"
class Foo class Foo
def foo def foo
end end
@ -447,8 +447,8 @@ class TestCoverage < Test::Unit::TestCase
result = { result = {
:methods => { :methods => {
[_singleton_Foo, :baz, 5] => 12, [_singleton_Foo, :baz, 5, 2, 6, 5] => 12,
[_Foo, :foo, 2] => 3, [_Foo, :foo, 2, 2, 3, 5] => 3,
} }
} }
assert_coverage(code, { methods: true }, result) assert_coverage(code, { methods: true }, result)