3 ms·
It's only possible to execute all lines if you take/don't take every if branch. They're the same.
by IshKebab 4y ago
It's only possible to execute all lines if you take/don't take every if branch. They're the same.
- mort96 4y agoNo? Take this code: void foo(int arg) { int *x = malloc(sizeof(int)); if (arg) { free(x); } } If your test only ever calls `foo` with a non-zero `arg`, you have covered 100% of the lines in the function, but you never discover the memory leak bug in the case where `if` body isn't executed.
- rhdunn 4y agoAn if statement without an else can have the case where line coverage does not cover the "don't take the branch" part of branch coverage. Therefore, if not taking that branch results in a bug line coverage only will not pick up that bug. -- For example, if you initialize a value in an if statement's then branch but don't have a default value for it or an else branch to provide a default. Or even if you have a ternary operator (which has an implicit if-then-else take/don't take branch) that is usually only one line.