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
Unexpected "syntax errors were encountered" after updating to 0.25.0 #1569
Comments
See #1564 (comment), it explains how to work with the logs and show more detailed info. I've run your repository with additional
So it looks like it is your code produces syntax error, not Infection (seems like code is not correctly fixed by You can read this topic #1566 and this comment in particular to get an idea how to kill such mutant: #1566 (reply in thread) |
Feel free to share your findings and reopen if you still think this is an Infection bug. For now, it looks like the change in the source code of the fixer produces incorrect behavior in your code. |
Looks like a bug to me, TBH. Reason: if we can't tell if something is a legitimate syntax error caused by Infection, we shouldn't report it as such. Alternatively, we could leave syntax errors to be reported only during debugging. This should go inline with our desire to help hackers to debug their custom mutators. |
If we look into this example, #1566 (reply in thread) I can't say that reporting syntax errors caused NOT by Infection is useless. This gives for the end developer information that some mutants will always lead to fatal (syntax) errors, without any ability to be escaped. Example: imagine we are writing code evaluator with the very simple logic: function evaluateCode(string $expression): void
{
eval($expression . ';');
} and Infection generates the following mutants function evaluateCode(string $expression): void
{
- eval($expression . ';');
+ eval($expression);
}
function evaluateCode(string $expression): void
{
- eval($expression . ';');
+ eval(';' . $expression);
} then, this application will always lead to syntax errors for those mutants: https://3v4l.org/JB7Hu Do we need to waste time generating them? IMO they are useless mutations that should be ignored, and displaying syntax errors with |
That's right. Shouldn't we then re-brand this feature as usable by end users instead of just developers? I mean, who could've known we'll find infection mutating code to cause actual syntax errors! Yes, it is fairly obvious in retrospect, but still. |
There are cases when after mutation code is still valid syntax and the error happens. Consider this code (of course it's simplification of the case that lead me to this report): $code = '<?php echo 42;X';
$code = \substr($code, 0, -1);
$tokens = \token_get_all($code, \TOKEN_PARSE); Mutator $code = '<?php echo 42;X';
$code = $code;
$tokens = \token_get_all($code, \TOKEN_PARSE); So I'd expect the mutant to be considered killed if there is a test for it or escaped if there is no test. I've pushed my test to https://github.com/werlos/php-cs-fixer-custom-fixers/tree/infection-example in cases anyone wants to experiment. |
This comment has been minimized.
This comment has been minimized.
Thank you @maks-rafalko, works like a charm. |
Cool. Thanks @sanmai for fixing it. |
You too @kubawerlos thanks for getting light on the problem. |
phpunit.xml
https://github.com/kubawerlos/php-cs-fixer-custom-fixers/blob/main/phpunit.xmlOutput with issue
Mutator
UnwrapStrReplace
after updating from 0.24.0 to 0.25.0 started to make Infection failing with "syntax errors were encountered".See the changes in this PR: kubawerlos/php-cs-fixer-custom-fixers#595 - code
\str_replace("\n", "\n//", $codeToCommentOut);
was fine on Infection 0.24.0 and on 0.25.0 it fails (see the failing job).There are others
str_replace
calls which are mutated and are fine.Very similar case for
substr
- started to report "syntax errors were encountered" with unwrapping mutator and only for some cases.I've tried to investigate it a bit:
--show-mutations
)tests/phpunit/Mutator/Unwrap/UnwrapStrReplaceTest.php
were passingThe text was updated successfully, but these errors were encountered: