Code coverage is an easy way to measure if we have enough tests, yet many of us have yet to use it.
This talk delves into the benefits of meaningful code coverage and how to avoid some of its pitfalls with a new tool called DeepCover.
24. Under the Hood - MRI
static int
iseq_compile_each0(rb_iseq_t *iseq, LINK_ANCHOR *const ret, ...)
{
const int line = (int)nd_line(node);
const enum node_type type = nd_type(node);
if (ISEQ_COMPILE_DATA(iseq)->last_line == line) {
/* ignore */
}
else {
if (node->flags & NODE_FL_NEWLINE) {
ISEQ_COMPILE_DATA(iseq)->last_line = line;
ADD_TRACE_LINE_COVERAGE(ret, line);
ADD_TRACE(ret, RUBY_EVENT_LINE);
}
}
// ...
ADD_TRACE_LINE_COVERAGE: same API as TracePoint, just not acccessible
from Ruby.
25. Under the Hood - MRI
// ...
switch (type) {
case NODE_BLOCK:{
while (node && nd_type(node) == NODE_BLOCK) {
CHECK(COMPILE_(ret, "BLOCK body", node->nd_head,
(node->nd_next ? 1 : popped)));
node = node->nd_next;
}
if (node) {
CHECK(COMPILE_(ret, "BLOCK next", node->nd_next, popped));
}
break;
}
case NODE_IF:
case NODE_UNLESS:
CHECK(compile_if(iseq, ret, node, popped, type));
break;
… 1600 more lines…