System.InvalidOperationException: Expected a block containing a conditional expression
See original GitHub issueDescribe the bug Stryker fails
Logs See attached
Expected behavior Stryker succeeds
Desktop (please complete the following information):
- OS: Windows
- Type of project: Full Framework
- Framework Version: net48
- Stryker Version: 0.22.2
Here is the original method: private List<string> ExtractXmlMessages(string message, out string partialMessage) { List<string> xmlMessages = new List<string>();
// While we think we have a valid message
while (true)
{
// Remove any junk starting characters which will prevent
// the ExtractXmlMessage method from working.
if (StringHelper.Contains(message, XmlStartSymbol) && !StringHelper.StartsWith(message, XmlStartSymbol))
{
int numberOfJunkChars = message.IndexOf(XmlStartSymbol, StringComparison.OrdinalIgnoreCase);
message = message.Remove(0, numberOfJunkChars);
}
string completeMessage = ExtractXmlMessage(message, out partialMessage);
completeMessage = completeMessage.Trim();
if (String.IsNullOrEmpty(completeMessage))
{
break;
}
xmlMessages.Add(completeMessage);
message = partialMessage;
}
return xmlMessages;
}
Here is the log output: [12:17:38 DBG] Remove a mutation helper. [12:17:38 ERR] An error occurred during the mutation test run System.InvalidOperationException: Expected a block containing a conditional expression, found:
/// <summary>
/// Extracts all complete xml strings from the given message string.
/// </summary>
/// <param name="message"></param>
/// <param name="partialMessage"></param>
/// <returns></returns>
private List<string> ExtractXmlMessages(string message, out string partialMessage)
{
List<string> xmlMessages = new List<string>();
// While we think we have a valid message
while ((Stryker7YxyYnQrRbPl8fG.MutantControl.IsActive(776)?!(true):(Stryker7YxyYnQrRbPl8fG.MutantControl.IsActive(775)?false:true)))
{
// Remove any junk starting characters which will prevent
// the ExtractXmlMessage method from working.
if ((Stryker7YxyYnQrRbPl8fG.MutantControl.IsActive(778)?!(StringHelper.Contains(message, XmlStartSymbol) && !StringHelper.StartsWith(message, XmlStartSymbol)):(Stryker7YxyYnQrRbPl8fG.MutantControl.IsActive(777)?StringHelper.Contains(message, XmlStartSymbol) || !StringHelper.StartsWith(message, XmlStartSymbol):StringHelper.Contains(message, XmlStartSymbol) && (Stryker7YxyYnQrRbPl8fG.MutantControl.IsActive(779)?StringHelper.StartsWith(message, XmlStartSymbol):!StringHelper.StartsWith(message, XmlStartSymbol)))))
{
int numberOfJunkChars = message.IndexOf(XmlStartSymbol, StringComparison.OrdinalIgnoreCase);
message = message.Remove(0, numberOfJunkChars);
}
string completeMessage = ExtractXmlMessage(message, out partialMessage);
completeMessage = completeMessage.Trim();
if ((Stryker7YxyYnQrRbPl8fG.MutantControl.IsActive(780)?!(String.IsNullOrEmpty(completeMessage)):String.IsNullOrEmpty(completeMessage)))
{
break;
}
xmlMessages.Add(completeMessage);
message = partialMessage;
}
return xmlMessages;
}
.
at Stryker.Core.Instrumentation.BaseEngine1.RemoveInstrumentation(SyntaxNode node) in D:\a\1\s\src\Stryker.Core\Stryker.Core\Instrumentation\BaseEngine.cs:line 26 at Stryker.Core.Mutants.MutantPlacer.RemoveMutant(SyntaxNode nodeToRemove) in D:\a\1\s\src\Stryker.Core\Stryker.Core\Mutants\MutantPlacer.cs:line 106 at Stryker.Core.Compiling.RollbackProcess.RemoveMutantIfStatements(SyntaxTree originalTree, IEnumerable
1 diagnosticInfo, Boolean devMode) in D:\a\1\s\src\Stryker.Core\Stryker.Core\Compiling\RollbackProcess.cs:line 227
at Stryker.Core.Compiling.RollbackProcess.Start(CSharpCompilation compiler, ImmutableArray1 diagnostics, Boolean lastAttempt, Boolean devMode) in D:\a\1\s\src\Stryker.Core\Stryker.Core\Compiling\RollbackProcess.cs:line 59 at Stryker.Core.Compiling.CompilingProcess.TryCompilation(Stream ms, Stream symbolStream, CSharpCompilation compilation, EmitResult previousEmitResult, Boolean lastAttempt, Boolean devMode, Int32 retryCount) in D:\a\1\s\src\Stryker.Core\Stryker.Core\Compiling\CompilingProcess.cs:line 110 at Stryker.Core.Compiling.CompilingProcess.Compile(IEnumerable
1 syntaxTrees, Stream ilStream, Stream symbolStream, Boolean devMode) in D:\a\1\s\src\Stryker.Core\Stryker.Core\Compiling\CompilingProcess.cs:line 76
at Stryker.Core.MutationTest.CsharpMutationProcess.CompileMutations() in D:\a\1\s\src\Stryker.Core\Stryker.Core\MutationTest\CsharpMutationProcess.cs:line 76
at Stryker.Core.MutationTest.CsharpMutationProcess.Mutate() in D:\a\1\s\src\Stryker.Core\Stryker.Core\MutationTest\CsharpMutationProcess.cs:line 68
at Stryker.Core.MutationTest.MutationTestProcess.Mutate() in D:\a\1\s\src\Stryker.Core\Stryker.Core\MutationTest\MutationTestProcess.cs:line 75
at Stryker.Core.Initialisation.ProjectMutator.MutateProject(IStrykerOptions options, IReporter reporters) in D:\a\1\s\src\Stryker.Core\Stryker.Core\Initialisation\ProjectMutator.cs:line 41
at Stryker.Core.Initialisation.ProjectOrchestrator.MutateProjects(StrykerOptions options, IReporter reporters)+MoveNext() in D:\a\1\s\src\Stryker.Core\Stryker.Core\Initialisation\ProjectOrchestrator.cs:line 61
at System.Collections.Generic.List1..ctor(IEnumerable
1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable1 source) at Stryker.Core.StrykerRunner.RunMutationTest(StrykerOptions options, IEnumerable
1 initialLogMessages) in D:\a\1\s\src\Stryker.Core\Stryker.Core\StrykerRunner.cs:line 59
[12:17:38 INF] Time Elapsed 00:00:35.2667064
Unhandled exception. System.InvalidOperationException: Expected a block containing a conditional expression, found:
/// <summary>
/// Extracts all complete xml strings from the given message string.
/// </summary>
/// <param name="message"></param>
/// <param name="partialMessage"></param>
/// <returns></returns>
private List<string> ExtractXmlMessages(string message, out string partialMessage)
{
List<string> xmlMessages = new List<string>();
// While we think we have a valid message
while ((Stryker7YxyYnQrRbPl8fG.MutantControl.IsActive(776)?!(true):(Stryker7YxyYnQrRbPl8fG.MutantControl.IsActive(775)?false:true)))
{
// Remove any junk starting characters which will prevent
// the ExtractXmlMessage method from working.
if ((Stryker7YxyYnQrRbPl8fG.MutantControl.IsActive(778)?!(StringHelper.Contains(message, XmlStartSymbol) && !StringHelper.StartsWith(message, XmlStartSymbol)):(Stryker7YxyYnQrRbPl8fG.MutantControl.IsActive(777)?StringHelper.Contains(message, XmlStartSymbol) || !StringHelper.StartsWith(message, XmlStartSymbol):StringHelper.Contains(message, XmlStartSymbol) && (Stryker7YxyYnQrRbPl8fG.MutantControl.IsActive(779)?StringHelper.StartsWith(message, XmlStartSymbol):!StringHelper.StartsWith(message, XmlStartSymbol)))))
{
int numberOfJunkChars = message.IndexOf(XmlStartSymbol, StringComparison.OrdinalIgnoreCase);
message = message.Remove(0, numberOfJunkChars);
}
string completeMessage = ExtractXmlMessage(message, out partialMessage);
completeMessage = completeMessage.Trim();
if ((Stryker7YxyYnQrRbPl8fG.MutantControl.IsActive(780)?!(String.IsNullOrEmpty(completeMessage)):String.IsNullOrEmpty(completeMessage)))
{
break;
}
xmlMessages.Add(completeMessage);
message = partialMessage;
}
return xmlMessages;
}
.
at Stryker.Core.Instrumentation.BaseEngine1.RemoveInstrumentation(SyntaxNode node) in D:\a\1\s\src\Stryker.Core\Stryker.Core\Instrumentation\BaseEngine.cs:line 26 at Stryker.Core.Mutants.MutantPlacer.RemoveMutant(SyntaxNode nodeToRemove) in D:\a\1\s\src\Stryker.Core\Stryker.Core\Mutants\MutantPlacer.cs:line 106 at Stryker.Core.Compiling.RollbackProcess.RemoveMutantIfStatements(SyntaxTree originalTree, IEnumerable
1 diagnosticInfo, Boolean devMode) in D:\a\1\s\src\Stryker.Core\Stryker.Core\Compiling\RollbackProcess.cs:line 227
at Stryker.Core.Compiling.RollbackProcess.Start(CSharpCompilation compiler, ImmutableArray1 diagnostics, Boolean lastAttempt, Boolean devMode) in D:\a\1\s\src\Stryker.Core\Stryker.Core\Compiling\RollbackProcess.cs:line 59 at Stryker.Core.Compiling.CompilingProcess.TryCompilation(Stream ms, Stream symbolStream, CSharpCompilation compilation, EmitResult previousEmitResult, Boolean lastAttempt, Boolean devMode, Int32 retryCount) in D:\a\1\s\src\Stryker.Core\Stryker.Core\Compiling\CompilingProcess.cs:line 110 at Stryker.Core.Compiling.CompilingProcess.Compile(IEnumerable
1 syntaxTrees, Stream ilStream, Stream symbolStream, Boolean devMode) in D:\a\1\s\src\Stryker.Core\Stryker.Core\Compiling\CompilingProcess.cs:line 76
at Stryker.Core.MutationTest.CsharpMutationProcess.CompileMutations() in D:\a\1\s\src\Stryker.Core\Stryker.Core\MutationTest\CsharpMutationProcess.cs:line 76
at Stryker.Core.MutationTest.CsharpMutationProcess.Mutate() in D:\a\1\s\src\Stryker.Core\Stryker.Core\MutationTest\CsharpMutationProcess.cs:line 68
at Stryker.Core.MutationTest.MutationTestProcess.Mutate() in D:\a\1\s\src\Stryker.Core\Stryker.Core\MutationTest\MutationTestProcess.cs:line 75
at Stryker.Core.Initialisation.ProjectMutator.MutateProject(IStrykerOptions options, IReporter reporters) in D:\a\1\s\src\Stryker.Core\Stryker.Core\Initialisation\ProjectMutator.cs:line 41
at Stryker.Core.Initialisation.ProjectOrchestrator.MutateProjects(StrykerOptions options, IReporter reporters)+MoveNext() in D:\a\1\s\src\Stryker.Core\Stryker.Core\Initialisation\ProjectOrchestrator.cs:line 61
at System.Collections.Generic.List1..ctor(IEnumerable
1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable1 source) at Stryker.Core.StrykerRunner.RunMutationTest(StrykerOptions options, IEnumerable
1 initialLogMessages) in D:\a\1\s\src\Stryker.Core\Stryker.Core\StrykerRunner.cs:line 59
at Stryker.CLI.StrykerCLI.RunStryker(StrykerOptions options) in D:\a\1\s\src\Stryker.CLI\Stryker.CLI\StrykerCLI.cs:line 136
at Stryker.CLI.StrykerCLI.<>c__DisplayClass7_0.<Run>b__0() in D:\a\1\s\src\Stryker.CLI\Stryker.CLI\StrykerCLI.cs:line 125
at McMaster.Extensions.CommandLineUtils.CommandLineApplication.<>c__DisplayClass146_0.<OnExecute>b__0(CancellationToken _)
at McMaster.Extensions.CommandLineUtils.CommandLineApplication.ExecuteAsync(String[] args, CancellationToken cancellationToken)
at McMaster.Extensions.CommandLineUtils.CommandLineApplication.Execute(String[] args)
at Stryker.CLI.StrykerCLI.Run(String[] args) in D:\a\1\s\src\Stryker.CLI\Stryker.CLI\StrykerCLI.cs:line 128
at Stryker.CLI.Program.Main(String[] args) in D:\a\1\s\src\Stryker.CLI\Stryker.CLI\Program.cs:line 16
strykerlogs.txt
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (5 by maintainers)
Update report: 0) fix is implemented and looking good in terms of design
The compilation error that triggered a swipe removal of mutations is
The out parameter 'partialMessage' must be assigned to before control leaves the current method
. Typically, Stryker injects helper to prevent that kind of errors. I will look into this.Update on my first analysis: it was only partially right. What I got right: the annotation signaling a helper were not removed. I have a fix for that, but I want first to try and improve unit testing to prevent regresion. What I got wrong: this was not linked to new compilation attempts (no trace in log of this); so this is more likely there were several errors signaled for this method, resulting in multiple scan for removal. Then, issue #1512 was clearly linked to attempting to remove
return default(xxx)
a second time; this issue is less clear, but I guess this is linked to an attempt to remove an ‘out variable assignment’ helper a second time.I already have a version that properly removes the helpers and the associated markers to prevent this kind of crash, but:
I’ll keep working on this and update on progress.