Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<CentralPackageTransitivePinningEnabled>true</CentralPackageTransitivePinningEnabled>
</PropertyGroup>
<ItemGroup>
<GlobalPackageReference Include="CSharpier.MSBuild" Version="1.3.0" />
<GlobalPackageReference Include="CSharpier.MSBuild" Version="1.4.0" />
<GlobalPackageReference Include="Microsoft.CodeAnalysis.BannedApiAnalyzers" Version="5.6.0" />
<GlobalPackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="10.0.403" />
<GlobalPackageReference Include="Meziantou.Analyzer" Version="3.0.322" />
Expand Down
6 changes: 2 additions & 4 deletions src/NetEvolve.FrameShift.Execution/IsolatedAssemblyRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,12 @@ string methodName
using var assemblyStream = new MemoryStream(assemblyBytes);
var assembly = context.LoadFromStream(assemblyStream);

var type =
assembly.GetType(typeFullName, throwOnError: false)
var type = assembly.GetType(typeFullName, throwOnError: false)
?? throw new TypeLoadException($"The mutant assembly does not declare a type named '{typeFullName}'.");

// Public only, deliberately: every mainstream test framework requires a public test method, so
// reaching into non-public members here would recognise a shape none of them actually run.
var method =
type.GetMethod(methodName, BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static)
var method = type.GetMethod(methodName, BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static)
?? throw new MissingMethodException(typeFullName, methodName);

var instance = method.IsStatic ? null : Activator.CreateInstance(type);
Expand Down
18 changes: 8 additions & 10 deletions src/NetEvolve.FrameShift/Analyzers/TestSurfaceAnalysis.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,13 @@ internal static ImmutableArray<IMethodSymbol> GetTestMethods(
CancellationToken cancellationToken
)
{
var perCompilation = TestMethodDiscoveryCache.GetValue(
compilation,
static _ => new ConcurrentDictionary<Type, ImmutableArray<IMethodSymbol>>()
);
var perCompilation = TestMethodDiscoveryCache.GetValue(compilation, static _ => new ConcurrentDictionary<
Type,
ImmutableArray<IMethodSymbol>
>());

return perCompilation.GetOrAdd(
probe.GetType(),
_ => TestMethodDiscovery.FindTestMethods(compilation, recognizer, cancellationToken)
return perCompilation.GetOrAdd(probe.GetType(), _ =>
TestMethodDiscovery.FindTestMethods(compilation, recognizer, cancellationToken)
);
}

Expand All @@ -169,9 +168,8 @@ CancellationToken cancellationToken
static _ => new ConcurrentDictionary<Type, ImmutableArray<IMethodSymbol>>()
);

return perCompilation.GetOrAdd(
probe.GetType(),
_ => TestSurfaceCollector.FindTestsWithoutProductionReference(compilation, recognizer, cancellationToken)
return perCompilation.GetOrAdd(probe.GetType(), _ =>
TestSurfaceCollector.FindTestsWithoutProductionReference(compilation, recognizer, cancellationToken)
);
}

Expand Down
17 changes: 8 additions & 9 deletions src/NetEvolve.FrameShift/Equivalence/EquivalenceClassifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -613,13 +613,13 @@ out var mutatedTokens
}

return ClassifyQuantifierCanonicalization(
originalPattern,
originalTokens,
mutatedPattern,
mutatedTokens,
CanonicalizeExactOne,
RegexExactOneQuantifierReason
)
originalPattern,
originalTokens,
mutatedPattern,
mutatedTokens,
CanonicalizeExactOne,
RegexExactOneQuantifierReason
)
?? ClassifyQuantifierCanonicalization(
originalPattern,
originalTokens,
Expand Down Expand Up @@ -1042,8 +1042,7 @@ CancellationToken cancellationToken
}

