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

Introduce --noop option to run Noop mutators that does not change the source code (AST) #1465

Merged
merged 3 commits into from Jan 14, 2021

Conversation

maks-rafalko
Copy link
Member

@maks-rafalko maks-rafalko commented Jan 7, 2021

This is needed for debugging purposes, to understand how and why Infection kills mutant even if no change is made for the given source code line.

If, using --noop options, we see killed mutants, it means that Infection environment somehow breaks the tests

Ideally, when you run

bin/infection --noop 

you should see the following picture:

Processing source code files: 407/407
.: killed, M: escaped, U: uncovered, E: fatal error, T: timed out, S: skipped

UMMMMMMMMMM                                          (11 / 11)

11 mutations were generated:
       0 mutants were killed
       1 mutants were not covered by tests
      10 covered mutants were not detected
       0 errors were encountered
       0 time outs were encountered
       0 mutants required more time than configured

Metrics:
         Mutation Score Indicator (MSI): 0%
         Mutation Code Coverage: 90%
         Covered Code MSI: 0%

so, mutants are either not covered by tests or escaped. It means tests are green for each noop mutator that just don't change the code.

If we get killed mutants using --noop option, it indicates the issues with the test suite:

  • probably tests suite can't work with random order
  • probably --threads=x makes tests suite broken (tests can't run in parallel)
  • something else

In order to further debug the issue, developer ca use --log-verbosite=all and text logger and analyze infection.log file to understand what was going wrong.

Interesting, running Infection for iself with 4 threads and --noop option uncovers issues with our tests suite as well:

bin/infection --noop --log-verbosity=all --threads=4
infection.log
60587   │ 76) /home/maksrafalko/apps/infection/src/TestFramework/PhpUnit/Config/Builder/MutationConfigBuilder.php:253    [M] Foreach_
60588   │ 
60589   │ --- Original
60590   │ +++ New
60591   │ 
60592   │ $ '/home/maksrafalko/apps/infection/vendor/phpunit/phpunit/phpunit' '--configuration' '/tmp/infection/phpunitConfiguration.aa6dcebeef88e4d0f2c093bac66eb6d1.infection.xml'
60593   │   PHPUnit 9.5.0 by Sebastian Bergmann and contributors.
60594   │   
60595   │   Runtime:       PHP 7.4.13
60596   │   Configuration: /tmp/infection/phpunitConfiguration.aa6dcebeef88e4d0f2c093bac66eb6d1.infection.xml
60597   │   Random Seed:   1610016633
60598   │   
60599   │   Testing 
60600   │   E
60601   │   
60602   │   Time: 00:00.004, Memory: 10.00 MB
60603   │   
60604   │   There was 1 error:
60605   │   
60606   │   1) Infection\Tests\TestFramework\PhpUnit\Config\Builder\MutationConfigBuilderTest::test_it_preserves_white_spaces_and_formatting
60607   │   fopen(/tmp/infection-test/FileSystemTestCase93939/interceptor.autoload.a1b2c3.infection.php): failed to open stream: No such file or directory
60608   │   
60609   │   /home/maksrafalko/apps/infection/vendor/infection/include-interceptor/src/IncludeInterceptor.php:111
60610   │   /home/maksrafalko/apps/infection/vendor/thecodingmachine/safe/generated/filesystem.php:339
60611   │   /home/maksrafalko/apps/infection/src/TestFramework/PhpUnit/Config/Builder/MutationConfigBuilder.php:91
60612   │   /home/maksrafalko/apps/infection/tests/phpunit/TestFramework/PhpUnit/Config/Builder/MutationConfigBuilderTest.php:122
60613   │   
60614   │   ERRORS!
60615   │   Tests: 1, Assertions: 0, Errors: 1.
60616   │ 
60617   │ 
60618   │ 77) /home/maksrafalko/apps/infection/src/TestFramework/PhpUnit/Config/Builder/MutationConfigBuilder.php:259    [M] MethodCallRemoval
60619   │ 
60620   │ --- Original
60621   │ +++ New
60622   │ 
60623   │ $ '/home/maksrafalko/apps/infection/vendor/phpunit/phpunit/phpunit' '--configuration' '/tmp/infection/phpunitConfiguration.651f3d9b82e0931c14af0ac02b8caf70.infection.xml'
60624   │   PHPUnit 9.5.0 by Sebastian Bergmann and contributors.
60625   │   
60626   │   Runtime:       PHP 7.4.13
60627   │   Configuration: /tmp/infection/phpunitConfiguration.651f3d9b82e0931c14af0ac02b8caf70.infection.xml
60628   │   Random Seed:   1610016633
60629   │   
60630   │   Testing 
60631   │   .......E
60632   │   
60633   │   Time: 00:00.008, Memory: 10.00 MB
60634   │   
60635   │   There was 1 error:
60636   │   
60637   │   1) Infection\Tests\TestFramework\PhpUnit\Config\Builder\MutationConfigBuilderTest::test_interceptor_is_included
60638   │   fopen(/tmp/infection-test/FileSystemTestCase68815/interceptor.autoload.a1b2c3.infection.php): failed to open stream: No such file or directory
60639   │   
60640   │   /home/maksrafalko/apps/infection/vendor/infection/include-interceptor/src/IncludeInterceptor.php:111
60641   │   /home/maksrafalko/apps/infection/vendor/thecodingmachine/safe/generated/filesystem.php:339
60642   │   /home/maksrafalko/apps/infection/src/TestFramework/PhpUnit/Config/Builder/MutationConfigBuilder.php:91
60643   │   /home/maksrafalko/apps/infection/tests/phpunit/TestFramework/PhpUnit/Config/Builder/MutationConfigBuilderTest.php:513
60644   │   
60645   │   ERRORS!
60646   │   Tests: 8, Assertions: 11, Errors: 1.

