diff options
author | Jackson Schuster <jschuster@microsoft.com> | 2021-12-10 18:27:35 +0300 |
---|---|---|
committer | Jackson Schuster <jschuster@microsoft.com> | 2021-12-10 20:03:11 +0300 |
commit | 359a51bd6ab157d6890aa18fb2fa76e7a2ac0a05 (patch) | |
tree | c6ece3a6c85a191842307f6ff96187d18aa8f463 | |
parent | fd8aa603ec738bbf953167543430bc017986530a (diff) |
Restore unnecessary changes and format
Remove .gitignore changes
Fix formatting with dotnet-format
49 files changed, 593 insertions, 213 deletions
diff --git a/.gitignore b/.gitignore index 0bbf8367c..414ad0275 100644 --- a/.gitignore +++ b/.gitignore @@ -10,7 +10,6 @@ *.user *.userprefs .vs/ -.vscode/ .idea/ packages/ @@ -36,7 +35,5 @@ bin/ .packages artifacts *.binlog -# Emacs / vim backup files -*~ test/Mono.Linker.Tests/TestResults.xml diff --git a/src/ILLink.RoslynAnalyzer/RequiresAnalyzerBase.cs b/src/ILLink.RoslynAnalyzer/RequiresAnalyzerBase.cs index 312e9bcdc..b9032ee22 100644 --- a/src/ILLink.RoslynAnalyzer/RequiresAnalyzerBase.cs +++ b/src/ILLink.RoslynAnalyzer/RequiresAnalyzerBase.cs @@ -220,7 +220,7 @@ namespace ILLink.RoslynAnalyzer ISymbol containingSymbol = FindContainingSymbol (operationContext, AnalyzerDiagnosticTargets); // Do not emit any diagnostic if caller is annotated with the attribute too. - if (containingSymbol.IsInRequiresScope(RequiresAttributeName)) + if (containingSymbol.IsInRequiresScope (RequiresAttributeName)) return; if (ReportSpecialIncompatibleMembersDiagnostic (operationContext, incompatibleMembers, member)) diff --git a/src/ILLink.RoslynAnalyzer/RequiresISymbolExtensions.cs b/src/ILLink.RoslynAnalyzer/RequiresISymbolExtensions.cs index f4ae7a3e7..24f8a0623 100644 --- a/src/ILLink.RoslynAnalyzer/RequiresISymbolExtensions.cs +++ b/src/ILLink.RoslynAnalyzer/RequiresISymbolExtensions.cs @@ -1,13 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; -using System.Text; using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.CSharp.Syntax; namespace ILLink.RoslynAnalyzer { @@ -29,12 +23,12 @@ namespace ILLink.RoslynAnalyzer /// <param name="containingSymbol"> /// Symbol that is either an overriding member or an overriden/virtual member /// </param> - public static bool IsOverrideInRequiresScope(this ISymbol member, string requiresAttribute) + public static bool IsOverrideInRequiresScope (this ISymbol member, string requiresAttribute) { - return member.IsInRequiresScope(requiresAttribute, false); + return member.IsInRequiresScope (requiresAttribute, false); } - private static bool IsInRequiresScope (this ISymbol member, string requiresAttribute, bool checkAssociatedSymbol) + private static bool IsInRequiresScope (this ISymbol member, string requiresAttribute, bool checkAssociatedSymbol) { if (member is ISymbol containingSymbol) { if (containingSymbol.HasAttribute (requiresAttribute) diff --git a/src/ILLink.Shared/DiagnosticString.cs b/src/ILLink.Shared/DiagnosticString.cs index e01cc9b5b..3464ef0a2 100644 --- a/src/ILLink.Shared/DiagnosticString.cs +++ b/src/ILLink.Shared/DiagnosticString.cs @@ -1,6 +1,4 @@ -using System; - -namespace ILLink.Shared +namespace ILLink.Shared { public readonly struct DiagnosticString { diff --git a/src/analyzer/ConsoleDependencyGraph.cs b/src/analyzer/ConsoleDependencyGraph.cs index fb2e845ee..50a688208 100644 --- a/src/analyzer/ConsoleDependencyGraph.cs +++ b/src/analyzer/ConsoleDependencyGraph.cs @@ -96,7 +96,7 @@ namespace LinkerAnalyzer int pi = 0, childIdx; do { - childIdx = childVertex.parentIndexes [pi]; + childIdx = childVertex.parentIndexes[pi]; pi++; } while (visited.Contains (childIdx) && pi < childVertex.parentIndexes.Count); @@ -148,13 +148,13 @@ namespace LinkerAnalyzer Header ("Statistics"); if (verbose) { foreach (var key in counts.Keys) - Console.WriteLine ("Vertex type:\t{0}{1}count:{2}", key, Tabs (key), counts [key]); + Console.WriteLine ("Vertex type:\t{0}{1}count:{2}", key, Tabs (key), counts[key]); } else { - Console.WriteLine ("Assemblies:\t{0}", counts ["Assembly"]); - Console.WriteLine ("Modules:\t{0}", counts ["Module"]); - Console.WriteLine ("Types:\t\t{0}", counts ["TypeDef"]); - Console.WriteLine ("Fields:\t\t{0}", counts ["Field"]); - Console.WriteLine ("Methods:\t{0}", counts ["Method"]); + Console.WriteLine ("Assemblies:\t{0}", counts["Assembly"]); + Console.WriteLine ("Modules:\t{0}", counts["Module"]); + Console.WriteLine ("Types:\t\t{0}", counts["TypeDef"]); + Console.WriteLine ("Fields:\t\t{0}", counts["Field"]); + Console.WriteLine ("Methods:\t{0}", counts["Method"]); } Console.WriteLine (); diff --git a/src/analyzer/LinkerAnalyzerCore/DependencyGraph.cs b/src/analyzer/LinkerAnalyzerCore/DependencyGraph.cs index 183c969da..e4346928b 100644 --- a/src/analyzer/LinkerAnalyzerCore/DependencyGraph.cs +++ b/src/analyzer/LinkerAnalyzerCore/DependencyGraph.cs @@ -14,7 +14,8 @@ using System.Xml; namespace LinkerAnalyzer.Core { - public class VertexData { + public class VertexData + { public string value; public List<int> parentIndexes; public int index; @@ -51,7 +52,8 @@ namespace LinkerAnalyzer.Core } } - void Load (GZipStream zipStream) { + void Load (GZipStream zipStream) + { using (XmlReader reader = XmlReader.Create (zipStream)) { while (reader.Read ()) { switch (reader.NodeType) { @@ -88,7 +90,7 @@ namespace LinkerAnalyzer.Core VertexData vertex; try { - vertex = vertices [indexes [vertexName]]; + vertex = vertices[indexes[vertexName]]; } catch (KeyNotFoundException) { if (create) { int index = vertices.Count; @@ -97,9 +99,9 @@ namespace LinkerAnalyzer.Core indexes.Add (vertexName, index); string prefix = vertexName.Substring (0, vertexName.IndexOf (':')); if (counts.ContainsKey (prefix)) - counts [prefix]++; + counts[prefix]++; else - counts [prefix] = 1; + counts[prefix] = 1; //Console.WriteLine ("prefix " + prefix + " count " + counts[prefix]); if (prefix == "TypeDef") { Types.Add (vertex); @@ -113,7 +115,7 @@ namespace LinkerAnalyzer.Core public VertexData Vertex (int index) { - return vertices [index]; + return vertices[index]; } IEnumerable<Tuple<VertexData, int>> AddDependencies (VertexData vertex, HashSet<int> reachedVertices, int depth) diff --git a/src/analyzer/LinkerAnalyzerCore/SpaceAnalyzer.cs b/src/analyzer/LinkerAnalyzerCore/SpaceAnalyzer.cs index 91ee74842..74b4ab928 100644 --- a/src/analyzer/LinkerAnalyzerCore/SpaceAnalyzer.cs +++ b/src/analyzer/LinkerAnalyzerCore/SpaceAnalyzer.cs @@ -75,7 +75,7 @@ namespace LinkerAnalyzer.Core var key = GetKey (method); if (sizes.ContainsKey (key)) - return sizes [key]; + return sizes[key]; var msize = method.Body.CodeSize; msize += method.Name.Length; @@ -125,7 +125,7 @@ namespace LinkerAnalyzer.Core else Console.Write ("."); - ReaderParameters parameters = new ReaderParameters () { ReadingMode = ReadingMode.Immediate, AssemblyResolver = resolver}; + ReaderParameters parameters = new ReaderParameters () { ReadingMode = ReadingMode.Immediate, AssemblyResolver = resolver }; var assembly = AssemblyDefinition.ReadAssembly (file, parameters); assemblies.Add (assembly); foreach (var module in assembly.Modules) { @@ -146,7 +146,7 @@ namespace LinkerAnalyzer.Core public int GetSize (VertexData vertex) { if (sizes.ContainsKey (vertex.value)) - return sizes [vertex.value]; + return sizes[vertex.value]; return 0; } } diff --git a/src/analyzer/Main.cs b/src/analyzer/Main.cs index 9e9b31cac..2f70441bc 100644 --- a/src/analyzer/Main.cs +++ b/src/analyzer/Main.cs @@ -7,8 +7,8 @@ // Copyright 2015 Xamarin Inc (http://www.xamarin.com). // using System; -using Mono.Options; using LinkerAnalyzer.Core; +using Mono.Options; namespace LinkerAnalyzer { @@ -56,7 +56,7 @@ namespace LinkerAnalyzer return; } - string dependencyFile = args [args.Length - 1]; + string dependencyFile = args[args.Length - 1]; ConsoleDependencyGraph deps = new ConsoleDependencyGraph () { Tree = reduceToTree, FlatDeps = flatDeps }; deps.Load (dependencyFile); diff --git a/src/linker/Linker.Steps/BaseSubStep.cs b/src/linker/Linker.Steps/BaseSubStep.cs index 4826c7014..af991fda9 100644 --- a/src/linker/Linker.Steps/BaseSubStep.cs +++ b/src/linker/Linker.Steps/BaseSubStep.cs @@ -1,7 +1,6 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using System; using System.Diagnostics; using Mono.Cecil; diff --git a/src/linker/Linker.Steps/DiscoverCustomOperatorsHandler.cs b/src/linker/Linker.Steps/DiscoverCustomOperatorsHandler.cs index 8497a61ea..64561aa6b 100644 --- a/src/linker/Linker.Steps/DiscoverCustomOperatorsHandler.cs +++ b/src/linker/Linker.Steps/DiscoverCustomOperatorsHandler.cs @@ -1,7 +1,6 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using System; using System.Collections.Generic; using System.Diagnostics; using Mono.Cecil; diff --git a/src/linker/Linker.Steps/DiscoverSerializationHandler.cs b/src/linker/Linker.Steps/DiscoverSerializationHandler.cs index 0b30d6ea4..6ac6da881 100644 --- a/src/linker/Linker.Steps/DiscoverSerializationHandler.cs +++ b/src/linker/Linker.Steps/DiscoverSerializationHandler.cs @@ -2,12 +2,8 @@ // The .NET Foundation licenses this file to you under the MIT license. using System; -using System.Collections.Generic; using System.Diagnostics; -using System.Linq; using Mono.Cecil; -using Mono.Linker.Dataflow; -using Mono.Linker.Steps; namespace Mono.Linker.Steps { diff --git a/src/linker/Linker.Steps/MarkSubStepsDispatcher.cs b/src/linker/Linker.Steps/MarkSubStepsDispatcher.cs index f97004fd0..8f15014f3 100644 --- a/src/linker/Linker.Steps/MarkSubStepsDispatcher.cs +++ b/src/linker/Linker.Steps/MarkSubStepsDispatcher.cs @@ -1,7 +1,6 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using System; using System.Collections.Generic; using System.Diagnostics; diff --git a/src/linker/Linker.Steps/OutputStep.cs b/src/linker/Linker.Steps/OutputStep.cs index b28d52c8d..2fd32880d 100644 --- a/src/linker/Linker.Steps/OutputStep.cs +++ b/src/linker/Linker.Steps/OutputStep.cs @@ -32,7 +32,6 @@ using System.IO; using System.Linq; using System.Runtime.Serialization.Json; using Mono.Cecil; -using Mono.Cecil.Cil; namespace Mono.Linker.Steps { diff --git a/src/linker/Linker.Steps/SubStepsDispatcher.cs b/src/linker/Linker.Steps/SubStepsDispatcher.cs index 3ed5a6e1c..338bbda8b 100644 --- a/src/linker/Linker.Steps/SubStepsDispatcher.cs +++ b/src/linker/Linker.Steps/SubStepsDispatcher.cs @@ -1,7 +1,6 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using System; using System.Collections.Generic; using System.Diagnostics; diff --git a/src/linker/Linker/AttributeInfo.cs b/src/linker/Linker/AttributeInfo.cs index 23b31c433..ea430b2de 100644 --- a/src/linker/Linker/AttributeInfo.cs +++ b/src/linker/Linker/AttributeInfo.cs @@ -3,7 +3,6 @@ using System; using System.Collections.Generic; -using System.Linq; using Mono.Cecil; namespace Mono.Linker diff --git a/src/linker/Linker/EmbeddedXmlInfo.cs b/src/linker/Linker/EmbeddedXmlInfo.cs index 14871394b..815bbb8d2 100644 --- a/src/linker/Linker/EmbeddedXmlInfo.cs +++ b/src/linker/Linker/EmbeddedXmlInfo.cs @@ -2,10 +2,8 @@ // The .NET Foundation licenses this file to you under the MIT license. using System; -using System.IO; using System.Linq; using System.Xml; -using System.Xml.XPath; using Mono.Cecil; using Mono.Linker.Steps; diff --git a/src/linker/Linker/MemberReferenceExtensions.cs b/src/linker/Linker/MemberReferenceExtensions.cs index b24364aaa..14278fdef 100644 --- a/src/linker/Linker/MemberReferenceExtensions.cs +++ b/src/linker/Linker/MemberReferenceExtensions.cs @@ -1,5 +1,4 @@ -using System; -using System.Diagnostics; +using System.Diagnostics; using System.Text; using Mono.Cecil; diff --git a/src/linker/Linker/MethodDefinitionExtensions.cs b/src/linker/Linker/MethodDefinitionExtensions.cs index 165b75138..d8b370422 100644 --- a/src/linker/Linker/MethodDefinitionExtensions.cs +++ b/src/linker/Linker/MethodDefinitionExtensions.cs @@ -1,5 +1,4 @@ -using System; -using System.Diagnostics.CodeAnalysis; +using System.Diagnostics.CodeAnalysis; using Mono.Cecil; namespace Mono.Linker diff --git a/src/linker/ref/Linker.Steps/BaseStep.cs b/src/linker/ref/Linker.Steps/BaseStep.cs index 53d03bbdd..417d0bf75 100644 --- a/src/linker/ref/Linker.Steps/BaseStep.cs +++ b/src/linker/ref/Linker.Steps/BaseStep.cs @@ -8,8 +8,8 @@ namespace Mono.Linker.Steps public abstract class BaseStep : IStep { - public LinkContext Context { get { throw null; } } - public AnnotationStore Annotations { get { throw null; } } + public static LinkContext Context { get { throw null; } } + public static AnnotationStore Annotations { get { throw null; } } public void Process (LinkContext context) { throw null; } protected virtual bool ConditionToProcess () { throw null; } protected virtual void Process () { throw null; } diff --git a/src/linker/ref/Linker.Steps/BaseSubStep.cs b/src/linker/ref/Linker.Steps/BaseSubStep.cs index 6fa045a1c..9f4f72067 100644 --- a/src/linker/ref/Linker.Steps/BaseSubStep.cs +++ b/src/linker/ref/Linker.Steps/BaseSubStep.cs @@ -7,9 +7,9 @@ namespace Mono.Linker.Steps { public abstract class BaseSubStep : ISubStep { - protected AnnotationStore Annotations { get => throw null; } + protected static AnnotationStore Annotations { get => throw null; } - protected LinkContext Context { get => throw null; } + protected static LinkContext Context { get => throw null; } public abstract SubStepTargets Targets { get; } diff --git a/src/linker/ref/Linker.Steps/SubStepsDispatcher.cs b/src/linker/ref/Linker.Steps/SubStepsDispatcher.cs index f6bbbbddd..bf6f7c64a 100644 --- a/src/linker/ref/Linker.Steps/SubStepsDispatcher.cs +++ b/src/linker/ref/Linker.Steps/SubStepsDispatcher.cs @@ -11,7 +11,7 @@ namespace Mono.Linker.Steps protected SubStepsDispatcher (IEnumerable<ISubStep> subSteps) => throw null; - public void Add (ISubStep substep) => throw null; + public static void Add (ISubStep substep) => throw null; void IStep.Process (LinkContext context) => throw null; } diff --git a/src/linker/ref/Linker/Annotations.cs b/src/linker/ref/Linker/Annotations.cs index 4490ffbf4..69309cb73 100644 --- a/src/linker/ref/Linker/Annotations.cs +++ b/src/linker/ref/Linker/Annotations.cs @@ -11,26 +11,26 @@ namespace Mono.Linker { internal AnnotationStore () { } - public IEnumerable<OverrideInformation> GetOverrides (MethodDefinition method) { throw null; } + public static IEnumerable<OverrideInformation> GetOverrides (MethodDefinition method) { throw null; } - public void Mark (IMetadataTokenProvider provider) { throw null; } - public void Mark (CustomAttribute attribute) { throw null; } + public static void Mark (IMetadataTokenProvider provider) { throw null; } + public static void Mark (CustomAttribute attribute) { throw null; } - public bool IsMarked (IMetadataTokenProvider provider) { throw null; } - public bool IsMarked (CustomAttribute attribute) { throw null; } + public static bool IsMarked (IMetadataTokenProvider provider) { throw null; } + public static bool IsMarked (CustomAttribute attribute) { throw null; } - public void AddPreservedMethod (MethodDefinition key, MethodDefinition method) { throw null; } - public void AddPreservedMethod (TypeDefinition type, MethodDefinition method) { throw null; } - public void SetPreserve (TypeDefinition type, TypePreserve preserve) { throw null; } + public static void AddPreservedMethod (MethodDefinition key, MethodDefinition method) { throw null; } + public static void AddPreservedMethod (TypeDefinition type, MethodDefinition method) { throw null; } + public static void SetPreserve (TypeDefinition type, TypePreserve preserve) { throw null; } - public void SetAction (MethodDefinition method, MethodAction action) { throw null; } - public void SetStubValue (MethodDefinition method, object value) { throw null; } + public static void SetAction (MethodDefinition method, MethodAction action) { throw null; } + public static void SetStubValue (MethodDefinition method, object value) { throw null; } - public AssemblyAction GetAction (AssemblyDefinition assembly) { throw null; } - public void SetAction (AssemblyDefinition assembly, AssemblyAction action) { throw null; } - public bool HasAction (AssemblyDefinition assembly) { throw null; } + public static AssemblyAction GetAction (AssemblyDefinition assembly) { throw null; } + public static void SetAction (AssemblyDefinition assembly, AssemblyAction action) { throw null; } + public static bool HasAction (AssemblyDefinition assembly) { throw null; } - public object GetCustomAnnotation (object key, IMetadataTokenProvider item) { throw null; } - public void SetCustomAnnotation (object key, IMetadataTokenProvider item, object value) { throw null; } + public static object GetCustomAnnotation (object key, IMetadataTokenProvider item) { throw null; } + public static void SetCustomAnnotation (object key, IMetadataTokenProvider item, object value) { throw null; } } } diff --git a/src/linker/ref/Linker/LinkContext.cs b/src/linker/ref/Linker/LinkContext.cs index 08dc1297e..3a452fd4c 100644 --- a/src/linker/ref/Linker/LinkContext.cs +++ b/src/linker/ref/Linker/LinkContext.cs @@ -9,25 +9,25 @@ namespace Mono.Linker public class LinkContext : IMetadataResolver { internal LinkContext () { } - public AnnotationStore Annotations { get { throw null; } } + public static AnnotationStore Annotations { get { throw null; } } - public TypeDefinition GetType (string fullName) { throw null; } - public string GetAssemblyLocation (AssemblyDefinition assembly) { throw null; } - public AssemblyDefinition GetLoadedAssembly (string name) { throw null; } + public static TypeDefinition GetType (string fullName) { throw null; } + public static string GetAssemblyLocation (AssemblyDefinition assembly) { throw null; } + public static AssemblyDefinition GetLoadedAssembly (string name) { throw null; } - public void LogMessage (MessageContainer message) { throw null; } + public static void LogMessage (MessageContainer message) { throw null; } - public bool HasCustomData (string key) { throw null; } - public bool TryGetCustomData (string key, out string value) { throw null; } + public static bool HasCustomData (string key) { throw null; } + public static bool TryGetCustomData (string key, out string value) { throw null; } public MethodDefinition Resolve (MethodReference methodReference) { throw null; } public FieldDefinition Resolve (FieldReference fieldReference) { throw null; } public TypeDefinition Resolve (TypeReference typeReference) { throw null; } - public MethodDefinition TryResolve (MethodReference methodReference) { throw null; } - public FieldDefinition TryResolve (FieldReference fieldReference) { throw null; } - public TypeDefinition TryResolve (TypeReference typeReference) { throw null; } + public static MethodDefinition TryResolve (MethodReference methodReference) { throw null; } + public static FieldDefinition TryResolve (FieldReference fieldReference) { throw null; } + public static TypeDefinition TryResolve (TypeReference typeReference) { throw null; } - public AssemblyDefinition Resolve (AssemblyNameReference nameReference) { throw null; } + public static AssemblyDefinition Resolve (AssemblyNameReference nameReference) { throw null; } } } diff --git a/src/linker/ref/Linker/OverrideInformation.cs b/src/linker/ref/Linker/OverrideInformation.cs index f33e94b71..4102b913e 100644 --- a/src/linker/ref/Linker/OverrideInformation.cs +++ b/src/linker/ref/Linker/OverrideInformation.cs @@ -11,9 +11,9 @@ namespace Mono.Linker { } - public MethodDefinition Base { get { throw null; } } - public MethodDefinition Override { get { throw null; } } - public InterfaceImplementation MatchingInterfaceImplementation { get { throw null; } } - public TypeDefinition InterfaceType { get { throw null; } } + public static MethodDefinition Base { get { throw null; } } + public static MethodDefinition Override { get { throw null; } } + public static InterfaceImplementation MatchingInterfaceImplementation { get { throw null; } } + public static TypeDefinition InterfaceType { get { throw null; } } } } diff --git a/test/ILLink.RoslynAnalyzer.Tests/CompilationExtensions.cs b/test/ILLink.RoslynAnalyzer.Tests/CompilationExtensions.cs index 550a7e8e4..64b3eecbb 100644 --- a/test/ILLink.RoslynAnalyzer.Tests/CompilationExtensions.cs +++ b/test/ILLink.RoslynAnalyzer.Tests/CompilationExtensions.cs @@ -1,14 +1,11 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using System; using System.Collections.Generic; using System.Collections.Immutable; using System.IO; using System.Linq; -using System.Text; using System.Threading; -using System.Threading.Tasks; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.Emit; using Xunit; diff --git a/test/ILLink.RoslynAnalyzer.Tests/RequiresAssemblyFilesAnalyzerTests.cs b/test/ILLink.RoslynAnalyzer.Tests/RequiresAssemblyFilesAnalyzerTests.cs index 7e27f2782..386279369 100644 --- a/test/ILLink.RoslynAnalyzer.Tests/RequiresAssemblyFilesAnalyzerTests.cs +++ b/test/ILLink.RoslynAnalyzer.Tests/RequiresAssemblyFilesAnalyzerTests.cs @@ -1,10 +1,8 @@ using System; using System.Collections.Generic; -using System.Linq; using System.Threading.Tasks; using ILLink.Shared; using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.Testing; using Microsoft.CodeAnalysis.Text; using Xunit; diff --git a/test/ILLink.RoslynAnalyzer.Tests/RequiresUnreferencedCodeAnalyzerTests.cs b/test/ILLink.RoslynAnalyzer.Tests/RequiresUnreferencedCodeAnalyzerTests.cs new file mode 100644 index 000000000..501ba16f9 --- /dev/null +++ b/test/ILLink.RoslynAnalyzer.Tests/RequiresUnreferencedCodeAnalyzerTests.cs @@ -0,0 +1,427 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using ILLink.Shared; +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.Testing; +using Microsoft.CodeAnalysis.Text; +using Xunit; +using VerifyCS = ILLink.RoslynAnalyzer.Tests.CSharpCodeFixVerifier< + ILLink.RoslynAnalyzer.RequiresUnreferencedCodeAnalyzer, + ILLink.CodeFix.RequiresUnreferencedCodeCodeFixProvider>; + +namespace ILLink.RoslynAnalyzer.Tests +{ + public class RequiresUnreferencedCodeAnalyzerTests + { + static readonly DiagnosticDescriptor dynamicInvocationDiagnosticDescriptor = DiagnosticDescriptors.GetDiagnosticDescriptor (DiagnosticId.RequiresUnreferencedCode, new DiagnosticString ("DynamicTypeInvocation")); + + static Task VerifyRequiresUnreferencedCodeAnalyzer (string source, params DiagnosticResult[] expected) => + VerifyRequiresUnreferencedCodeAnalyzer (source, null, expected); + + static async Task VerifyRequiresUnreferencedCodeAnalyzer (string source, IEnumerable<MetadataReference>? additionalReferences, params DiagnosticResult[] expected) => + await VerifyCS.VerifyAnalyzerAsync (source, + TestCaseUtils.UseMSBuildProperties (MSBuildPropertyOptionNames.EnableTrimAnalyzer), + additionalReferences ?? Array.Empty<MetadataReference> (), + expected); + + static Task VerifyRequiresUnreferencedCodeCodeFix ( + string source, + string fixedSource, + DiagnosticResult[] baselineExpected, + DiagnosticResult[] fixedExpected, + int? numberOfIterations = null) + { + var test = new VerifyCS.Test { + TestCode = source, + FixedCode = fixedSource, + ReferenceAssemblies = TestCaseUtils.Net6PreviewAssemblies + }; + test.ExpectedDiagnostics.AddRange (baselineExpected); + test.TestState.AnalyzerConfigFiles.Add ( + ("/.editorconfig", SourceText.From (@$" +is_global = true +build_property.{MSBuildPropertyOptionNames.EnableTrimAnalyzer} = true"))); + if (numberOfIterations != null) { + test.NumberOfIncrementalIterations = numberOfIterations; + test.NumberOfFixAllIterations = numberOfIterations; + } + test.FixedState.ExpectedDiagnostics.AddRange (fixedExpected); + return test.RunAsync (); + } + + + + [Fact] + public async Task SimpleDiagnosticFix () + { + var test = @" +using System.Diagnostics.CodeAnalysis; + +public class C +{ + [RequiresUnreferencedCodeAttribute(""message"")] + public int M1() => 0; + + int M2() => M1(); +} +class D +{ + public int M3(C c) => c.M1(); + + public class E + { + public int M4(C c) => c.M1(); + } +} +public class E +{ + public class F + { + public int M5(C c) => c.M1(); + } +} +"; + + var fixtest = @" +using System.Diagnostics.CodeAnalysis; + +public class C +{ + [RequiresUnreferencedCodeAttribute(""message"")] + public int M1() => 0; + + [RequiresUnreferencedCode(""Calls C.M1()"")] + int M2() => M1(); +} +class D +{ + [RequiresUnreferencedCode(""Calls C.M1()"")] + public int M3(C c) => c.M1(); + + public class E + { + [RequiresUnreferencedCode(""Calls C.M1()"")] + public int M4(C c) => c.M1(); + } +} +public class E +{ + public class F + { + [RequiresUnreferencedCode()] + public int M5(C c) => c.M1(); + } +} +"; + + await VerifyRequiresUnreferencedCodeCodeFix (test, fixtest, new[] { + // /0/Test0.cs(9,17): warning IL2026: Using member 'C.M1()' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. message. + VerifyCS.Diagnostic (DiagnosticId.RequiresUnreferencedCode).WithSpan (9, 17, 9, 21).WithArguments ("C.M1()", " message.", ""), + // /0/Test0.cs(13,27): warning IL2026: Using member 'C.M1()' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. message. + VerifyCS.Diagnostic(DiagnosticId.RequiresUnreferencedCode).WithSpan(13, 27, 13, 33).WithArguments("C.M1()", " message.", ""), + // /0/Test0.cs(17,31): warning IL2026: Using member 'C.M1()' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. message. + VerifyCS.Diagnostic (DiagnosticId.RequiresUnreferencedCode).WithSpan (17, 31, 17, 37).WithArguments ("C.M1()", " message.", ""), + // /0/Test0.cs(24,31): warning IL2026: Using member 'C.M1()' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. message. + VerifyCS.Diagnostic (DiagnosticId.RequiresUnreferencedCode).WithSpan (24, 31, 24, 37).WithArguments ("C.M1()", " message.", "") + }, new[] { + // /0/Test0.cs(27,10): error CS7036: There is no argument given that corresponds to the required formal parameter 'message' of 'RequiresUnreferencedCodeAttribute.RequiresUnreferencedCodeAttribute(string)' + DiagnosticResult.CompilerError("CS7036").WithSpan(27, 10, 27, 36).WithArguments("message", "System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute.RequiresUnreferencedCodeAttribute(string)"), + } + ); + } + + [Fact] + public Task FixInLambda () + { + var src = @" +using System; +using System.Diagnostics.CodeAnalysis; + +public class C +{ + [RequiresUnreferencedCodeAttribute(""message"")] + public int M1() => 0; + + Action M2() + { + return () => M1(); + } +}"; + var fix = @" +using System; +using System.Diagnostics.CodeAnalysis; + +public class C +{ + [RequiresUnreferencedCodeAttribute(""message"")] + public int M1() => 0; + + Action M2() + { + return () => M1(); + } +}"; + // No fix available inside a lambda, requries manual code change since attribute cannot + // be applied + return VerifyRequiresUnreferencedCodeCodeFix ( + src, + fix, + baselineExpected: new[] { + // /0/Test0.cs(12,22): warning IL2026: Using member 'C.M1()' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. message. + VerifyCS.Diagnostic(DiagnosticId.RequiresUnreferencedCode).WithSpan(12, 22, 12, 26).WithArguments("C.M1()", " message.", "") + }, + fixedExpected: Array.Empty<DiagnosticResult> ()); + } + + [Fact] + public Task FixInLocalFunc () + { + var src = @" +using System; +using System.Diagnostics.CodeAnalysis; + +public class C +{ + [RequiresUnreferencedCodeAttribute(""message"")] + public int M1() => 0; + + Action M2() + { + void Wrapper () => M1(); + return Wrapper; + } +}"; + var fix = @" +using System; +using System.Diagnostics.CodeAnalysis; + +public class C +{ + [RequiresUnreferencedCodeAttribute(""message"")] + public int M1() => 0; + + [RequiresUnreferencedCode(""Calls Wrapper()"")] + Action M2() + { + [global::System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute(""Calls C.M1()"")] void Wrapper () => M1(); + return Wrapper; + } +}"; + // Roslyn currently doesn't simplify the attribute name properly, see https://github.com/dotnet/roslyn/issues/52039 + return VerifyRequiresUnreferencedCodeCodeFix ( + src, + fix, + baselineExpected: new[] { + // /0/Test0.cs(12,28): warning IL2026: Using member 'C.M1()' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. message. + VerifyCS.Diagnostic(DiagnosticId.RequiresUnreferencedCode).WithSpan(12, 28, 12, 32).WithArguments("C.M1()", " message.", "") + }, + fixedExpected: Array.Empty<DiagnosticResult> (), + // The default iterations for the codefix is the number of diagnostics (1 in this case) + // but since the codefixer introduces a new diagnostic in the first iteration, it needs + // to run twice, so we need to set the number of iterations to 2. + numberOfIterations: 2); + } + + [Fact] + public Task FixInCtor () + { + var src = @" +using System; +using System.Diagnostics.CodeAnalysis; + +public class C +{ + [RequiresUnreferencedCodeAttribute(""message"")] + public static int M1() => 0; + + public C() => M1(); +}"; + var fix = @" +using System; +using System.Diagnostics.CodeAnalysis; + +public class C +{ + [RequiresUnreferencedCodeAttribute(""message"")] + public static int M1() => 0; + + [RequiresUnreferencedCode()] + public C() => M1(); +}"; + // Roslyn currently doesn't simplify the attribute name properly, see https://github.com/dotnet/roslyn/issues/52039 + return VerifyRequiresUnreferencedCodeCodeFix ( + src, + fix, + baselineExpected: new[] { + // /0/Test0.cs(10,19): warning IL2026: Using member 'C.M1()' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. message. + VerifyCS.Diagnostic(DiagnosticId.RequiresUnreferencedCode).WithSpan(10, 19, 10, 23).WithArguments("C.M1()", " message.", "") + }, + fixedExpected: new[] { + // /0/Test0.cs(10,6): error CS7036: There is no argument given that corresponds to the required formal parameter 'message' of 'RequiresUnreferencedCodeAttribute.RequiresUnreferencedCodeAttribute(string)' + DiagnosticResult.CompilerError("CS7036").WithSpan(10, 6, 10, 32).WithArguments("message", "System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute.RequiresUnreferencedCodeAttribute(string)"), + }); + } + + [Fact] + public Task FixInPropertyDecl () + { + var src = @" +using System; +using System.Diagnostics.CodeAnalysis; + +public class C +{ + [RequiresUnreferencedCodeAttribute(""message"")] + public int M1() => 0; + + int M2 => M1(); +}"; + var fix = @" +using System; +using System.Diagnostics.CodeAnalysis; + +public class C +{ + [RequiresUnreferencedCodeAttribute(""message"")] + public int M1() => 0; + + int M2 => M1(); +}"; + // Can't apply RUC on properties at the moment + return VerifyRequiresUnreferencedCodeCodeFix ( + src, + fix, + baselineExpected: new[] { + // /0/Test0.cs(10,15): warning IL2026: Using member 'C.M1()' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. message. + VerifyCS.Diagnostic(DiagnosticId.RequiresUnreferencedCode).WithSpan(10, 15, 10, 19).WithArguments("C.M1()", " message.", "") + }, + fixedExpected: new[] { + // /0/Test0.cs(10,15): warning IL2026: Using member 'C.M1()' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. message. + VerifyCS.Diagnostic(DiagnosticId.RequiresUnreferencedCode).WithSpan(10, 15, 10, 19).WithArguments("C.M1()", " message.", "") + }); + } + + [Fact] + public Task InvocationOnDynamicType () + { + var source = @" +using System; +class C +{ + static void M0 () + { + dynamic dynamicField = ""Some string""; + Console.WriteLine (dynamicField); + } + + static void M1 () + { + MethodWithDynamicArgDoNothing (0); + MethodWithDynamicArgDoNothing (""Some string""); + MethodWithDynamicArg(-1); + } + + static void MethodWithDynamicArgDoNothing (dynamic arg) + { + } + + static void MethodWithDynamicArg (dynamic arg) + { + arg.MethodWithDynamicArg (arg); + } +}"; + + return VerifyRequiresUnreferencedCodeAnalyzer (source, + // (8,3): warning IL2026: Invoking members on dynamic types is not trimming safe. Types or members might have been removed by the trimmer. + VerifyCS.Diagnostic (dynamicInvocationDiagnosticDescriptor).WithSpan (8, 3, 8, 35), + // (24,3): warning IL2026: Invoking members on dynamic types is not trimming safe. Types or members might have been removed by the trimmer. + VerifyCS.Diagnostic (dynamicInvocationDiagnosticDescriptor).WithSpan (24, 3, 24, 33)); + } + + [Fact] + public Task InvocationOnDynamicTypeInMethodWithRUCDoesNotWarnTwoTimes () + { + var source = @" +using System; +using System.Diagnostics.CodeAnalysis; +class C +{ + [RequiresUnreferencedCode (""We should only see the warning related to this annotation, and none about the dynamic type."")] + static void M0 () + { + dynamic dynamicField = ""Some string""; + Console.WriteLine (dynamicField); + } +}"; + + return VerifyRequiresUnreferencedCodeAnalyzer (source); + } + + [Fact] + public Task TestMakeGenericMethodUsage () + { + var source = @" +using System.Diagnostics.CodeAnalysis; +using System.Reflection; + +class C +{ + static void M1 (MethodInfo methodInfo) + { + methodInfo.MakeGenericMethod (typeof (C)); + } + + [RequiresUnreferencedCode (""Message from RUC"")] + static void M2 (MethodInfo methodInfo) + { + methodInfo.MakeGenericMethod (typeof (C)); + } +}"; + + return VerifyRequiresUnreferencedCodeAnalyzer (source); + } + + [Fact] + public Task TestMakeGenericTypeUsage () + { + var source = @" +using System; +using System.Diagnostics.CodeAnalysis; + +class C +{ + static void M1 (Type t) + { + typeof (Nullable<>).MakeGenericType (typeof (C)); + } + + [RequiresUnreferencedCode (""Message from RUC"")] + static void M2 (Type t) + { + typeof (Nullable<>).MakeGenericType (typeof (C)); + } +}"; + + return VerifyRequiresUnreferencedCodeAnalyzer (source); + } + + [Fact] + public Task VerifyThatAnalysisOfFieldsDoesNotNullRef () + { + var source = @" +using System.Diagnostics.CodeAnalysis; + +[DynamicallyAccessedMembers (field)] +class C +{ + public const DynamicallyAccessedMemberTypes field = DynamicallyAccessedMemberTypes.PublicMethods; +}"; + + return VerifyRequiresUnreferencedCodeAnalyzer (source); + } + } +} diff --git a/test/ILLink.RoslynAnalyzer.Tests/TestCaseCompilation.cs b/test/ILLink.RoslynAnalyzer.Tests/TestCaseCompilation.cs index edca78bfe..f2764ef29 100644 --- a/test/ILLink.RoslynAnalyzer.Tests/TestCaseCompilation.cs +++ b/test/ILLink.RoslynAnalyzer.Tests/TestCaseCompilation.cs @@ -4,9 +4,7 @@ using System; using System.Collections.Generic; using System.Collections.Immutable; -using System.Diagnostics; using System.Linq; -using System.Text; using System.Threading.Tasks; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; diff --git a/test/ILLink.RoslynAnalyzer.Tests/TestCaseUtils.cs b/test/ILLink.RoslynAnalyzer.Tests/TestCaseUtils.cs index 194a1a96b..eb7c2b4b4 100644 --- a/test/ILLink.RoslynAnalyzer.Tests/TestCaseUtils.cs +++ b/test/ILLink.RoslynAnalyzer.Tests/TestCaseUtils.cs @@ -12,7 +12,6 @@ using System.Threading.Tasks; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; -using Microsoft.CodeAnalysis.Diagnostics; using Microsoft.CodeAnalysis.Testing; using Microsoft.CodeAnalysis.Text; using Xunit; @@ -31,7 +30,7 @@ namespace ILLink.RoslynAnalyzer.Tests .WithNuGetConfigFilePath (Path.Combine (TestCaseUtils.GetRepoRoot (), "NuGet.config")); private static ImmutableArray<MetadataReference> s_net6Refs; - public async static ValueTask<ImmutableArray<MetadataReference>> GetNet6References () + public static async ValueTask<ImmutableArray<MetadataReference>> GetNet6References () { if (s_net6Refs.IsDefault) { var refs = await Net6PreviewAssemblies.ResolveAsync (null, default); diff --git a/test/ILLink.RoslynAnalyzer.Tests/TestChecker.cs b/test/ILLink.RoslynAnalyzer.Tests/TestChecker.cs index 56b5c1e72..2bc19c118 100644 --- a/test/ILLink.RoslynAnalyzer.Tests/TestChecker.cs +++ b/test/ILLink.RoslynAnalyzer.Tests/TestChecker.cs @@ -10,7 +10,6 @@ using System.Text; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; -using Microsoft.CodeAnalysis.Diagnostics; using Microsoft.CodeAnalysis.Text; using Mono.Linker.Tests.Cases.Expectations.Assertions; using Xunit; @@ -159,7 +158,7 @@ namespace ILLink.RoslynAnalyzer.Tests } } - bool IsExpectedDiagnostic (AttributeSyntax attribute) + static bool IsExpectedDiagnostic (AttributeSyntax attribute) { switch (attribute.Name.ToString ()) { case "ExpectedWarning": @@ -282,7 +281,7 @@ namespace ILLink.RoslynAnalyzer.Tests } } - missingDiagnosticMessage = $"Could not find text:\n{text}\nIn diagnostics:\n{(string.Join (Environment.NewLine, _diagnostics))}"; + missingDiagnosticMessage = $"Could not find text:\n{text}\nIn diagnostics:\n{string.Join (Environment.NewLine, _diagnostics)}"; return false; } diff --git a/test/ILLink.RoslynAnalyzer.Tests/UnconditionalSuppressMessageCodeFixTests.cs b/test/ILLink.RoslynAnalyzer.Tests/UnconditionalSuppressMessageCodeFixTests.cs index 26a273aff..3e308104f 100644 --- a/test/ILLink.RoslynAnalyzer.Tests/UnconditionalSuppressMessageCodeFixTests.cs +++ b/test/ILLink.RoslynAnalyzer.Tests/UnconditionalSuppressMessageCodeFixTests.cs @@ -2,12 +2,8 @@ // The .NET Foundation licenses this file to you under the MIT license. using System; -using System.Diagnostics.CodeAnalysis; using System.Threading.Tasks; -using ILLink.CodeFix; using ILLink.Shared; -using Microsoft.CodeAnalysis.CodeFixes; -using Microsoft.CodeAnalysis.Diagnostics; using Microsoft.CodeAnalysis.Testing; using Microsoft.CodeAnalysis.Text; using Xunit; diff --git a/test/ILLink.RoslynAnalyzer.Tests/Verifiers/CSharpAnalyzerVerifier`1.cs b/test/ILLink.RoslynAnalyzer.Tests/Verifiers/CSharpAnalyzerVerifier`1.cs index 79800c3f8..37c7ae4f9 100644 --- a/test/ILLink.RoslynAnalyzer.Tests/Verifiers/CSharpAnalyzerVerifier`1.cs +++ b/test/ILLink.RoslynAnalyzer.Tests/Verifiers/CSharpAnalyzerVerifier`1.cs @@ -2,7 +2,6 @@ using System; using System.Collections.Generic; using System.Collections.Immutable; using System.Diagnostics; -using System.IO; using System.Linq; using System.Reflection; using System.Text; @@ -10,7 +9,6 @@ using System.Threading; using System.Threading.Tasks; using ILLink.Shared; using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Testing; using Microsoft.CodeAnalysis.Diagnostics; using Microsoft.CodeAnalysis.Testing; diff --git a/test/ILLink.RoslynAnalyzer.Tests/Verifiers/CSharpCodeFixVerifier`2.cs b/test/ILLink.RoslynAnalyzer.Tests/Verifiers/CSharpCodeFixVerifier`2.cs index 9fc04e38f..fcef098ea 100644 --- a/test/ILLink.RoslynAnalyzer.Tests/Verifiers/CSharpCodeFixVerifier`2.cs +++ b/test/ILLink.RoslynAnalyzer.Tests/Verifiers/CSharpCodeFixVerifier`2.cs @@ -6,7 +6,6 @@ using System.Threading; using System.Threading.Tasks; using ILLink.Shared; using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.CSharp.Testing; using Microsoft.CodeAnalysis.Diagnostics; using Microsoft.CodeAnalysis.Testing; diff --git a/test/ILLink.Tasks.Tests/CreateRuntimeRootDescriptorFileTests.cs b/test/ILLink.Tasks.Tests/CreateRuntimeRootDescriptorFileTests.cs index 19d5e6c86..db3bf83f6 100644 --- a/test/ILLink.Tasks.Tests/CreateRuntimeRootDescriptorFileTests.cs +++ b/test/ILLink.Tasks.Tests/CreateRuntimeRootDescriptorFileTests.cs @@ -3,9 +3,7 @@ using System; using System.IO; -using System.Linq; using System.Xml.Linq; -using Microsoft.Build.Framework; using Microsoft.Build.Utilities; using Xunit; @@ -47,7 +45,7 @@ namespace ILLink.Tasks.Tests File.WriteAllText ("namespace.h", "#define g_TestNS \"TestNS\"" + Environment.NewLine); - File.WriteAllLines ("cortypeinfo.h", new string[] { }); + File.WriteAllLines ("cortypeinfo.h", Array.Empty<string> ()); File.WriteAllLines ("rexcep.h", new string[] { "DEFINE_EXCEPTION(g_TestNS, TestAlwaysException, false, C)", @@ -62,7 +60,7 @@ namespace ILLink.Tasks.Tests XElement existingAssembly = new XElement ("assembly", new XAttribute ("fullname", "testassembly"), new XComment ("Existing content")); XElement existingContent = new XElement ("linker", existingAssembly); - (new XDocument (existingContent)).Save ("Test.ILLink.Descriptors.Combined.xml"); + new XDocument (existingContent).Save ("Test.ILLink.Descriptors.Combined.xml"); var task = new CreateRuntimeRootILLinkDescriptorFile () { NamespaceFilePath = new TaskItem ("namespace.h"), @@ -142,7 +140,7 @@ namespace ILLink.Tasks.Tests File.WriteAllText ("namespace.h", "#define g_TestNS \"TestNS\"" + Environment.NewLine); - File.WriteAllLines ("cortypeinfo.h", new string[] { }); + File.WriteAllLines ("cortypeinfo.h", Array.Empty<string> ()); File.WriteAllLines ("rexcep.h", new string[] { "DEFINE_EXCEPTION(g_TestNS, TestAlwaysException, false, C)", @@ -157,7 +155,7 @@ namespace ILLink.Tasks.Tests XElement existingAssembly = new XElement ("assembly", new XAttribute ("fullname", "testassembly"), new XComment ("Existing content")); XElement existingContent = new XElement ("linker", existingAssembly); - (new XDocument (existingContent)).Save ("Test.ILLink.Descriptors.Combined.xml"); + new XDocument (existingContent).Save ("Test.ILLink.Descriptors.Combined.xml"); var task = new CreateRuntimeRootILLinkDescriptorFile () { NamespaceFilePath = new TaskItem ("namespace.h"), diff --git a/test/ILLink.Tasks.Tests/ILLink.Tasks.Tests.cs b/test/ILLink.Tasks.Tests/ILLink.Tasks.Tests.cs index 216dec205..e6aef3617 100644 --- a/test/ILLink.Tasks.Tests/ILLink.Tasks.Tests.cs +++ b/test/ILLink.Tasks.Tests/ILLink.Tasks.Tests.cs @@ -369,7 +369,7 @@ namespace ILLink.Tasks.Tests using (var driver = task.CreateDriver ()) { var actualWarnAsError = driver.Context.WarnAsError; var actualGeneralWarnAsError = driver.Context.GeneralWarnAsError; - Assert.Equal (warnAsError.Count () + warnNotAsError.Count (), actualWarnAsError.Count); + Assert.Equal (warnAsError.Length + warnNotAsError.Length, actualWarnAsError.Count); Assert.Equal (treatWarningsAsErrors, actualGeneralWarnAsError); if (warnAsError.Length > 0) { foreach (var warningCode in warnAsError) @@ -753,7 +753,7 @@ namespace ILLink.Tasks.Tests public void TestErrorHandling () { var task = new MockTask () { - RootAssemblyNames = new ITaskItem[0] + RootAssemblyNames = Array.Empty<ITaskItem> () }; task.BuildEngine = new MockBuildEngine (); Assert.False (task.Execute ()); diff --git a/test/ILLink.Tasks.Tests/Mock.cs b/test/ILLink.Tasks.Tests/Mock.cs index dba28887b..2ea9e492c 100644 --- a/test/ILLink.Tasks.Tests/Mock.cs +++ b/test/ILLink.Tasks.Tests/Mock.cs @@ -21,8 +21,8 @@ namespace ILLink.Tasks.Tests public MockTask () { // Ensure that [Required] members are non-null - AssemblyPaths = new ITaskItem[0]; - RootAssemblyNames = new ITaskItem[0]; + AssemblyPaths = Array.Empty<ITaskItem> (); + RootAssemblyNames = Array.Empty<ITaskItem> (); ILLinkPath = Path.Combine (Path.GetDirectoryName (Assembly.GetExecutingAssembly ().Location), "illink.dll"); } diff --git a/test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresCapability.cs b/test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresCapability.cs index c78418ae7..b30027738 100644 --- a/test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresCapability.cs +++ b/test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresCapability.cs @@ -935,12 +935,12 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability [RequiresAssemblyFiles ("Message")] public virtual string VirtualPropertyAnnotationInProperty { get; set; } - [RequiresAssemblyFiles("Message")] - public virtual string VirtualPropertyAnnotationInPropertyAndAccessor { - [RequiresAssemblyFiles("Message")] - [RequiresUnreferencedCode("Message")] - get; - set; + [RequiresAssemblyFiles ("Message")] + public virtual string VirtualPropertyAnnotationInPropertyAndAccessor { + [RequiresAssemblyFiles ("Message")] + [RequiresUnreferencedCode ("Message")] + get; + set; } } @@ -1019,14 +1019,14 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability private string name; - [RequiresAssemblyFiles("Message")] + [RequiresAssemblyFiles ("Message")] [ExpectedWarning ("IL3003", "DerivedClassWithAllWarnings.VirtualPropertyAnnotationInAccesor", "BaseClassWithRequires.VirtualPropertyAnnotationInAccesor", ProducedBy = ProducedBy.Analyzer)] public override string VirtualPropertyAnnotationInAccesor { [ExpectedWarning ("IL2046", "DerivedClassWithAllWarnings.VirtualPropertyAnnotationInAccesor.get", "BaseClassWithRequires.VirtualPropertyAnnotationInAccesor.get")] [ExpectedWarning ("IL3003", "DerivedClassWithAllWarnings.VirtualPropertyAnnotationInAccesor.get", "BaseClassWithRequires.VirtualPropertyAnnotationInAccesor.get", ProducedBy = ProducedBy.Analyzer)] get { return name; } [RequiresAssemblyFiles ("Message")] - [RequiresUnreferencedCode("Message")] + [RequiresUnreferencedCode ("Message")] [ExpectedWarning ("IL2046", "VirtualPropertyAnnotationInAccesor.set", "BaseClassWithRequires.VirtualPropertyAnnotationInAccesor.set")] [ExpectedWarning ("IL3003", "DerivedClassWithAllWarnings.VirtualPropertyAnnotationInAccesor.set", "BaseClassWithRequires.VirtualPropertyAnnotationInAccesor.set", ProducedBy = ProducedBy.Analyzer)] set { name = value; } @@ -1043,7 +1043,8 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability [RequiresUnreferencedCode ("Message")] [ExpectedWarning ("IL2046", "VirtualPropertyAnnotationInProperty.set", "BaseClassWithRequires.VirtualPropertyAnnotationInProperty.set")] [ExpectedWarning ("IL3003", "DerivedClassWithAllWarnings.VirtualPropertyAnnotationInProperty.set", "BaseClassWithRequires.VirtualPropertyAnnotationInProperty.set", ProducedBy = ProducedBy.Analyzer)] - set; } + set; + } [ExpectedWarning ("IL3003", "DerivedClassWithAllWarnings.VirtualPropertyAnnotationInPropertyAndAccessor", "BaseClassWithRequires.VirtualPropertyAnnotationInPropertyAndAccessor", ProducedBy = ProducedBy.Analyzer)] public override string VirtualPropertyAnnotationInPropertyAndAccessor { @@ -1075,11 +1076,12 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability string PropertyAnnotationInProperty { get; set; } [RequiresAssemblyFiles ("Message")] - string PropertyAnnotationInPropertyAndAccessor { + string PropertyAnnotationInPropertyAndAccessor { get; [RequiresUnreferencedCode ("Message")] [RequiresAssemblyFiles ("Message")] - set; } + set; + } } public interface IBaseWithoutRequires @@ -1121,11 +1123,12 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability [ExpectedWarning ("IL3003", "ImplementationClassWithRequires.PropertyAnnotationInPropertyAndAccessor", "IBaseWithoutRequires.PropertyAnnotationInPropertyAndAccessor", ProducedBy = ProducedBy.Analyzer)] public string PropertyAnnotationInPropertyAndAccessor { [RequiresAssemblyFiles ("Message")] - [RequiresUnreferencedCode("Message")] + [RequiresUnreferencedCode ("Message")] [ExpectedWarning ("IL2046", "ImplementationClassWithRequires.PropertyAnnotationInPropertyAndAccessor.get", "IBaseWithoutRequires.PropertyAnnotationInPropertyAndAccessor.get")] [ExpectedWarning ("IL3003", "ImplementationClassWithRequires.PropertyAnnotationInPropertyAndAccessor.get", "IBaseWithoutRequires.PropertyAnnotationInPropertyAndAccessor.get", ProducedBy = ProducedBy.Analyzer)] - get; - set; } + get; + set; + } } class ExplicitImplementationClassWithRequires : IBaseWithoutRequires @@ -1156,7 +1159,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability [ExpectedWarning ("IL3003", "PropertyAnnotationInPropertyAndAccessor", "IBaseWithoutRequires.PropertyAnnotationInPropertyAndAccessor", ProducedBy = ProducedBy.Analyzer)] string IBaseWithoutRequires.PropertyAnnotationInPropertyAndAccessor { [RequiresAssemblyFiles ("Message")] - [RequiresUnreferencedCode("Message")] + [RequiresUnreferencedCode ("Message")] [ExpectedWarning ("IL2046", "PropertyAnnotationInPropertyAndAccessor.get", "IBaseWithoutRequires.PropertyAnnotationInPropertyAndAccessor.get")] [ExpectedWarning ("IL3003", "PropertyAnnotationInPropertyAndAccessor.get", "IBaseWithoutRequires.PropertyAnnotationInPropertyAndAccessor.get", ProducedBy = ProducedBy.Analyzer)] get; @@ -1185,8 +1188,8 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability [ExpectedWarning ("IL3003", "ImplementationClassWithoutRequires.PropertyAnnotationInPropertyAndAccessor", "IBaseWithRequires.PropertyAnnotationInPropertyAndAccessor", ProducedBy = ProducedBy.Analyzer)] public string PropertyAnnotationInPropertyAndAccessor { - [RequiresAssemblyFiles("Message")] - [RequiresUnreferencedCode("Message")] + [RequiresAssemblyFiles ("Message")] + [RequiresUnreferencedCode ("Message")] [ExpectedWarning ("IL2046", "ImplementationClassWithoutRequires.PropertyAnnotationInPropertyAndAccessor.get", "IBaseWithRequires.PropertyAnnotationInPropertyAndAccessor.get")] [ExpectedWarning ("IL3003", "ImplementationClassWithoutRequires.PropertyAnnotationInPropertyAndAccessor.get", "IBaseWithRequires.PropertyAnnotationInPropertyAndAccessor.get", ProducedBy = ProducedBy.Analyzer)] get; @@ -1535,8 +1538,6 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability [RequiresUnreferencedCode ("RUC")] class DerivedWithRequiresOnType : BaseWithoutRequiresOnType { - // Bug https://github.com/dotnet/linker/issues/2379 - //[ExpectedWarning ("IL2046", ProducedBy = ProducedBy.Analyzer)] public override void Method () { } } @@ -1572,8 +1573,6 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability return 1; } - // Bug https://github.com/dotnet/linker/issues/2379 - //[ExpectedWarning ("IL2046", ProducedBy = ProducedBy.Analyzer)] public int Method (int a) { return a; diff --git a/test/Mono.Linker.Tests/Extensions/NiceIO.cs b/test/Mono.Linker.Tests/Extensions/NiceIO.cs index 8cbf9c5a5..5fbe8982c 100644 --- a/test/Mono.Linker.Tests/Extensions/NiceIO.cs +++ b/test/Mono.Linker.Tests/Extensions/NiceIO.cs @@ -51,7 +51,7 @@ namespace Mono.Linker.Tests.Extensions if (path == "/") { _isRelative = false; - _elements = new string[] { }; + _elements = Array.Empty<string> (); } else { var split = path.Split ('/', '\\'); @@ -94,7 +94,7 @@ namespace Mono.Linker.Tests.Extensions return stack.Count > 0 && stack[stack.Count - 1] != ".."; } - private string ParseDriveLetter (string path, out string driveLetter) + private static string ParseDriveLetter (string path, out string driveLetter) { if (path.Length >= 2 && path[1] == ':') { driveLetter = path[0].ToString (); @@ -433,7 +433,7 @@ namespace Mono.Linker.Tests.Extensions ThrowIfRelative (); ThrowIfRoot (); EnsureParentDirectoryExists (); - File.WriteAllBytes (ToString (), new byte[0]); + File.WriteAllBytes (ToString (), Array.Empty<byte> ()); return this; } diff --git a/test/Mono.Linker.Tests/TestCases/IndividualTests.cs b/test/Mono.Linker.Tests/TestCases/IndividualTests.cs index a6fb77cad..ca7754f8e 100644 --- a/test/Mono.Linker.Tests/TestCases/IndividualTests.cs +++ b/test/Mono.Linker.Tests/TestCases/IndividualTests.cs @@ -19,7 +19,7 @@ namespace Mono.Linker.Tests.TestCases [TestFixture] public class IndividualTests { - private NPath TestsDirectory => TestDatabase.TestCasesRootDirectory.Parent.Combine ("Mono.Linker.Tests"); + private static NPath TestsDirectory => TestDatabase.TestCasesRootDirectory.Parent.Combine ("Mono.Linker.Tests"); [Test] public void CanSkipUnresolved () @@ -217,14 +217,14 @@ namespace Mono.Linker.Tests.TestCases Assert.That (secondOutputMvid, Is.EqualTo (firstOutputMvid)); } - protected Guid GetMvid (NPath assemblyPath) + protected static Guid GetMvid (NPath assemblyPath) { using (var assembly = AssemblyDefinition.ReadAssembly (assemblyPath)) { return assembly.MainModule.Mvid; } } - private TestCase CreateIndividualCase (Type testCaseType) + private static TestCase CreateIndividualCase (Type testCaseType) { return TestDatabase.CreateCollector ().CreateIndividualCase (testCaseType); } diff --git a/test/Mono.Linker.Tests/TestCasesRunner/PeVerifier.cs b/test/Mono.Linker.Tests/TestCasesRunner/PeVerifier.cs index f4d4b25df..3c9a222be 100644 --- a/test/Mono.Linker.Tests/TestCasesRunner/PeVerifier.cs +++ b/test/Mono.Linker.Tests/TestCasesRunner/PeVerifier.cs @@ -5,7 +5,6 @@ using System.Linq; using Mono.Cecil; using Mono.Linker.Tests.Cases.Expectations.Assertions; using Mono.Linker.Tests.Extensions; -using NUnit.Framework; namespace Mono.Linker.Tests.TestCasesRunner { diff --git a/test/Mono.Linker.Tests/TestCasesRunner/ResultChecker.cs b/test/Mono.Linker.Tests/TestCasesRunner/ResultChecker.cs index 949029edc..8915d13fb 100644 --- a/test/Mono.Linker.Tests/TestCasesRunner/ResultChecker.cs +++ b/test/Mono.Linker.Tests/TestCasesRunner/ResultChecker.cs @@ -3,8 +3,6 @@ using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; -using System.Runtime.CompilerServices; -using System.Text; using System.Text.RegularExpressions; using Mono.Cecil; using Mono.Cecil.Cil; @@ -395,7 +393,7 @@ namespace Mono.Linker.Tests.TestCasesRunner Assert.Fail ($"Invalid test assertion. No member named `{memberName}` exists on the original type `{originalType}`"); } - void VerifyCopyAssemblyIsKeptUnmodified (NPath outputDirectory, string assemblyName) + static void VerifyCopyAssemblyIsKeptUnmodified (NPath outputDirectory, string assemblyName) { string inputAssemblyPath = Path.Combine (Directory.GetParent (outputDirectory).ToString (), "input", assemblyName); string outputAssemblyPath = Path.Combine (outputDirectory, assemblyName); @@ -602,7 +600,7 @@ namespace Mono.Linker.Tests.TestCasesRunner { var assembly = ResolveLinkedAssembly (inAssemblyAttribute.ConstructorArguments[0].Value.ToString ()); var expectedReferenceNames = ((CustomAttributeArgument[]) inAssemblyAttribute.ConstructorArguments[1].Value).Select (attr => (string) attr.Value).ToList (); - for (int i = 0; i < expectedReferenceNames.Count (); i++) + for (int i = 0; i < expectedReferenceNames.Count; i++) if (expectedReferenceNames[i].EndsWith (".dll")) expectedReferenceNames[i] = expectedReferenceNames[i].Substring (0, expectedReferenceNames[i].LastIndexOf (".")); @@ -651,12 +649,13 @@ namespace Mono.Linker.Tests.TestCasesRunner } } - bool IsProducedByLinker (CustomAttribute attr) + static bool IsProducedByLinker (CustomAttribute attr) { var producedBy = attr.GetPropertyValue ("ProducedBy"); return producedBy is null ? true : ((ProducedBy) producedBy).HasFlag (ProducedBy.Trimmer); } - IEnumerable<ICustomAttributeProvider> GetAttributeProviders (AssemblyDefinition assembly) + + static IEnumerable<ICustomAttributeProvider> GetAttributeProviders (AssemblyDefinition assembly) { foreach (var testType in assembly.AllDefinedTypes ()) { foreach (var provider in testType.AllMembers ()) @@ -767,8 +766,7 @@ namespace Mono.Linker.Tests.TestCasesRunner return false; } } else if (isCompilerGeneratedCode == true) { - MethodDefinition methodDefinition = mc.Origin?.Provider as MethodDefinition; - if (methodDefinition != null) { + if (mc.Origin?.Provider is MethodDefinition methodDefinition) { if (attrProvider is not IMemberDefinition expectedMember) return false; @@ -946,7 +944,7 @@ namespace Mono.Linker.Tests.TestCasesRunner $"{expectedSourceMember}: Usage of {expectedReflectionMember} unrecognized " + $"{(expectedMessageParts == null ? string.Empty : "and message contains " + string.Join (" ", expectedMessageParts.Select (p => "'" + p + "'")))}"; - Assert.AreEqual (matchedMessages.Count (), matchedPatterns.Count (), + Assert.AreEqual (matchedMessages.Count, matchedPatterns.Count, $"Inconsistency between logged messages and recorded patterns.{Environment.NewLine}{expectedUnrecognizedPatternMessage}{Environment.NewLine}" + $"Matched messages: {Environment.NewLine}{string.Join (Environment.NewLine, matchedMessages.Select (mc => "\t" + mc.Text))}{Environment.NewLine}" + $"Matched unrecognized patterns: {Environment.NewLine}{string.Join (Environment.NewLine, matchedPatterns.Select (p => "\t" + RecognizedReflectionAccessPatternToString (p)))}{Environment.NewLine}"); @@ -1346,7 +1344,7 @@ namespace Mono.Linker.Tests.TestCasesRunner return attr.AttributeType.Resolve ()?.DerivesFrom (nameof (BaseInAssemblyAttribute)) ?? false; } - bool HasAttribute (ICustomAttributeProvider caProvider, string attributeName) + static bool HasAttribute (ICustomAttributeProvider caProvider, string attributeName) { if (caProvider is AssemblyDefinition assembly && assembly.EntryPoint != null) return assembly.EntryPoint.DeclaringType.CustomAttributes diff --git a/test/Mono.Linker.Tests/TestCasesRunner/TestCaseCompiler.cs b/test/Mono.Linker.Tests/TestCasesRunner/TestCaseCompiler.cs index 5d6c8c35a..2607e356e 100644 --- a/test/Mono.Linker.Tests/TestCasesRunner/TestCaseCompiler.cs +++ b/test/Mono.Linker.Tests/TestCasesRunner/TestCaseCompiler.cs @@ -36,7 +36,7 @@ namespace Mono.Linker.Tests.TestCasesRunner public NPath CompileTestIn (NPath outputDirectory, string outputName, IEnumerable<string> sourceFiles, string[] commonReferences, string[] mainAssemblyReferences, IEnumerable<string> defines, NPath[] resources, string[] additionalArguments) { var originalCommonReferences = commonReferences.Select (r => r.ToNPath ()).ToArray (); - var originalDefines = defines?.ToArray () ?? new string[0]; + var originalDefines = defines?.ToArray () ?? Array.Empty<string> (); Prepare (outputDirectory); @@ -89,8 +89,8 @@ namespace Mono.Linker.Tests.TestCasesRunner protected virtual CompilerOptions CreateOptionsForSupportingAssembly (SetupCompileInfo setupCompileInfo, NPath outputDirectory, NPath[] sourceFiles, NPath[] references, string[] defines, NPath[] resources) { - var allDefines = defines.Concat (setupCompileInfo.Defines ?? new string[0]).ToArray (); - var allReferences = references.Concat (setupCompileInfo.References?.Select (p => MakeSupportingAssemblyReferencePathAbsolute (outputDirectory, p)) ?? new NPath[0]).ToArray (); + var allDefines = defines.Concat (setupCompileInfo.Defines ?? Array.Empty<string> ()).ToArray (); + var allReferences = references.Concat (setupCompileInfo.References?.Select (p => MakeSupportingAssemblyReferencePathAbsolute (outputDirectory, p)) ?? Array.Empty<NPath> ()).ToArray (); string[] additionalArguments = string.IsNullOrEmpty (setupCompileInfo.AdditionalArguments) ? null : new[] { setupCompileInfo.AdditionalArguments }; return new CompilerOptions { OutputPath = outputDirectory.Combine (setupCompileInfo.OutputName), diff --git a/test/Mono.Linker.Tests/TestCasesRunner/TestCaseMetadataProvider.cs b/test/Mono.Linker.Tests/TestCasesRunner/TestCaseMetadataProvider.cs index 404ecbf0f..fdcde52f7 100644 --- a/test/Mono.Linker.Tests/TestCasesRunner/TestCaseMetadataProvider.cs +++ b/test/Mono.Linker.Tests/TestCasesRunner/TestCaseMetadataProvider.cs @@ -69,7 +69,7 @@ namespace Mono.Linker.Tests.TestCasesRunner if (pos != -1) { string custom_assembly_path = values[0].Substring (pos + 1); if (!Path.IsPathRooted (custom_assembly_path)) - values[0] = values[0].Substring (0, pos + 1) + Path.Combine (inputPath, custom_assembly_path); + values[0] = string.Concat (values[0].AsSpan (0, pos + 1), Path.Combine (inputPath, custom_assembly_path)); } break; case "-a": diff --git a/test/Mono.Linker.Tests/TestCasesRunner/TestReflectionPatternRecorder.cs b/test/Mono.Linker.Tests/TestCasesRunner/TestReflectionPatternRecorder.cs index d4b70f1f7..7143952ed 100644 --- a/test/Mono.Linker.Tests/TestCasesRunner/TestReflectionPatternRecorder.cs +++ b/test/Mono.Linker.Tests/TestCasesRunner/TestReflectionPatternRecorder.cs @@ -6,7 +6,7 @@ namespace Mono.Linker.Tests.TestCasesRunner { public class TestReflectionPatternRecorder : IReflectionPatternRecorder { - public IReflectionPatternRecorder PreviousRecorder = null; + public IReflectionPatternRecorder PreviousRecorder; public struct ReflectionAccessPattern { diff --git a/test/Mono.Linker.Tests/TestCasesRunner/TestRunner.cs b/test/Mono.Linker.Tests/TestCasesRunner/TestRunner.cs index f6ce178d0..e9ead9713 100644 --- a/test/Mono.Linker.Tests/TestCasesRunner/TestRunner.cs +++ b/test/Mono.Linker.Tests/TestCasesRunner/TestRunner.cs @@ -145,7 +145,7 @@ namespace Mono.Linker.Tests.TestCasesRunner return customizations; } - private T GetResultOfTaskThatMakesNUnitAssertions<T> (Task<T> task) + private static T GetResultOfTaskThatMakesNUnitAssertions<T> (Task<T> task) { try { return task.Result; diff --git a/test/Mono.Linker.Tests/Tests/CecilVersionCheck.cs b/test/Mono.Linker.Tests/Tests/CecilVersionCheck.cs index 78fbbbb81..ca7e43d84 100644 --- a/test/Mono.Linker.Tests/Tests/CecilVersionCheck.cs +++ b/test/Mono.Linker.Tests/Tests/CecilVersionCheck.cs @@ -1,4 +1,3 @@ -using System; using System.Linq; using System.Reflection; using NUnit.Framework; diff --git a/test/Mono.Linker.Tests/Tests/DocumentationSignatureParserTests.cs b/test/Mono.Linker.Tests/Tests/DocumentationSignatureParserTests.cs index 4ea98ba18..19864eb37 100644 --- a/test/Mono.Linker.Tests/Tests/DocumentationSignatureParserTests.cs +++ b/test/Mono.Linker.Tests/Tests/DocumentationSignatureParserTests.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using System.Linq; using System.Text; using Mono.Cecil; -using Mono.Linker; using Mono.Linker.Tests.Cases.Expectations.Assertions; using Mono.Linker.Tests.TestCasesRunner; using NUnit.Framework; @@ -103,32 +102,32 @@ namespace Mono.Linker.Tests [ExpectGeneratedDocumentationSignature ("M:Mono.Linker.Tests.DocumentationSignatureParserTests.A.M(System.Int32[])")] [ExpectExactlyResolvedDocumentationSignature ("M:Mono.Linker.Tests.DocumentationSignatureParserTests.A.M(System.Int32[])")] - public void M (int[] a) + public static void M (int[] a) { } [ExpectExactlyResolvedDocumentationSignature ("M:Mono.Linker.Tests.DocumentationSignatureParserTests.A.M(System.Int32,System.Int32,System.Int32)~System.Int32")] - public int M (int a, int b, int c) + public static int M (int a, int b, int c) { return 0; } [ExpectGeneratedDocumentationSignature ("M:Mono.Linker.Tests.DocumentationSignatureParserTests.A.MRef(System.Int32@)")] [ExpectExactlyResolvedDocumentationSignature ("M:Mono.Linker.Tests.DocumentationSignatureParserTests.A.MRef(System.Int32@)")] - public void MRef (ref int a) + public static void MRef (ref int a) { } [ExpectGeneratedDocumentationSignature ("M:Mono.Linker.Tests.DocumentationSignatureParserTests.A.MOut(System.Int32@)")] [ExpectExactlyResolvedDocumentationSignature ("M:Mono.Linker.Tests.DocumentationSignatureParserTests.A.MOut(System.Int32@)")] - public void MOut (out int a) + public static void MOut (out int a) { a = 5; } [ExpectGeneratedDocumentationSignature ("M:Mono.Linker.Tests.DocumentationSignatureParserTests.A.MIn(System.Int32@)")] [ExpectExactlyResolvedDocumentationSignature ("M:Mono.Linker.Tests.DocumentationSignatureParserTests.A.MIn(System.Int32@)")] - public void MIn (in int a) + public static void MIn (in int a) { } @@ -137,7 +136,7 @@ namespace Mono.Linker.Tests [ExpectGeneratedDocumentationSignature ("M:Mono.Linker.Tests.DocumentationSignatureParserTests.A.MRefReturn")] [ExpectExactlyResolvedDocumentationSignature ("M:Mono.Linker.Tests.DocumentationSignatureParserTests.A.MRefReturn")] [ExpectExactlyResolvedDocumentationSignature ("M:Mono.Linker.Tests.DocumentationSignatureParserTests.A.MRefReturn~System.Int32@")] - public ref int MRefReturn () + public static ref int MRefReturn () { return ref i; } @@ -145,63 +144,63 @@ namespace Mono.Linker.Tests [ExpectGeneratedDocumentationSignature ("M:Mono.Linker.Tests.DocumentationSignatureParserTests.A.M")] [ExpectResolvedDocumentationSignature ("M:Mono.Linker.Tests.DocumentationSignatureParserTests.A.M")] // binds to both. [ExpectResolvedDocumentationSignature ("M:Mono.Linker.Tests.DocumentationSignatureParserTests.A.M()")] // binds to both. - public void M () + public static void M () { } [ExpectGeneratedDocumentationSignature ("M:Mono.Linker.Tests.DocumentationSignatureParserTests.A.M()")] [ExpectResolvedDocumentationSignature ("M:Mono.Linker.Tests.DocumentationSignatureParserTests.A.M")] [ExpectResolvedDocumentationSignature ("M:Mono.Linker.Tests.DocumentationSignatureParserTests.A.M()")] - public void M (__arglist) + public static void M (__arglist) { } [ExpectGeneratedDocumentationSignature ("M:Mono.Linker.Tests.DocumentationSignatureParserTests.A.M(System.Int32[][])")] [ExpectExactlyResolvedDocumentationSignature ("M:Mono.Linker.Tests.DocumentationSignatureParserTests.A.M(System.Int32[][])")] - public void M (int[][] a) + public static void M (int[][] a) { } [ExpectGeneratedDocumentationSignature ("M:Mono.Linker.Tests.DocumentationSignatureParserTests.A.M(System.Int32[][0:,0:,0:])")] [ExpectExactlyResolvedDocumentationSignature ("M:Mono.Linker.Tests.DocumentationSignatureParserTests.A.M(System.Int32[][0:,0:,0:])")] - public void M (int[,,][] a) + public static void M (int[,,][] a) { } [ExpectGeneratedDocumentationSignature ("M:Mono.Linker.Tests.DocumentationSignatureParserTests.A.M(System.Int32[0:,0:])")] [ExpectExactlyResolvedDocumentationSignature ("M:Mono.Linker.Tests.DocumentationSignatureParserTests.A.M(System.Int32[0:,0:])")] - public void M (int[,] a) + public static void M (int[,] a) { } [ExpectGeneratedDocumentationSignature ("M:Mono.Linker.Tests.DocumentationSignatureParserTests.A.M(System.Object)")] [ExpectExactlyResolvedDocumentationSignature ("M:Mono.Linker.Tests.DocumentationSignatureParserTests.A.M(System.Object)")] - public void M (dynamic d) + public static void M (dynamic d) { } [ExpectGeneratedDocumentationSignature ("M:Mono.Linker.Tests.DocumentationSignatureParserTests.A.M(System.Int32*)")] [ExpectExactlyResolvedDocumentationSignature ("M:Mono.Linker.Tests.DocumentationSignatureParserTests.A.M(System.Int32*)")] - public unsafe void M (int* a) + public static unsafe void M (int* a) { } [ExpectGeneratedDocumentationSignature ("M:Mono.Linker.Tests.DocumentationSignatureParserTests.A.M``1(Mono.Linker.Tests.DocumentationSignatureParserTests.S{Mono.Linker.Tests.DocumentationSignatureParserTests.G{Mono.Linker.Tests.DocumentationSignatureParserTests.A,``0}}**[0:,0:,0:][][][0:,0:]@)")] [ExpectExactlyResolvedDocumentationSignature ("M:Mono.Linker.Tests.DocumentationSignatureParserTests.A.M``1(Mono.Linker.Tests.DocumentationSignatureParserTests.S{Mono.Linker.Tests.DocumentationSignatureParserTests.G{Mono.Linker.Tests.DocumentationSignatureParserTests.A,``0}}**[0:,0:,0:][][][0:,0:]@)")] - public unsafe void M<T> (ref S<G<A, T>>**[,][][][,,] a) + public static unsafe void M<T> (ref S<G<A, T>>**[,][][][,,] a) { } [ExpectGeneratedDocumentationSignature ("M:Mono.Linker.Tests.DocumentationSignatureParserTests.A.M(System.Collections.Generic.List{System.Int32[]})")] [ExpectExactlyResolvedDocumentationSignature ("M:Mono.Linker.Tests.DocumentationSignatureParserTests.A.M(System.Collections.Generic.List{System.Int32[]})")] - public void M (List<int[]> a) + public static void M (List<int[]> a) { } [ExpectGeneratedDocumentationSignature ("M:Mono.Linker.Tests.DocumentationSignatureParserTests.A.M(System.Int32,)")] //[ExpectExactlyResolvedDocumentationSignature ("M:Mono.Linker.Tests.DocumentationSignatureParserTests.A.M(System.Int32,)")] // there's no way to reference this, since the parsing logic doesn't like it. - public void M (int abo, __arglist) + public static void M (int abo, __arglist) { } @@ -296,7 +295,7 @@ namespace Mono.Linker.Tests { [ExpectExactlyResolvedDocumentationSignature ("M:Mono.Linker.Tests.DocumentationSignatureParserTests.B.Method(Mono.Linker.Tests.DocumentationSignatureParserTests.G{Mono.Linker.Tests.DocumentationSignatureParserTests.A{Mono.Linker.Tests.DocumentationSignatureParserTests.B},System.Collections.Generic.List{Mono.Linker.Tests.DocumentationSignatureParserTests.A}})")] [ExpectGeneratedDocumentationSignature ("M:Mono.Linker.Tests.DocumentationSignatureParserTests.B.Method(Mono.Linker.Tests.DocumentationSignatureParserTests.G{Mono.Linker.Tests.DocumentationSignatureParserTests.A{Mono.Linker.Tests.DocumentationSignatureParserTests.B},System.Collections.Generic.List{Mono.Linker.Tests.DocumentationSignatureParserTests.A}})")] - public void Method (G<A<B>, List<A>> l) + public static void Method (G<A<B>, List<A>> l) { } } @@ -336,44 +335,44 @@ namespace Mono.Linker.Tests [ExpectGeneratedDocumentationSignature ("M:Mono.Linker.Tests.DocumentationSignatureParserTests.Method")] [ExpectExactlyResolvedDocumentationSignature ("M:Mono.Linker.Tests.DocumentationSignatureParserTests.Method")] - public void Method () + public static void Method () { } [ExpectGeneratedDocumentationSignature ("M:Mono.Linker.Tests.DocumentationSignatureParserTests.Method(System.Int32)")] [ExpectExactlyResolvedDocumentationSignature ("M:Mono.Linker.Tests.DocumentationSignatureParserTests.Method(System.Int32)")] - public void Method (int i) + public static void Method (int i) { } [ExpectGeneratedDocumentationSignature ("M:Mono.Linker.Tests.DocumentationSignatureParserTests.IntMethod")] [ExpectExactlyResolvedDocumentationSignature ("M:Mono.Linker.Tests.DocumentationSignatureParserTests.IntMethod")] - public int IntMethod () => 0; + public static int IntMethod () => 0; [ExpectGeneratedDocumentationSignature ("M:Mono.Linker.Tests.DocumentationSignatureParserTests.Method(Mono.Linker.Tests.DocumentationSignatureParserTests.G{Mono.Linker.Tests.DocumentationSignatureParserTests.A,Mono.Linker.Tests.DocumentationSignatureParserTests.A})")] [ExpectExactlyResolvedDocumentationSignature ("M:Mono.Linker.Tests.DocumentationSignatureParserTests.Method(Mono.Linker.Tests.DocumentationSignatureParserTests.G{Mono.Linker.Tests.DocumentationSignatureParserTests.A,Mono.Linker.Tests.DocumentationSignatureParserTests.A})")] - public void Method (G<A, A> g) + public static void Method (G<A, A> g) { } [ExpectGeneratedDocumentationSignature ("M:Mono.Linker.Tests.DocumentationSignatureParserTests.Method(Mono.Linker.Tests.DocumentationSignatureParserTests.G{Mono.Linker.Tests.DocumentationSignatureParserTests.A,Mono.Linker.Tests.DocumentationSignatureParserTests.A}.NG{Mono.Linker.Tests.DocumentationSignatureParserTests.A})")] [ExpectExactlyResolvedDocumentationSignature ("M:Mono.Linker.Tests.DocumentationSignatureParserTests.Method(Mono.Linker.Tests.DocumentationSignatureParserTests.G{Mono.Linker.Tests.DocumentationSignatureParserTests.A,Mono.Linker.Tests.DocumentationSignatureParserTests.A}.NG{Mono.Linker.Tests.DocumentationSignatureParserTests.A})")] - public void Method (G<A, A>.NG<A> g) + public static void Method (G<A, A>.NG<A> g) { } public class Invalid { [ExpectUnresolvedDocumentationSignature ("M:Mono.Linker.Tests.DocumentationSignatureParserTests.Invalid.NoReturnType~")] - public int NoReturnType () => 0; + public static int NoReturnType () => 0; [ExpectUnresolvedDocumentationSignature ("M:Mono.Linker.Tests.DocumentationSignatureParserTests.Invalid.NoParameters(,)")] - public void NoParameters (int a, int b) + public static void NoParameters (int a, int b) { } [ExpectUnresolvedDocumentationSignature ("M:Mono.Linker.Tests.DocumentationSignatureParserTests.Invalid.NoClosingParen(")] - public void NoClosingParen () { } + public static void NoClosingParen () { } [ExpectUnresolvedDocumentationSignature ("T:Mono.Linker.Tests.DocumentationSignatureParserTests.Invalid.Whitespace ")] [ExpectUnresolvedDocumentationSignature (" T:Mono.Linker.Tests.DocumentationSignatureParserTests.Invalid.Whitespace")] @@ -384,12 +383,12 @@ namespace Mono.Linker.Tests public class Whitespace { [ExpectUnresolvedDocumentationSignature ("M:Mono.Linker.Tests.DocumentationSignatureParserTests.Invalid.Whitespace.Method(System.Int32, System.Int32)")] - public void Method (int a, int b) + public static void Method (int a, int b) { } [ExpectUnresolvedDocumentationSignature ("M:Mono.Linker.Tests.DocumentationSignatureParserTests.Invalid.Whitespace.Method(Mono.Linker.Tests.DocumentationSignatureParserTests.Invalid.Generic{System.Int32, System.Int32})")] - public void Method (Generic<int, int> g) + public static void Method (Generic<int, int> g) { } } @@ -422,18 +421,18 @@ namespace Mono.Linker.Tests } [ExpectUnresolvedDocumentationSignature ("M:Mono.Linker.Tests.DocumentationSignatureParserTests.Invalid.MethodWithGenericInstantiation(Mono.Linker.Tests.DocumentationSignatureParserTests.Invalid.Generic`1)")] - public void MethodWithGenericInstantiation (Generic<A> g) + public static void MethodWithGenericInstantiation (Generic<A> g) { } [ExpectUnresolvedDocumentationSignature ("M:Mono.Linker.Tests.DocumentationSignatureParserTests.Invalid.Method(System.Int32[:,:])")] [ExpectUnresolvedDocumentationSignature ("M:Mono.Linker.Tests.DocumentationSignatureParserTests.Invalid.Method(System.Int32[0:,)")] - public void Method (int[,] a) + public static void Method (int[,] a) { } [ExpectUnresolvedDocumentationSignature ("M:Mono.Linker.Tests.DocumentationSignatureParserTests.Invalid.NonGenericMethod(``0)")] - public void NonGenericMethod (int i) + public static void NonGenericMethod (int i) { } @@ -445,7 +444,7 @@ namespace Mono.Linker.Tests } [ExpectUnresolvedDocumentationSignature ("M:Mono.Linker.Tests.DocumentationSignatureParserTests.Invalid.MethodMissingArgumentTypeName(System.)")] - public void MethodMissingArgumentTypeName (int i) + public static void MethodMissingArgumentTypeName (int i) { } @@ -453,7 +452,7 @@ namespace Mono.Linker.Tests public class NoType { [ExpectUnresolvedDocumentationSignature ("M:Mono.Linker.Tests.DocumentationSignatureParserTests.Invalid..Method")] - public void Method () + public static void Method () { } } @@ -466,12 +465,12 @@ namespace Mono.Linker.Tests } [ExpectUnresolvedDocumentationSignature ("T:Mono.Linker.Tests.DocumentationSignatureParserTests.Invalid.NoParameterType()")] - public void NoParameterType (int i) + public static void NoParameterType (int i) { } [ExpectUnresolvedDocumentationSignature ("T:Mono.Linker.Tests.DocumentationSignatureParserTests.Invalid.NoParameterType(Mono.Linker.Tests.DocumentationSignatureParserTests.Invalid.Generic{})")] - public void NoGenericParameterType (Generic<A> g) + public static void NoGenericParameterType (Generic<A> g) { } @@ -503,12 +502,12 @@ namespace Mono.Linker.Tests } [ExpectExactlyResolvedDocumentationSignature ("M:Mono.Linker.Tests.DocumentationSignatureParserTests.Invalid.NoClosingParenWithParameters(System.Int32")] - public void NoClosingParenWithParameters (int a) + public static void NoClosingParenWithParameters (int a) { } [ExpectExactlyResolvedDocumentationSignature ("M:Mono.Linker.Tests.DocumentationSignatureParserTests.Invalid.NoClosingBrace(Mono.Linker.Tests.DocumentationSignatureParserTests.Invalid.Generic{Mono.Linker.Tests.DocumentationSignatureParserTests.A)")] - public void NoClosingBrace (Generic<A> g) + public static void NoClosingBrace (Generic<A> g) { } diff --git a/test/Mono.Linker.Tests/Tests/GetDisplayNameTests.cs b/test/Mono.Linker.Tests/Tests/GetDisplayNameTests.cs index b025aae92..2b3075850 100644 --- a/test/Mono.Linker.Tests/Tests/GetDisplayNameTests.cs +++ b/test/Mono.Linker.Tests/Tests/GetDisplayNameTests.cs @@ -52,53 +52,53 @@ namespace Mono.Linker.Tests } [DisplayName ("Mono.Linker.Tests.GetDisplayNameTests.A.SingleDimensionalArrayTypeParameter(Int32[])")] - public void SingleDimensionalArrayTypeParameter (int[] p) + public static void SingleDimensionalArrayTypeParameter (int[] p) { } [DisplayName ("Mono.Linker.Tests.GetDisplayNameTests.A.MultiDimensionalArrayTypeParameter(Int32[,])")] - public void MultiDimensionalArrayTypeParameter (int[,] p) + public static void MultiDimensionalArrayTypeParameter (int[,] p) { } [DisplayName ("Mono.Linker.Tests.GetDisplayNameTests.A.JaggedArrayTypeParameter(Int32[][,])")] - public void JaggedArrayTypeParameter (int[][,] p) + public static void JaggedArrayTypeParameter (int[][,] p) { } [DisplayName ("Mono.Linker.Tests.GetDisplayNameTests.A.JaggedArrayTypeParameter(Int32[,][])")] - public void JaggedArrayTypeParameter (int[,][] p) + public static void JaggedArrayTypeParameter (int[,][] p) { } [DisplayName ("Mono.Linker.Tests.GetDisplayNameTests.A.JaggedArrayTypeParameter(Int32[,][,,][,,,])")] - public void JaggedArrayTypeParameter (int[,][,,][,,,] p) + public static void JaggedArrayTypeParameter (int[,][,,][,,,] p) { } // PointerType [DisplayName ("Mono.Linker.Tests.GetDisplayNameTests.A.CommonPointerPointerTypeParameter(Int32*)")] - public unsafe void CommonPointerPointerTypeParameter (int* p) + public static unsafe void CommonPointerPointerTypeParameter (int* p) { } [DisplayName ("Mono.Linker.Tests.GetDisplayNameTests.A.PointerToPointerPointerTypeParameter(Int32**)")] - public unsafe void PointerToPointerPointerTypeParameter (int** p) + public static unsafe void PointerToPointerPointerTypeParameter (int** p) { } [DisplayName ("Mono.Linker.Tests.GetDisplayNameTests.A.PointerToArrayPointerTypeParameter(Int32*[,,,])")] - public unsafe void PointerToArrayPointerTypeParameter (int*[,,,] p) + public static unsafe void PointerToArrayPointerTypeParameter (int*[,,,] p) { } [DisplayName ("Mono.Linker.Tests.GetDisplayNameTests.A.PointerToArrayPointerTypeParameter(Int32*[,][,,])")] - public unsafe void PointerToArrayPointerTypeParameter (int*[,][,,] p) + public static unsafe void PointerToArrayPointerTypeParameter (int*[,][,,] p) { } [DisplayName ("Mono.Linker.Tests.GetDisplayNameTests.A.PointerTypeToUnknownTypeParameter(Void*)")] - public unsafe void PointerTypeToUnknownTypeParameter (void* p) + public static unsafe void PointerTypeToUnknownTypeParameter (void* p) { } } @@ -167,7 +167,7 @@ namespace Mono.Linker.Tests } [DisplayName ("Mono.Linker.Tests.GetDisplayNameTests.MethodWithNestedGenericTypeArgumentsNoArgumentsOnLeaf(GetDisplayNameTests.GenericClassOneParameter<Int32>.B)")] - public void MethodWithNestedGenericTypeArgumentsNoArgumentsOnLeaf (GenericClassOneParameter<int>.B p) { } + public static void MethodWithNestedGenericTypeArgumentsNoArgumentsOnLeaf (GenericClassOneParameter<int>.B p) { } [DisplayName ("Mono.Linker.Tests.GetDisplayNameTests.GenericClassMultipleParameters<T,S>")] public class GenericClassMultipleParameters<T, S> @@ -179,24 +179,24 @@ namespace Mono.Linker.Tests } [DisplayName ("Mono.Linker.Tests.GetDisplayNameTests.MethodWithGenericTypeArgument(IList<GetDisplayNameTests.GenericClassOneParameter<Byte*[]>>)")] - public void MethodWithGenericTypeArgument (IList<GenericClassOneParameter<byte*[]>> p) + public static void MethodWithGenericTypeArgument (IList<GenericClassOneParameter<byte*[]>> p) { } [DisplayName ("Mono.Linker.Tests.GetDisplayNameTests.MethodWithGenericTypeArguments(GetDisplayNameTests.GenericClassMultipleParameters<Char*[],Int32[,][]>)")] - public void MethodWithGenericTypeArguments (GenericClassMultipleParameters<char*[], int[,][]> p) + public static void MethodWithGenericTypeArguments (GenericClassMultipleParameters<char*[], int[,][]> p) { } [DisplayName ("Mono.Linker.Tests.GetDisplayNameTests.MethodWithNestedGenericTypeArguments" + "(GetDisplayNameTests.GenericClassMultipleParameters<Char*[],Int32[,][]>.NestedGenericClassMultipleParameters<Char*[],Int32[,][]>)")] - public void MethodWithNestedGenericTypeArguments (GenericClassMultipleParameters<char*[], int[,][]>.NestedGenericClassMultipleParameters<char*[], int[,][]> p) + public static void MethodWithNestedGenericTypeArguments (GenericClassMultipleParameters<char*[], int[,][]>.NestedGenericClassMultipleParameters<char*[], int[,][]> p) { } [DisplayName ("Mono.Linker.Tests.GetDisplayNameTests.MethodWithPartiallyInstantiatedNestedGenericTypeArguments<MethodT,MethodV>" + "(GetDisplayNameTests.GenericClassMultipleParameters<MethodT,String>.NestedGenericClassMultipleParameters<Int32,MethodV>)")] - public void MethodWithPartiallyInstantiatedNestedGenericTypeArguments<MethodT, MethodV> ( + public static void MethodWithPartiallyInstantiatedNestedGenericTypeArguments<MethodT, MethodV> ( GenericClassMultipleParameters<MethodT, string>.NestedGenericClassMultipleParameters<int, MethodV> p) { } @@ -219,7 +219,7 @@ public class GetDisplayNameTestsGlobalScope public class TypeInGlobalScope { [DisplayName ("GetDisplayNameTestsGlobalScope.TypeInGlobalScope.Method()")] - public void Method () + public static void Method () { } } diff --git a/test/Mono.Linker.Tests/Tests/ParseResponseFileLinesTests.cs b/test/Mono.Linker.Tests/Tests/ParseResponseFileLinesTests.cs index e97960359..df06c3ff0 100644 --- a/test/Mono.Linker.Tests/Tests/ParseResponseFileLinesTests.cs +++ b/test/Mono.Linker.Tests/Tests/ParseResponseFileLinesTests.cs @@ -106,7 +106,7 @@ b""", new string[] { @"a b" }); } - private void TestParseResponseFileLines (string v1, string[] v2) + private static void TestParseResponseFileLines (string v1, string[] v2) { var result = new Queue<string> (); using (var reader = new StringReader (v1)) |