var scope = mutation.Original.FirstAncestorOrSelf<MemberDeclarationSyntax>();
var diagnostics =
unreachableCodeDiagnosticsCache?.GetDiagnostics(semanticModel, scope?.Span, cancellationToken)
var diagnostics = unreachableCodeDiagnosticsCache?.GetDiagnostics(semanticModel, scope?.Span, cancellationToken)
?? semanticModel.GetDiagnostics(scope?.Span, cancellationToken);
var mutationSpan = mutation.Location.SourceSpan;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,8 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
{
var provider = context.CompilationProvider.Combine(context.AnalyzerConfigOptionsProvider);

context.RegisterSourceOutput(
provider,
static (productionContext, source) => Execute(productionContext, source.Left, source.Right)
context.RegisterSourceOutput(provider, static (productionContext, source) =>
Execute(productionContext, source.Left, source.Right)
);
}

Expand Down
8 changes: 4 additions & 4 deletions src/NetEvolve.FrameShift/Mutations/WellKnownTypeCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ internal static class WellKnownTypeCache
throw new ArgumentNullException(nameof(metadataName));
}

var perCompilation = _cache.GetValue(
compilation,
static _ => new ConcurrentDictionary<string, INamedTypeSymbol?>(StringComparer.Ordinal)
);
var perCompilation = _cache.GetValue(compilation, static _ => new ConcurrentDictionary<
string,
INamedTypeSymbol?
>(StringComparer.Ordinal));

return perCompilation.GetOrAdd(metadataName, name => compilation.GetTypeByMetadataName(name));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,8 +350,7 @@ private static CSharpCompilation CreateTest(Compilation production) =>
/// <exception cref="InvalidOperationException">The MSTest probe did not recognise the compilation.</exception>
private static string CreateManifest(Compilation test)
{
var recognizer =
MSTestTestFrameworkProbe.Instance.TryCreateRecognizer(test)
var recognizer = MSTestTestFrameworkProbe.Instance.TryCreateRecognizer(test)
?? throw new InvalidOperationException(
"The MSTest probe did not recognise a compilation built against the real MSTest assemblies."
);
Expand All @@ -360,9 +359,8 @@ private static string CreateManifest(Compilation test)
}

