flacoco icon indicating copy to clipboard operation
flacoco copied to clipboard

Include `while (true)` lines in coverage

Open andre15silva opened this issue 4 years ago • 5 comments

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

andre15silva avatar Jul 19 '21 13:07 andre15silva

In https://github.com/SpoonLabs/astor/tree/master/examples/quixbugscompiled/breadth_first_search it is included

andre15silva avatar Jul 20 '21 08:07 andre15silva

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

martinezmatias avatar Jul 21 '21 12:07 martinezmatias

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.

andre15silva avatar Jul 21 '21 13:07 andre15silva

You can see https://github.com/SpoonLabs/flacoco/pull/69 now

andre15silva avatar Jul 21 '21 13:07 andre15silva

Perfect. I see now that in the PR the example has the while(true)

martinezmatias avatar Jul 22 '21 08:07 martinezmatias