summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authormame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-09-14 03:25:36 +0000
committermame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-09-14 03:25:36 +0000
commitce570370f0f1e2aaf8c58d4b6629a627b7e7085b (patch)
treec0824cbcc23b9aacf694750e6f83b8b780da828d /ext
parentc171ca1efdbc5553f9ba94e9ce4e7d868f3cb298 (diff)
Add branch coverage for if statement
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59876 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext')
-rw-r--r--ext/coverage/coverage.c27
1 files changed, 26 insertions, 1 deletions
diff --git a/ext/coverage/coverage.c b/ext/coverage/coverage.c
index a286cf9..e484548 100644
--- a/ext/coverage/coverage.c
+++ b/ext/coverage/coverage.c
@@ -67,6 +67,31 @@ rb_coverage_start(int argc, VALUE *argv, VALUE klass)
return Qnil;
}
+static VALUE
+branch_coverage(VALUE branches)
+{
+ VALUE ret = rb_hash_new();
+ VALUE structure = rb_ary_dup(RARRAY_AREF(branches, 0));
+ VALUE counters = rb_ary_dup(RARRAY_AREF(branches, 1));
+ int i, j, id = 0;
+
+ for (i = 0; i < RARRAY_LEN(structure); i++) {
+ VALUE branches = RARRAY_AREF(structure, i);
+ VALUE base_type = RARRAY_AREF(branches, 0);
+ VALUE base_lineno = RARRAY_AREF(branches, 1);
+ VALUE children = rb_hash_new();
+ rb_hash_aset(ret, rb_ary_new_from_args(3, base_type, INT2FIX(id++), base_lineno), children);
+ for (j = 2; j < RARRAY_LEN(branches); j += 3) {
+ VALUE target_label = RARRAY_AREF(branches, j);
+ VALUE target_lineno = RARRAY_AREF(branches, j + 1);
+ int idx = FIX2INT(RARRAY_AREF(branches, j + 2));
+ rb_hash_aset(children, rb_ary_new_from_args(3, target_label, INT2FIX(id++), target_lineno), RARRAY_AREF(counters, idx));
+ }
+ }
+
+ return ret;
+}
+
static int
coverage_peek_result_i(st_data_t key, st_data_t val, st_data_t h)
{
@@ -92,7 +117,7 @@ coverage_peek_result_i(st_data_t key, st_data_t val, st_data_t h)
}
if (branches) {
- rb_hash_aset(h, ID2SYM(rb_intern("branches")), branches);
++ rb_hash_aset(h, ID2SYM(rb_intern("branches")), branch_coverage(branches));
}
if (methods) {