private static MethodDeclarationSyntax FindMethod(Compilation compilation, string name) =>
SyntaxNodeLocator.FindFirst<MethodDeclarationSyntax>(
compilation.SyntaxTrees.First(),
method => string.Equals(method.Identifier.ValueText, name, StringComparison.Ordinal)
SyntaxNodeLocator.FindFirst<MethodDeclarationSyntax>(compilation.SyntaxTrees.First(), method =>
string.Equals(method.Identifier.ValueText, name, StringComparison.Ordinal)
);

private static Task<ImmutableArray<Diagnostic>> RunAsync(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -444,9 +444,8 @@ private static string CreateManifest(Compilation test)
}

private static MethodDeclarationSyntax FindMethod(Compilation compilation, string name) =>
SyntaxNodeLocator.FindFirst<MethodDeclarationSyntax>(
compilation.SyntaxTrees.First(),
method => string.Equals(method.Identifier.ValueText, name, StringComparison.Ordinal)
SyntaxNodeLocator.FindFirst<MethodDeclarationSyntax>(compilation.SyntaxTrees.First(), method =>
string.Equals(method.Identifier.ValueText, name, StringComparison.Ordinal)
);

private static Task<ImmutableArray<Diagnostic>> RunAsync(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -895,9 +895,8 @@ private static string CreateManifest(Compilation test)
}

private static MethodDeclarationSyntax FindMethod(Compilation compilation, string name) =>
SyntaxNodeLocator.FindFirst<MethodDeclarationSyntax>(
compilation.SyntaxTrees.First(),
method => string.Equals(method.Identifier.ValueText, name, StringComparison.Ordinal)
SyntaxNodeLocator.FindFirst<MethodDeclarationSyntax>(compilation.SyntaxTrees.First(), method =>
string.Equals(method.Identifier.ValueText, name, StringComparison.Ordinal)
);

private static Task<ImmutableArray<Diagnostic>> RunAsync(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1116,8 +1116,7 @@ private static CSharpCompilation CreateTest(string productionSource, string test
/// </remarks>
private static string CreateManifest(Compilation test, ITestFrameworkProbe probe)
{
var recognizer =
probe.TryCreateRecognizer(test)
var recognizer = probe.TryCreateRecognizer(test)
?? throw new InvalidOperationException(
$"The probe of '{probe.FrameworkName}' did not recognise the marker fixture."
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -480,9 +480,8 @@ private static string CreateManifest(Compilation test)
}

private static MethodDeclarationSyntax FindMethod(Compilation compilation, string name) =>
SyntaxNodeLocator.FindFirst<MethodDeclarationSyntax>(
compilation.SyntaxTrees.First(),
method => string.Equals(method.Identifier.ValueText, name, StringComparison.Ordinal)
SyntaxNodeLocator.FindFirst<MethodDeclarationSyntax>(compilation.SyntaxTrees.First(), method =>
string.Equals(method.Identifier.ValueText, name, StringComparison.Ordinal)
);

private static Task<ImmutableArray<Diagnostic>> RunAsync(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -473,9 +473,8 @@ private static string CreateManifest(Compilation test)
}

private static MethodDeclarationSyntax FindMethod(Compilation compilation, string name) =>
SyntaxNodeLocator.FindFirst<MethodDeclarationSyntax>(
compilation.SyntaxTrees.First(),
method => string.Equals(method.Identifier.ValueText, name, StringComparison.Ordinal)
SyntaxNodeLocator.FindFirst<MethodDeclarationSyntax>(compilation.SyntaxTrees.First(), method =>
string.Equals(method.Identifier.ValueText, name, StringComparison.Ordinal)
);

private static Task<ImmutableArray<Diagnostic>> RunAsync(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,10 @@ ImmutableArray<IMethodSymbol> testMethods
);
#pragma warning restore CS0618

var method =
typeof(TestSurfaceAnalysis).GetMethod("FindAwakeFrameworks", BindingFlags.NonPublic | BindingFlags.Static)
?? throw new InvalidOperationException("TestSurfaceAnalysis.FindAwakeFrameworks was not found.");
var method = typeof(TestSurfaceAnalysis).GetMethod(
"FindAwakeFrameworks",
BindingFlags.NonPublic | BindingFlags.Static
) ?? throw new InvalidOperationException("TestSurfaceAnalysis.FindAwakeFrameworks was not found.");

var result = method.Invoke(null, [context, probe, recognizer, testMethods, FrameShiftOptions.Default]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,16 +271,13 @@ public async Task Verify_ConcurrentlyForDistinctMutations_ReturnsViableForEveryO
var mutations = CreateOperatorSwapMutations(tree);
var results = new ConcurrentBag<MutantViability>();

_ = Parallel.ForEach(
Enumerable.Range(0, 32),
_ =>
_ = Parallel.ForEach(Enumerable.Range(0, 32), _ =>
{
foreach (var mutation in mutations)
{
foreach (var mutation in mutations)
{
results.Add(compiler.Verify(mutation, tree, CancellationToken.None));
}
results.Add(compiler.Verify(mutation, tree, CancellationToken.None));
}
);
});

using (Assert.Multiple())
{
Expand All @@ -300,14 +297,11 @@ public async Task Verify_ConcurrentlyForTheSameMutations_ReturnsConsistentVerdic
var broken = CreateBrokenMutation(tree);
var results = new ConcurrentBag<(string OperatorId, MutantViability Viability)>();

_ = Parallel.ForEach(
Enumerable.Range(0, 32),
_ =>
{
results.Add((ViableOperatorId, compiler.Verify(viable, tree, CancellationToken.None)));
results.Add((BrokenOperatorId, compiler.Verify(broken, tree, CancellationToken.None)));
}
);
_ = Parallel.ForEach(Enumerable.Range(0, 32), _ =>
{
results.Add((ViableOperatorId, compiler.Verify(viable, tree, CancellationToken.None)));
results.Add((BrokenOperatorId, compiler.Verify(broken, tree, CancellationToken.None)));
});

using (Assert.Multiple())
{
Expand Down Expand Up @@ -789,9 +783,8 @@ private static Mutation CreateUnparsableMutation(SyntaxTree tree)
/// <returns>The mutation.</returns>
private static Mutation CreateBrokenMutation(SyntaxTree tree, string operatorId)
{
var original = SyntaxNodeLocator.FindFirst<LiteralExpressionSyntax>(
tree,
node => string.Equals(node.Token.ValueText, "7", StringComparison.Ordinal)
var original = SyntaxNodeLocator.FindFirst<LiteralExpressionSyntax>(tree, node =>
string.Equals(node.Token.ValueText, "7", StringComparison.Ordinal)
);
var replacement = SyntaxFactory.LiteralExpression(
SyntaxKind.StringLiteralExpression,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1017,8 +1017,7 @@ public async Task Mapper_SyntaxKindIsNoCompoundAssignment_ThrowsArgumentOutOfRan
public async Task HasCounterpart_OperandCountDiffers_ReturnsFalse()
{
var (compilation, _, _) = CompilationFactory.CreateWithModel(UnaryAndBinaryMinusSource);
var money =
compilation.GetTypeByMetadataName("Fixtures.Money")
var money = compilation.GetTypeByMetadataName("Fixtures.Money")
?? throw new InvalidOperationException("The fixture does not declare 'Fixtures.Money'.");
var unaryMinus = money.GetMembers("op_UnaryNegation").OfType<IMethodSymbol>().Single();
var binaryMinus = money.GetMembers("op_Subtraction").OfType<IMethodSymbol>().Single();
Expand Down Expand Up @@ -1124,9 +1123,10 @@ private static ImmutableArray<string> AllCounterparts(string originalName) =>
/// </exception>
private static ArgumentOutOfRangeException InvokeMapper(string mapperName, SyntaxKind expressionKind)
{
var mapper =
typeof(ArithmeticAssignmentMutator).GetMethod(mapperName, BindingFlags.NonPublic | BindingFlags.Static)
?? throw new InvalidOperationException($"The mapping method '{mapperName}' no longer exists.");
var mapper = typeof(ArithmeticAssignmentMutator).GetMethod(
mapperName,
BindingFlags.NonPublic | BindingFlags.Static
) ?? throw new InvalidOperationException($"The mapping method '{mapperName}' no longer exists.");

try
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -882,8 +882,7 @@ public async Task Mapper_SyntaxKindIsNotArithmetic_ThrowsArgumentOutOfRangeExcep
public async Task HasCounterpart_OperandCountDiffers_ReturnsFalse()
{
var (compilation, _, _) = CompilationFactory.CreateWithModel(UnaryAndBinaryMinusSource);
var money =
compilation.GetTypeByMetadataName("Fixtures.Money")
var money = compilation.GetTypeByMetadataName("Fixtures.Money")
?? throw new InvalidOperationException("The fixture does not declare 'Fixtures.Money'.");
var unaryMinus = money.GetMembers("op_UnaryNegation").OfType<IMethodSymbol>().Single();
var binaryMinus = money.GetMembers("op_Subtraction").OfType<IMethodSymbol>().Single();
Expand Down Expand Up @@ -978,9 +977,10 @@ private static ImmutableArray<string> AllCounterparts(string originalName) =>
/// </exception>
private static ArgumentOutOfRangeException InvokeMapper(string mapperName, SyntaxKind expressionKind)
{
var mapper =
typeof(ArithmeticOperatorMutator).GetMethod(mapperName, BindingFlags.NonPublic | BindingFlags.Static)
?? throw new InvalidOperationException($"The mapping method '{mapperName}' no longer exists.");
var mapper = typeof(ArithmeticOperatorMutator).GetMethod(
mapperName,
BindingFlags.NonPublic | BindingFlags.Static
) ?? throw new InvalidOperationException($"The mapping method '{mapperName}' no longer exists.");

try
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,15 +288,12 @@ private static (SyntaxTree Tree, Mutation[] Mutations) Run(string source, Func<S
private static string Rewrite(SyntaxTree tree, Mutation mutation) => mutation.ApplyTo(tree).ToString();

private static SyntaxNode FindBooleanLiteral(SyntaxTree tree) =>
SyntaxNodeLocator.FindFirst<LiteralExpressionSyntax>(
tree,
static literal =>
literal.IsKind(SyntaxKind.TrueLiteralExpression) || literal.IsKind(SyntaxKind.FalseLiteralExpression)
SyntaxNodeLocator.FindFirst<LiteralExpressionSyntax>(tree, static literal =>
literal.IsKind(SyntaxKind.TrueLiteralExpression) || literal.IsKind(SyntaxKind.FalseLiteralExpression)
);

private static SyntaxNode FindNumericLiteral(SyntaxTree tree) =>
SyntaxNodeLocator.FindFirst<LiteralExpressionSyntax>(
tree,
static literal => literal.IsKind(SyntaxKind.NumericLiteralExpression)
SyntaxNodeLocator.FindFirst<LiteralExpressionSyntax>(tree, static literal =>
literal.IsKind(SyntaxKind.NumericLiteralExpression)
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -807,11 +807,9 @@ private static Mutation Pick(ImmutableArray<Mutation> mutations, string source,
}

private static InvocationExpressionSyntax FindCall(SyntaxTree tree, string methodName) =>
SyntaxNodeLocator.FindFirst<InvocationExpressionSyntax>(
tree,
invocation =>
invocation.Expression is MemberAccessExpressionSyntax access
&& string.Equals(access.Name.Identifier.ValueText, methodName, StringComparison.Ordinal)
SyntaxNodeLocator.FindFirst<InvocationExpressionSyntax>(tree, invocation =>
invocation.Expression is MemberAccessExpressionSyntax access
&& string.Equals(access.Name.Identifier.ValueText, methodName, StringComparison.Ordinal)
);

private static string[] DisplayNames(ImmutableArray<Mutation> mutations) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -443,9 +443,8 @@ public async Task CreateMutations_UnsupportedSyntaxKind_ReturnsEmpty()
{
var (_, semanticModel, tree) = CompilationFactory.CreateWithModel(ArrayInitializerSource);
var mutator = new CollectionInitializerMutator();
var literal = SyntaxNodeLocator.FindFirst<LiteralExpressionSyntax>(
tree,
static candidate => candidate.IsKind(SyntaxKind.NumericLiteralExpression)
var literal = SyntaxNodeLocator.FindFirst<LiteralExpressionSyntax>(tree, static candidate =>
candidate.IsKind(SyntaxKind.NumericLiteralExpression)
);

Mutation[] mutations = [.. mutator.CreateMutations(literal, semanticModel, CancellationToken.None)];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -857,8 +857,7 @@ private static SyntaxNode FindConditional(SyntaxTree tree) =>
SyntaxNodeLocator.FindFirst<ConditionalExpressionSyntax>(tree);

private static SyntaxNode FindNumericLiteral(SyntaxTree tree) =>
SyntaxNodeLocator.FindFirst<LiteralExpressionSyntax>(
tree,
static literal => literal.IsKind(SyntaxKind.NumericLiteralExpression)
SyntaxNodeLocator.FindFirst<LiteralExpressionSyntax>(tree, static literal =>
literal.IsKind(SyntaxKind.NumericLiteralExpression)
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -761,9 +761,8 @@ private static string Ids(IEnumerable<Mutation> mutations) =>
string.Join(", ", mutations.Select(mutation => mutation.OperatorId));

private static SyntaxNode FindCultureAccess(SyntaxTree tree) =>
SyntaxNodeLocator.FindFirst<MemberAccessExpressionSyntax>(
tree,
static access => IsCultureMemberName(access.Name.Identifier.ValueText)
SyntaxNodeLocator.FindFirst<MemberAccessExpressionSyntax>(tree, static access =>
IsCultureMemberName(access.Name.Identifier.ValueText)
);

private static bool IsCultureMemberName(string name) =>
Expand Down
Loading
Loading