Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include while (true) lines in coverage #67

Open
andre15silva opened this issue Jul 19, 2021 · 5 comments
Open

Include while (true) lines in coverage #67

andre15silva opened this issue Jul 19, 2021 · 5 comments

Comments

@andre15silva
Copy link
Member

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
Copy link
Member Author

@martinezmatias
Copy link
Collaborator

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
Copy link
Member Author

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 added a commit to andre15silva/flacoco that referenced this issue Jul 21, 2021
@andre15silva
Copy link
Member Author

You can see #69 now

@martinezmatias
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants