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

Detect syntax errors during mutation analysis and differentiate them from all errors #1555

Merged
merged 5 commits into from Aug 17, 2021

Conversation

maks-rafalko
Copy link
Member

@maks-rafalko maks-rafalko commented Aug 12, 2021

Implements #262

  • Release infection/abstract-testframework-adapter before merging

From the first look, I didn't want to implement it since we ensure mutated code is always valid, but in the future we will allow users to write their own Mutators and use them in addition to Infection's ones, and if users' Mutator produce invalid code - users should be aware of it, because Mutators that produce invalid syntax should be fixed and should not be used since this is a wasting of time/resources.

@maks-rafalko maks-rafalko added DX Developer Experience Feature labels Aug 12, 2021
@maks-rafalko maks-rafalko added this to the 0.25.0 milestone Aug 12, 2021
@maks-rafalko maks-rafalko linked an issue Aug 12, 2021 that may be closed by this pull request
@maks-rafalko maks-rafalko enabled auto-merge (rebase) August 12, 2021 13:52
@maks-rafalko maks-rafalko merged commit b07e053 into master Aug 17, 2021
@maks-rafalko maks-rafalko deleted the feature/syntax-error branch August 17, 2021 19:37
Copy link
Member

@theofidry theofidry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tiny nitpicks, looks good!

@@ -464,6 +464,9 @@ final class ProfileList
// Extensions
'BCMath' => Mutator\Extensions\BCMath::class,
'MBString' => Mutator\Extensions\MBString::class,

// Internal only usage
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Internal usage only

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed in #1557

*
* @implements Mutator<Node\Expr\Variable>
*/
final class SyntaxError implements Mutator
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what i understand it's for testing only right? So why registering the mutator here in source code? I guess we don't have (yet) a way to register mutators only the fly for tests only?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's for testing only, yes

as far as I know, we can't register mutators on the fly atm. If we remove SyntaxError from ProfileList.php, tests fail with "Uknown Mutator" error raised here

$knownMutatorClassNames = array_flip(ProfileList::ALL_MUTATORS);
foreach ($resolvedMutators as $mutatorClassName => $config) {
Assert::keyExists(
$knownMutatorClassNames,
$mutatorClassName,
sprintf('Unknown mutator "%s"', $mutatorClassName)


yield [
<<<TXT
'ParseError
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just in case: you can now indent the heredocs: https://wiki.php.net/rfc/flexible_heredoc_nowdoc_syntaxes

I would also recommend to use nowdocs vs heredocs when possible (i.e. quote TXT into 'TXT')

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed in #1557

'coveredCodeMsi' => 75,
'msi' => 50,
'mutationCodeCoverage' => 83.33,
'coveredCodeMsi' => 60,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, this is wrong. If Infection caused an arbitrary program to end with a syntax error, this was a killed mutant. Just like if mutation leads to a type error.

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

Successfully merging this pull request may close these issues.

Syntax errors are not accounted for, not counted
3 participants