JoinColony / solcover

Code coverage for solidity
MIT License
64 stars 8 forks source link

Remove newline condition for statement coverage #4

Closed cgewecke closed 7 years ago

cgewecke commented 7 years ago

This PR removes a condition that allows statements to be instrumented if they are preceded by a newline because there are common cases where non-self-contained statements span several lines. For example:

if (x == 1)
    throw;

produces this error

Error: Instrumented solidity invalid: :13:40: Error: Expected primary expression.
{BranchCoverage('test.sol',1,0);throw;}else { BranchCoverage('test.sol',1,1);}

and is currently instrumented as

StatementCoverage('test.sol',1);
if (x==1) 
                     StatementCoverage('test.sol',2);
{BranchCoverage('test.sol',1,0);throw;}else { BranchCoverage('test.sol',1,1);}

This also happens when statements that are arguments to a function are broken up across lines per the solidity style guide:

Person a = Person(
    paramA,
    paramB,
    paramC,
    address(0x579fadbb36a7b7284ef4e50bbc83f3f294e9a8ec)
);

I think the newline condition can be removed without reducing the accuracy of the coverage and the other two tests in instrumentStatementare adequate in themselves. (That definitely needs a sanity check though.)