ASSERT-KTH / flacoco

FLACOCO: Fault Localization for Java based on Industry-grade Coverage http://arxiv.org/pdf/2111.12513
MIT License
28 stars 15 forks source link

Include `while (true)` lines in coverage #67

Open andre15silva opened 3 years ago

andre15silva commented 3 years ago

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 commented 3 years ago

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

martinezmatias commented 3 years ago

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

andre15silva commented 3 years ago

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 commented 3 years ago

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

martinezmatias commented 3 years ago

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