Include `while (true)` lines in coverage
Right now, flacoco does not consider while loop conditions that have a constant value true in the coverage computation.
Example:
package fr.spoonlabs.FLtest1;
public class Calculator {
public Calculator() {
}
public int calculate(String op, int op1, int op2) {
while(true) {
if (op.equals("+")) {
return op1 + op2;
} else if (op.equals("-")) {
return op1 - op2;
} else if (op.equals("*")) {
return op1 / op2;//buggy
} else if (op.equals("/")) {
return op1 / op2;
} else if (op.equals("%")) {
return op1 % op2;
}
throw new UnsupportedOperationException(op);
}
}
}
Output:
fr/spoonlabs/FLtest1/Calculator@-@16,1.0
fr/spoonlabs/FLtest1/Calculator@-@15,0.7071067811865475
fr/spoonlabs/FLtest1/Calculator@-@13,0.5773502691896258
fr/spoonlabs/FLtest1/Calculator@-@11,0.5
fr/spoonlabs/FLtest1/Calculator@-@12,0.0
fr/spoonlabs/FLtest1/Calculator@-@14,0.0
fr/spoonlabs/FLtest1/Calculator@-@17,0.0
fr/spoonlabs/FLtest1/Calculator@-@18,0.0
while(true) { is on line 10.
Another example where this happens is https://github.com/SpoonLabs/astor/tree/master/examples/quixbugscompiled/detect_cycle
In https://github.com/SpoonLabs/astor/tree/master/examples/quixbugscompiled/breadth_first_search it is included
Hi @andre15silva
I could be the case that we have a mistake in our test data. Which is the project example related to Calculator that you test?
I see that the in some example projects that use Calculator, the while(true) does not exist.
Example:
https://github.com/SpoonLabs/flacoco/blob/master/examples/exampleFL1/FLtest1/src/main/java/fr/spoonlabs/FLtest1/Calculator.java
https://github.com/SpoonLabs/flacoco/blob/master/examples/exampleFL3/FLtest1/src/main/java/fr/spoonlabs/FLtest1/Calculator.java
Hi @martinezmatias
This is a new test case based on exampleFL1, sorry for not specifying it.
I haven't added it since it won't work, but I'll open a PR in a second so you can see.
You can see https://github.com/SpoonLabs/flacoco/pull/69 now
Perfect. I see now that in the PR the example has the while(true)