So, it looks like we have tests that can't work in parallel:

 fopen(/tmp/infection-test/FileSystemTestCase93939/interceptor.autoload.a1b2c3.infection.php): failed to open stream: No such file or directory

@maks-rafalko maks-rafalko added DX Developer Experience Feature labels Jan 7, 2021
@maks-rafalko maks-rafalko added this to the 0.21.0 milestone Jan 7, 2021
@sanmai sanmai self-requested a review January 7, 2021 13:10
@theofidry theofidry self-requested a review January 7, 2021 14:06
Copy link
Member

@sanmai sanmai left a comment

Choose a reason for hiding this comment

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

Great idea!

Below is just nitpicking.

$mutators[$mutator->getName()] = $mutator;
if ($ignored !== []) {
$mutator = new IgnoreMutator(new IgnoreConfig($ignored), $mutator);
}
Copy link
Member

Choose a reason for hiding this comment

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

It appears to me the mutator factory does slightly more than it should. There could be a thin decorator object, that would be super easy to test.

In the same light adding IgnoreMutator could a job of a similar object, yet we're already here so it might be easier to leave it as it is for time being.

Copy link
Member Author

Choose a reason for hiding this comment

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

TBH, I didn't get the idea here, or this file still looks ok for me. I left it as is for now.

…he source code (AST)

This is needed for debugging purposes, to understand how and why Infection kills mutant even if no change is made for the given source code line.

If, using `--noop` options, we see killed mutants, it means that Infection environment somehow breaks the tests
@maks-rafalko
Copy link
Member Author

maks-rafalko commented Jan 14, 2021

Great idea!

This one is from mbj, the author of ruby's Mutant lib. Agree - cool idea!

@infection/core here is an invite link to our discord channel https://discord.gg/ZUmyHTJ - there are many other channels of mutation testing libs for different languages, as well as a #general channel, where people discuss interesting things. Feel free to join!

@maks-rafalko maks-rafalko enabled auto-merge (squash) January 14, 2021 22:12
@maks-rafalko maks-rafalko merged commit d133849 into master Jan 14, 2021
@maks-rafalko maks-rafalko deleted the noop-mutations branch January 14, 2021 22:20
@maks-rafalko
Copy link
Member Author

@sanmai auto-merge worked here 👍

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.

None yet

4 participants