gotwarlost / istanbul

Yet another JS code coverage tool that computes statement, line, function and branch coverage with module loader hooks to transparently add coverage when running tests. Supports all JS coverage use cases including unit tests, server side functional tests and browser tests. Built for scale.
Other
8.7k stars 786 forks source link

What's the difference between statements and lines? #639

Closed lobabob closed 8 years ago

lobabob commented 8 years ago

Please let me know if there is a more appropriate place to ask this.

Most other coverage tools I've used before have either had statements or lines, never both leading me to think that they were one and the same. Istanbul however has both statements and lines. Can anyone clarify the difference between the two for me?

gotwarlost commented 8 years ago

if you have a line of code that says var x= 10; console.log(x) that's one line and 2 statements.

Of the two statement coverage is more accurate - however line coverage exists for interop with line oriented coverage tools like lcov and backwards compatibility with YUI coverage (for when istanbul was written, no longer relevant now)

fabianorodrigo commented 5 years ago

if you have a line of code that says var x= 10; console.log(x) that's one line and 2 statements.

Of the two statement coverage is more accurate - however line coverage exists for interop with line oriented coverage tools like lcov and backwards compatibility with YUI coverage (for when istanbul was written, no longer relevant now)

I'm using solidity-coverage, that uses Istanbul. In many cases I've got more lines than statements. How is that possible?

HelKyle commented 5 years ago

@fabianorodrigo like this return ; console.log('never run');, 2 statements in one line. while the second statement will never run.