stryker-mutator / stryker-net

Mutation testing for .NET core and .NET framework!
https://stryker-mutator.io
Apache License 2.0
1.76k stars 175 forks source link

Stryker.NET could not compile the project after mutation #619

Closed tbino5981 closed 5 years ago

tbino5981 commented 5 years ago

Describe the bug Stryker fails during execution with a fatal error: Stryker.NET could not compile the project after mutation Run with dotnet-stryker -tr vstest

Logs


   _____ _              _               _   _ ______ _______                                                                                                                                                                                                          
  / ____| |            | |             | \ | |  ____|__   __|                                                                                                                                                                                                         
 | (___ | |_ _ __ _   _| | _____ _ __  |  \| | |__     | |                                                                                                                                                                                                            
  \___ \| __| '__| | | | |/ / _ \ '__| | . ` |  __|    | |                                                                                                                                                                                                            
  ____) | |_| |  | |_| |   <  __/ |    | |\  | |____   | |                                                                                                                                                                                                            
 |_____/ \__|_|   \__, |_|\_\___|_| (_)|_| \_|______|  |_|                                                                                                                                                                                                            
                   __/ |                                                                                                                                                                                                                                              
                  |___/                                                                                                                                                                                                                                               

Version: 0.12.0 (beta)                                                                                                                                                                                                                                                

[09:56:27 INF] The project D:\tmp\StrykerTest\StrykerSample\StrykerSample.csproj will be mutated                                                                                                                                                                      
[09:56:33 INF] Started initial build using dotnet build                                                                                                                                                                                                               
[09:56:35 INF] Initial build successful                                                                                                                                                                                                                               
[09:56:51 INF] Using testrunner VsTest                                                                                                                                                                                                                                
[09:56:51 INF] Initial testrun started                                                                                                                                                                                                                                
[09:56:52 INF] Total number of tests found in initial test run: 1                                                                                                                                                                                                     
[09:56:52 INF] Using 6651 ms as testrun timeout                                                                                                                                                                                                                       
[09:56:55 WRN] Stryker.NET encountered an compile error in D:\tmp\StrykerTest\StrykerSample\Utils.cs with message: Der Name "Unsafe" ist im aktuellen Kontext nicht vorhanden. (Source code: Unsafe)                                                                  
[09:56:55 WRN] Safe Mode! Stryker will try to continue by rolling back all mutations in method. This should not happen, please report this as an issue on github with the previous error message.                                                                     
[09:56:55 FTL] Stryker.NET could not compile the project after mutation. This is probably an error for Stryker.NET and not your project. Please report this issue on github with the previous error message.                                                          
[09:56:55 ERR] An error occurred during the mutation test run                                                                                                                                                                                                         
System.ApplicationException: Internal error due to compile error.                                                                                                                                                                                                     
   at Stryker.Core.Compiling.RollbackProcess.RemoveMutantIfStatements(SyntaxTree originalTree, ICollection`1 diagnosticInfo, Boolean devMode) in d:\a\1\s\src\Stryker.Core\Stryker.Core\Compiling\RollbackProcess.cs:line 190                                         
   at Stryker.Core.Compiling.RollbackProcess.Start(CSharpCompilation compiler, ImmutableArray`1 diagnostics, Boolean devMode) in d:\a\1\s\src\Stryker.Core\Stryker.Core\Compiling\RollbackProcess.cs:line 60                                                          
   at Stryker.Core.Compiling.CompilingProcess.TryCompilation(MemoryStream ms, CSharpCompilation compilation, EmitResult previousEmitResult, Boolean devMode, Int32 retryCount) in d:\a\1\s\src\Stryker.Core\Stryker.Core\Compiling\CompilingProcess.cs:line 107       
   at Stryker.Core.Compiling.CompilingProcess.Compile(IEnumerable`1 syntaxTrees, MemoryStream ms, Boolean devMode) in d:\a\1\s\src\Stryker.Core\Stryker.Core\Compiling\CompilingProcess.cs:line 75                                                                    
   at Stryker.Core.MutationTest.MutationTestProcess.Mutate(StrykerOptions options) in d:\a\1\s\src\Stryker.Core\Stryker.Core\MutationTest\MutationTestProcess.cs:line 92                                                                                              
   at Stryker.Core.StrykerRunner.RunMutationTest(StrykerOptions options) in d:\a\1\s\src\Stryker.Core\Stryker.Core\StrykerRunner.cs:line 79                                                                                                                           
[09:56:55 INF] Time Elapsed 00:00:35.2723590                                                                                                                                                                                                                          

Additional Logs are here

Expected behavior Stryker completes without error.

Desktop (please complete the following information):

Additional context Issue can be reproduced with this repository

rouke-broersma commented 5 years ago

Thank you for the report and the easy repro, much appreciated! We'll take a look asap.

dupdob commented 5 years ago

I had a look at the project, I suspect the issue comes from using custom constant/symbols which are not supported by Stryker as of now. There is no problem for predefined symbols (see here). Could you try again using only NETSTANDARD (that you don't need to define explicitly) and NETCORE? That should to the trick

tbino5981 commented 5 years ago

Indeed it did work when removing my custom symbols. Visual Studio (intellisense) did not show me NETSTANDARD as a constant so I assumed it did not exist. After a clean & rebuild everything worked as expected. Stryker testing also worked. Thanks for the quick help!