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

Test "if" condition usefuleness #1284

Open
kubawerlos opened this issue Jul 23, 2020 · 3 comments
Open

Test "if" condition usefuleness #1284

kubawerlos opened this issue Jul 23, 2020 · 3 comments

Comments

@kubawerlos
Copy link
Contributor

Would it make sense to test if the if condition is useful?

The mutation would be:

-if ($foo) {
+if (true || $foo) {
     return 1;
 }
 return 3;
@maks-rafalko
Copy link
Member

maks-rafalko commented Jul 23, 2020

Are you saying only about cases when variable (not negated) is used in an if statement?

because, we already have other mutators that do

- if (! $var)
+ if ($var)

- if ($var === 1)
+ if ($var !== 1)

...

If yes, then probably makes sense, but we will definitely need to analyze the results of this mutator (how many mutants are created / escaped / killed) to understand if it's useful one or not

@kubawerlos
Copy link
Contributor Author

No, not only, in general test "if" condition.

Maybe better example would be with with return false.

The real life scenario would be some validator like this:

function isValid($a, $b, $c)
{
    if ($a || someGlobalFunction($a)) {
        return true;
    }
    if ($b) {
        return false;
    }
    if ($c) {
        return true;
    }
    return false;
}

and adding false && (...) to the condition (not true || as my first post - but maybe both mutation make sense) would verify if each condition is useful because maybe the other ifs handle all tests cases.

we will definitely need to analyze the results of this mutator

Is there any good practise flow for that? Or do you mean writing the mutator and running it in some "random" repositories and see the output?

@maks-rafalko
Copy link
Member

This one is probably related to #243

Is there any good practise flow for that? Or do you mean writing the mutator and running it in some "random" repositories and see the output?

You can see e.g. #1215 (comment) - there is a table with stats that can be generated by perMutator logger, see https://infection.github.io/guide/usage.html

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

No branches or pull requests

2 participants