Hywan / atoum-instrumentation

The atoum\instrumentation library. Instrumentation for PHP (moles, code coverage…)
7 stars 2 forks source link

Mark line before they are executed #7

Closed jubianchi closed 10 years ago

jubianchi commented 10 years ago

Using Hywan/atoum-instrumentation@25829d0

Given the following source code:

<?php

namespace hey;

class foo
{
    public function bar($a, $b)
    {
        $a += 12;
        $b = $b ?: rand(0, 10);

        return $a + $b;
    }
}

I get the following instrumented code:

<?php

namespace hey;

class foo
{
    public function bar($a, $b)
    { if(\atoum\instrumentation\mole::exists('foo::bar')) return \atoum\instrumentation\mole::call('foo::bar', $this, func_get_args());
        $a += 12;mark_line(__LINE__);
        $b = $b ?: rand(0, 10);mark_line(__LINE__);

        mark_line(__LINE__);return $a + $b;
    }
}

I think the mark_line method should be called before the line it marks is executed because, if this line throws an error, it won't be marked as covered even if it was in fact.

Hywan commented 10 years ago

mark_line and mark_cond were just present for the POC. There are going to be deleted.

jubianchi commented 10 years ago

Ok but if you deleted those two functions, how would you mark covered lines/conditionals ?

Hywan commented 10 years ago

With others functions and with another API ;-). I will mimic a control flow graph with markers.