From 80871b8a3a24a85e3f8a2c562ae04a2a9149dbb7 Mon Sep 17 00:00:00 2001 From: Cyrille DUPUYDAUBY Date: Fri, 22 Nov 2024 13:16:05 +0100 Subject: [PATCH] fix: fix some unit tests --- .../Mutation Orchestration Design.md | 3 +-- .../Stryker.Core.UnitTest/AssertExtensions.cs | 18 +----------------- .../Mutants/CsharpMutantOrchestratorTests.cs | 14 ++++++++------ 3 files changed, 10 insertions(+), 25 deletions(-) diff --git a/docs/technical-reference/Mutation Orchestration Design.md b/docs/technical-reference/Mutation Orchestration Design.md index f592d931c7..839b869102 100644 --- a/docs/technical-reference/Mutation Orchestration Design.md +++ b/docs/technical-reference/Mutation Orchestration Design.md @@ -262,8 +262,7 @@ This class is used for several constructs: - `AttributeListSyntax`: Attributes must be defined at compile time. - `ParameterListSyntax`: Parameters and default values must be known at compile time. - `EnumMemberSyntax`: Enumeration value must be known at compile time -- `RecursivePatternSyntax`: Pattern syntax must be known at compile time. -- `UsingDirectiveSyntax`: using directives are fixed and critical for compilation +- `UsingDirectiveSyntax`: using directives are fixed and critical for compilation - `FieldDeclarationSyntax` (only const fields): cannot modify const fields at run time. - `LocalDeclarationStatementSyntax` (only const): cannot modify constants at run time. diff --git a/src/Stryker.Core/Stryker.Core.UnitTest/AssertExtensions.cs b/src/Stryker.Core/Stryker.Core.UnitTest/AssertExtensions.cs index f372cbb36c..fcc3d6e2c7 100644 --- a/src/Stryker.Core/Stryker.Core.UnitTest/AssertExtensions.cs +++ b/src/Stryker.Core/Stryker.Core.UnitTest/AssertExtensions.cs @@ -39,23 +39,7 @@ public static void ShouldBeSemantically(this SyntaxTree actual, SyntaxTree expec Console.WriteLine(string.Join(Environment.NewLine, diff)); } - - // find the different - var actualLines = actual.ToString().Split(Environment.NewLine); - var expectedLines = expected.ToString().Split(Environment.NewLine); - for (var i = 0; i < actualLines.Length; i++) - { - if (expectedLines.Length <= i) - { - isSame.ShouldBeTrue($"AST's are not equivalent. Line[{i + 1}]{Environment.NewLine}actual:{actualLines[i]}{Environment.NewLine}expect: nothing{Environment.NewLine}Actual(full):{Environment.NewLine}{actual}{Environment.NewLine}, expected:{Environment.NewLine}{expected}"); - continue; - } - if (actualLines[i] != expectedLines[i]) - { - isSame.ShouldBeTrue($"AST's are not equivalent. Line[{i + 1}]{Environment.NewLine}actual:{actualLines[i]}{Environment.NewLine}expect:{expectedLines[i]}{Environment.NewLine}Actual(full):{Environment.NewLine}{actual}{Environment.NewLine}, expected:{Environment.NewLine}{expected}"); - } - } - } + } private static List ScanDiff(SyntaxNode actual, SyntaxNode expected) { diff --git a/src/Stryker.Core/Stryker.Core.UnitTest/Mutants/CsharpMutantOrchestratorTests.cs b/src/Stryker.Core/Stryker.Core.UnitTest/Mutants/CsharpMutantOrchestratorTests.cs index 32e44313a8..08e1e87249 100644 --- a/src/Stryker.Core/Stryker.Core.UnitTest/Mutants/CsharpMutantOrchestratorTests.cs +++ b/src/Stryker.Core/Stryker.Core.UnitTest/Mutants/CsharpMutantOrchestratorTests.cs @@ -1,9 +1,7 @@ -using System.Collections.Generic; using System.Linq; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.VisualStudio.TestTools.UnitTesting; -using Mono.Cecil; using Shouldly; using Stryker.Abstractions; using Stryker.Abstractions.Mutators; @@ -1269,9 +1267,11 @@ public void ShouldNotAddReturnDefaultToAsyncTaskMethods() ; }"; var expected = @"public async Task TestMethod() -{if(StrykerNamespace.MutantControl.IsActive(0)){}else{ +{if(StrykerNamespace.MutantControl.IsActive(0)){} +else{ ; -}}"; +} +}"; ShouldMutateSourceInClassToExpected(source, expected); } @@ -1283,9 +1283,11 @@ public void ShouldNotAddReturnDefaultToMethodsWithReturnTypeVoid() ; }"; var expected = @"void TestMethod() -{if(StrykerNamespace.MutantControl.IsActive(0)){}else{ +{if(StrykerNamespace.MutantControl.IsActive(0)){}else +{ ; -}}"; +} +}"; ShouldMutateSourceInClassToExpected(source, expected); }