Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/linker.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAndy Gocke <angocke@microsoft.com>2021-10-27 00:40:46 +0300
committerAndy Gocke <angocke@microsoft.com>2021-10-27 00:40:46 +0300
commit7603d9fc71d32457011c975a9f1a0817db1f2e6d (patch)
treeddb7d1c36c4548304cee9584b50cce8d300d3d48 /test
parentcf525c5d5e5dd5ce098962b21adeea22b687ff1d (diff)
parent7cfb14ecdf63b3a6819a89d5c05c2dd84232b246 (diff)
Merge remote-tracking branch 'upstream/main' into release/6.0.2xx
Diffstat (limited to 'test')
-rw-r--r--test/ILLink.RoslynAnalyzer.Tests/LinkerTestCases.cs7
-rw-r--r--test/ILLink.RoslynAnalyzer.Tests/RequiresAssemblyFilesAnalyzerTests.cs4
-rw-r--r--test/ILLink.RoslynAnalyzer.Tests/RequiresUnreferencedCodeAnalyzerTests.cs4
-rw-r--r--test/ILLink.RoslynAnalyzer.Tests/TestCaseCompilation.cs99
-rw-r--r--test/ILLink.RoslynAnalyzer.Tests/TestCaseUtils.cs17
-rw-r--r--test/ILLink.RoslynAnalyzer.Tests/TestChecker.cs33
-rw-r--r--test/ILLink.RoslynAnalyzer.Tests/Verifiers/CSharpAnalyzerVerifier`1.cs81
-rw-r--r--test/ILLink.Tasks.Tests/ILLink.Tasks.Tests.cs2
-rw-r--r--test/ILLink.Tasks.Tests/Mock.cs14
-rw-r--r--test/Mono.Linker.Tests.Cases.Expectations/Assertions/ProducedBy.cs5
-rw-r--r--test/Mono.Linker.Tests.Cases/Interop/PInvoke/Warnings/ComPInvokeWarning.cs22
-rw-r--r--test/Mono.Linker.Tests/TestCasesRunner/AssemblyChecker.cs18
12 files changed, 200 insertions, 106 deletions
diff --git a/test/ILLink.RoslynAnalyzer.Tests/LinkerTestCases.cs b/test/ILLink.RoslynAnalyzer.Tests/LinkerTestCases.cs
index a52400284..37fca09bd 100644
--- a/test/ILLink.RoslynAnalyzer.Tests/LinkerTestCases.cs
+++ b/test/ILLink.RoslynAnalyzer.Tests/LinkerTestCases.cs
@@ -27,5 +27,12 @@ namespace ILLink.RoslynAnalyzer.Tests
RunTest<RequiresUnreferencedCodeAnalyzer> (m, attrs, UseMSBuildProperties (MSBuildPropertyOptionNames.EnableTrimAnalyzer));
}
+
+ [Theory]
+ [MemberData (nameof (TestCaseUtils.GetTestData), parameters: nameof (Interop))]
+ public void Interop (string testName, MethodDeclarationSyntax m, List<AttributeSyntax> attrs)
+ {
+ RunTest<COMAnalyzer> (m, attrs, UseMSBuildProperties (MSBuildPropertyOptionNames.EnableTrimAnalyzer));
+ }
}
}
diff --git a/test/ILLink.RoslynAnalyzer.Tests/RequiresAssemblyFilesAnalyzerTests.cs b/test/ILLink.RoslynAnalyzer.Tests/RequiresAssemblyFilesAnalyzerTests.cs
index 10da5a5d9..a4bdc5be5 100644
--- a/test/ILLink.RoslynAnalyzer.Tests/RequiresAssemblyFilesAnalyzerTests.cs
+++ b/test/ILLink.RoslynAnalyzer.Tests/RequiresAssemblyFilesAnalyzerTests.cs
@@ -1147,7 +1147,7 @@ class AnotherImplementation : IRAF
}
}
";
- var compilation = (await CSharpAnalyzerVerifier<RequiresAssemblyFilesAnalyzer>.GetCompilation (references)).EmitToImageReference ();
+ var compilation = (await TestCaseCompilation.GetCompilation (references)).EmitToImageReference ();
await VerifyRequiresAssemblyFilesAnalyzer (src, additionalReferences: new[] { compilation },
// (4,14): warning IL3003: Interface member 'IRAF.Method()' with 'RequiresAssemblyFilesAttribute' has an implementation member 'Implementation.Method()' without 'RequiresAssemblyFilesAttribute'. Attributes must match across all interface implementations or overrides.
@@ -1219,7 +1219,7 @@ class AnotherImplementation : IRAF
}
}
";
- var compilation = (await CSharpAnalyzerVerifier<RequiresAssemblyFilesAnalyzer>.GetCompilation (references)).EmitToImageReference ();
+ var compilation = (await TestCaseCompilation.GetCompilation (references)).EmitToImageReference ();
await VerifyRequiresAssemblyFilesAnalyzer (src, additionalReferences: new[] { compilation },
// (7,14): warning IL3003: Member 'Implementation.Method()' with 'RequiresAssemblyFilesAttribute' implements interface member 'IRAF.Method()' without 'RequiresAssemblyFilesAttribute'. Attributes must match across all interface implementations or overrides.
diff --git a/test/ILLink.RoslynAnalyzer.Tests/RequiresUnreferencedCodeAnalyzerTests.cs b/test/ILLink.RoslynAnalyzer.Tests/RequiresUnreferencedCodeAnalyzerTests.cs
index 74b21fc7e..9cb7d8995 100644
--- a/test/ILLink.RoslynAnalyzer.Tests/RequiresUnreferencedCodeAnalyzerTests.cs
+++ b/test/ILLink.RoslynAnalyzer.Tests/RequiresUnreferencedCodeAnalyzerTests.cs
@@ -795,7 +795,7 @@ class AnotherImplementation : IRAF
}
}
";
- var compilation = (await CSharpAnalyzerVerifier<RequiresUnreferencedCodeAnalyzer>.GetCompilation (references)).EmitToImageReference ();
+ var compilation = (await TestCaseCompilation.GetCompilation (references)).EmitToImageReference ();
await VerifyRequiresUnreferencedCodeAnalyzer (src, additionalReferences: new[] { compilation },
// (4,14): warning IL2046: Interface member 'IRAF.Method()' with 'RequiresUnreferencedCodeAttribute' has an implementation member 'Implementation.Method()' without 'RequiresUnreferencedCodeAttribute'. Attributes must match across all interface implementations or overrides.
@@ -847,7 +847,7 @@ class AnotherImplementation : IRAF
}
}
";
- var compilation = (await CSharpAnalyzerVerifier<RequiresUnreferencedCodeAnalyzer>.GetCompilation (references)).EmitToImageReference ();
+ var compilation = (await TestCaseCompilation.GetCompilation (references)).EmitToImageReference ();
await VerifyRequiresUnreferencedCodeAnalyzer (src, additionalReferences: new[] { compilation },
// (7,14): warning IL2046: Member 'Implementation.Method()' with 'RequiresUnreferencedCodeAttribute' implements interface member 'IRAF.Method()' without 'RequiresUnreferencedCodeAttribute'. Attributes must match across all interface implementations or overrides.
diff --git a/test/ILLink.RoslynAnalyzer.Tests/TestCaseCompilation.cs b/test/ILLink.RoslynAnalyzer.Tests/TestCaseCompilation.cs
new file mode 100644
index 000000000..01acca13b
--- /dev/null
+++ b/test/ILLink.RoslynAnalyzer.Tests/TestCaseCompilation.cs
@@ -0,0 +1,99 @@
+// 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.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Microsoft.CodeAnalysis;
+using Microsoft.CodeAnalysis.CSharp;
+using Microsoft.CodeAnalysis.Diagnostics;
+
+namespace ILLink.RoslynAnalyzer.Tests
+{
+ internal class TestCaseCompilation
+ {
+ private static readonly ImmutableArray<DiagnosticAnalyzer> SupportedDiagnosticAnalyzers =
+ ImmutableArray.Create<DiagnosticAnalyzer> (
+ new COMAnalyzer (),
+ new RequiresAssemblyFilesAnalyzer (),
+ new RequiresUnreferencedCodeAnalyzer ());
+
+ public static Task<(CompilationWithAnalyzers Compilation, SemanticModel SemanticModel)> CreateCompilation (
+ string src,
+ (string, string)[]? globalAnalyzerOptions = null,
+ IEnumerable<MetadataReference>? additionalReferences = null,
+ IEnumerable<SyntaxTree>? additionalSources = null)
+ => CreateCompilation (CSharpSyntaxTree.ParseText (src), globalAnalyzerOptions, additionalReferences, additionalSources);
+
+ public static async Task<(CompilationWithAnalyzers Compilation, SemanticModel SemanticModel)> CreateCompilation (
+ SyntaxTree src,
+ (string, string)[]? globalAnalyzerOptions = null,
+ IEnumerable<MetadataReference>? additionalReferences = null,
+ IEnumerable<SyntaxTree>? additionalSources = null)
+ {
+ var mdRef = MetadataReference.CreateFromFile (typeof (Mono.Linker.Tests.Cases.Expectations.Metadata.BaseMetadataAttribute).Assembly.Location);
+ additionalReferences ??= Array.Empty<MetadataReference> ();
+ var sources = new List<SyntaxTree> () { src };
+ sources.AddRange (additionalSources ?? Array.Empty<SyntaxTree> ());
+ var comp = CSharpCompilation.Create (
+ assemblyName: Guid.NewGuid ().ToString ("N"),
+ syntaxTrees: sources,
+ references: (await TestCaseUtils.GetNet6References ()).Add (mdRef).AddRange (additionalReferences),
+ new CSharpCompilationOptions (OutputKind.DynamicallyLinkedLibrary));
+
+ var analyzerOptions = new AnalyzerOptions (
+ ImmutableArray<AdditionalText>.Empty,
+ new SimpleAnalyzerOptions (globalAnalyzerOptions));
+
+ var compWithAnalyzerOptions = new CompilationWithAnalyzersOptions (
+ analyzerOptions,
+ (_1, _2, _3) => { },
+ concurrentAnalysis: true,
+ logAnalyzerExecutionTime: false);
+
+ return (new CompilationWithAnalyzers (comp, SupportedDiagnosticAnalyzers, compWithAnalyzerOptions), comp.GetSemanticModel (src));
+ }
+
+ public static async Task<Compilation> GetCompilation (string source, IEnumerable<MetadataReference>? additionalReferences = null, IEnumerable<SyntaxTree>? additionalSources = null)
+ => (await CreateCompilation (source, additionalReferences: additionalReferences ?? Array.Empty<MetadataReference> ())).Compilation.Compilation;
+
+ class SimpleAnalyzerOptions : AnalyzerConfigOptionsProvider
+ {
+ public SimpleAnalyzerOptions ((string, string)[]? globalOptions)
+ {
+ globalOptions ??= Array.Empty<(string, string)> ();
+ GlobalOptions = new SimpleAnalyzerConfigOptions (ImmutableDictionary.CreateRange (
+ StringComparer.OrdinalIgnoreCase,
+ globalOptions.Select (x => new KeyValuePair<string, string> (x.Item1, x.Item2))));
+ }
+
+ public override AnalyzerConfigOptions GlobalOptions { get; }
+
+ public override AnalyzerConfigOptions GetOptions (SyntaxTree tree)
+ => SimpleAnalyzerConfigOptions.Empty;
+
+ public override AnalyzerConfigOptions GetOptions (AdditionalText textFile)
+ => SimpleAnalyzerConfigOptions.Empty;
+
+ class SimpleAnalyzerConfigOptions : AnalyzerConfigOptions
+ {
+ public static readonly SimpleAnalyzerConfigOptions Empty = new SimpleAnalyzerConfigOptions (ImmutableDictionary<string, string>.Empty);
+
+ private readonly ImmutableDictionary<string, string> _dict;
+ public SimpleAnalyzerConfigOptions (ImmutableDictionary<string, string> dict)
+ {
+ _dict = dict;
+ }
+
+ // Suppress warning about missing nullable attributes
+#pragma warning disable 8765
+ public override bool TryGetValue (string key, out string? value)
+ => _dict.TryGetValue (key, out value);
+#pragma warning restore 8765
+ }
+ }
+ }
+}
diff --git a/test/ILLink.RoslynAnalyzer.Tests/TestCaseUtils.cs b/test/ILLink.RoslynAnalyzer.Tests/TestCaseUtils.cs
index 7e5739cad..fb0c2aef0 100644
--- a/test/ILLink.RoslynAnalyzer.Tests/TestCaseUtils.cs
+++ b/test/ILLink.RoslynAnalyzer.Tests/TestCaseUtils.cs
@@ -18,6 +18,8 @@ namespace ILLink.RoslynAnalyzer.Tests
{
public abstract class TestCaseUtils
{
+ private static readonly string MonoLinkerTestsCases = "Mono.Linker.Tests.Cases";
+
public static readonly ReferenceAssemblies Net6PreviewAssemblies =
new ReferenceAssemblies (
"net6.0",
@@ -73,9 +75,8 @@ namespace ILLink.RoslynAnalyzer.Tests
var testDependenciesSource = GetTestDependencies (testSyntaxTree)
.Select (testDependency => CSharpSyntaxTree.ParseText (File.ReadAllText (testDependency)));
- var test = new TestChecker (m, CSharpAnalyzerVerifier<TAnalyzer>
- .CreateCompilation (testSyntaxTree, MSBuildProperties, additionalSources: testDependenciesSource).Result);
-
+ var compilation = TestCaseCompilation.CreateCompilation (testSyntaxTree, MSBuildProperties, additionalSources: testDependenciesSource);
+ var test = new TestChecker (m, compilation.Result);
test.ValidateAttributes (attrs);
}
@@ -86,12 +87,16 @@ namespace ILLink.RoslynAnalyzer.Tests
var builder = ImmutableDictionary.CreateBuilder<string, List<string>> ();
foreach (var file in GetTestFiles ()) {
- var dirName = Path.GetFileName (Path.GetDirectoryName (file))!;
- if (builder.TryGetValue (dirName, out var sources)) {
+ var directory = Path.GetDirectoryName (file);
+ while (Path.GetFileName (Path.GetDirectoryName (directory)) != MonoLinkerTestsCases)
+ directory = Path.GetDirectoryName (directory);
+
+ var parentDirectory = Path.GetFileName (directory);
+ if (builder.TryGetValue (parentDirectory!, out var sources)) {
sources.Add (file);
} else {
sources = new List<string> () { file };
- builder[dirName] = sources;
+ builder[parentDirectory!] = sources;
}
}
diff --git a/test/ILLink.RoslynAnalyzer.Tests/TestChecker.cs b/test/ILLink.RoslynAnalyzer.Tests/TestChecker.cs
index ecf91c376..ce88b0045 100644
--- a/test/ILLink.RoslynAnalyzer.Tests/TestChecker.cs
+++ b/test/ILLink.RoslynAnalyzer.Tests/TestChecker.cs
@@ -11,6 +11,7 @@ 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;
namespace ILLink.RoslynAnalyzer.Tests
@@ -67,11 +68,11 @@ namespace ILLink.RoslynAnalyzer.Tests
switch (attribute.Name.ToString ()) {
case "ExpectedWarning":
var args = TestCaseUtils.GetAttributeArguments (attribute);
- if (args.TryGetValue ("ProducedBy", out var producedBy) &&
- producedBy is MemberAccessExpressionSyntax memberAccessExpression &&
- memberAccessExpression.Name is IdentifierNameSyntax identifierNameSyntax &&
- identifierNameSyntax.Identifier.ValueText == "Trimmer")
- return false;
+ if (args.TryGetValue ("ProducedBy", out var producedBy)) {
+ // Skip if this warning is not expected to be produced by any of the analyzers that we are currently testing.
+ return GetProducedBy (producedBy).HasFlag (ProducedBy.Analyzer);
+ }
+
return true;
case "LogContains":
case "UnrecognizedReflectionAccessPattern":
@@ -79,6 +80,28 @@ namespace ILLink.RoslynAnalyzer.Tests
default:
return false;
}
+
+ static ProducedBy GetProducedBy (ExpressionSyntax expression)
+ {
+ var producedBy = (ProducedBy) 0x0;
+ switch (expression) {
+ case BinaryExpressionSyntax binaryExpressionSyntax:
+ Enum.TryParse<ProducedBy> ((binaryExpressionSyntax.Left as MemberAccessExpressionSyntax)!.Name.Identifier.ValueText, out var besProducedBy);
+ producedBy |= besProducedBy;
+ producedBy |= GetProducedBy (binaryExpressionSyntax.Right);
+ break;
+
+ case MemberAccessExpressionSyntax memberAccessExpressionSyntax:
+ Enum.TryParse<ProducedBy> (memberAccessExpressionSyntax.Name.Identifier.ValueText, out var maeProducedBy);
+ producedBy |= maeProducedBy;
+ break;
+
+ default:
+ break;
+ }
+
+ return producedBy;
+ }
}
bool TryValidateExpectedDiagnostic (AttributeSyntax attribute, List<Diagnostic> diagnostics, [NotNullWhen (true)] out int? matchIndex, [NotNullWhen (false)] out string? missingDiagnosticMessage)
diff --git a/test/ILLink.RoslynAnalyzer.Tests/Verifiers/CSharpAnalyzerVerifier`1.cs b/test/ILLink.RoslynAnalyzer.Tests/Verifiers/CSharpAnalyzerVerifier`1.cs
index a503bbe70..5afc179b8 100644
--- a/test/ILLink.RoslynAnalyzer.Tests/Verifiers/CSharpAnalyzerVerifier`1.cs
+++ b/test/ILLink.RoslynAnalyzer.Tests/Verifiers/CSharpAnalyzerVerifier`1.cs
@@ -34,51 +34,10 @@ namespace ILLink.RoslynAnalyzer.Tests
public static DiagnosticResult Diagnostic (DiagnosticDescriptor descriptor)
=> CSharpAnalyzerVerifier<TAnalyzer, XUnitVerifier>.Diagnostic (descriptor);
- public static Task<(CompilationWithAnalyzers Compilation, SemanticModel SemanticModel)> CreateCompilation (
- string src,
- (string, string)[]? globalAnalyzerOptions = null,
- IEnumerable<MetadataReference>? additionalReferences = null,
- IEnumerable<SyntaxTree>? additionalSources = null)
- => CreateCompilation (CSharpSyntaxTree.ParseText (src), globalAnalyzerOptions, additionalReferences, additionalSources);
-
- public static async Task<Compilation> GetCompilation (string source, IEnumerable<MetadataReference>? additionalReferences = null, IEnumerable<SyntaxTree>? additionalSources = null)
- => (await CSharpAnalyzerVerifier<RequiresAssemblyFilesAnalyzer>.CreateCompilation (source, additionalReferences: additionalReferences ?? Array.Empty<MetadataReference> ())).Compilation.Compilation;
-
- public static async Task<(CompilationWithAnalyzers Compilation, SemanticModel SemanticModel)> CreateCompilation (
- SyntaxTree src,
- (string, string)[]? globalAnalyzerOptions = null,
- IEnumerable<MetadataReference>? additionalReferences = null,
- IEnumerable<SyntaxTree>? additionalSources = null)
- {
- var mdRef = MetadataReference.CreateFromFile (typeof (Mono.Linker.Tests.Cases.Expectations.Metadata.BaseMetadataAttribute).Assembly.Location);
- additionalReferences ??= Array.Empty<MetadataReference> ();
- var sources = new List<SyntaxTree> () { src };
- sources.AddRange (additionalSources ?? Array.Empty<SyntaxTree> ());
- var comp = CSharpCompilation.Create (
- assemblyName: Guid.NewGuid ().ToString ("N"),
- syntaxTrees: sources,
- references: (await TestCaseUtils.GetNet6References ()).Add (mdRef).AddRange (additionalReferences),
- new CSharpCompilationOptions (OutputKind.DynamicallyLinkedLibrary));
-
- var analyzerOptions = new AnalyzerOptions (
- ImmutableArray<AdditionalText>.Empty,
- new SimpleAnalyzerOptions (globalAnalyzerOptions));
-
- var compWithAnalyzerOptions = new CompilationWithAnalyzersOptions (
- analyzerOptions,
- (_1, _2, _3) => { },
- concurrentAnalysis: true,
- logAnalyzerExecutionTime: false);
-
- var analyzers = ImmutableArray.Create<DiagnosticAnalyzer> (new TAnalyzer ());
- return (new CompilationWithAnalyzers (comp, analyzers, compWithAnalyzerOptions), comp.GetSemanticModel (src));
- }
-
/// <inheritdoc cref="AnalyzerVerifier{TAnalyzer, TTest, TVerifier}.VerifyAnalyzerAsync(string, DiagnosticResult[])"/>
public static async Task VerifyAnalyzerAsync (string src, (string, string)[]? analyzerOptions = null, IEnumerable<MetadataReference>? additionalReferences = null, params DiagnosticResult[] expected)
{
- var diags = await (await CreateCompilation (src, analyzerOptions, additionalReferences)).Compilation.GetAllDiagnosticsAsync ();
-
+ var diags = await (await TestCaseCompilation.CreateCompilation (src, analyzerOptions, additionalReferences)).Compilation.GetAllDiagnosticsAsync ();
var analyzers = ImmutableArray.Create<DiagnosticAnalyzer> (new TAnalyzer ());
VerifyDiagnosticResults (diags, analyzers, expected, DefaultVerifier);
}
@@ -673,44 +632,6 @@ namespace ILLink.RoslynAnalyzer.Tests
return (IReadOnlyList<object?>?) diagnostic.GetType ().GetProperty ("Arguments", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)?.GetValue (diagnostic)
?? Array.Empty<object> ();
}
-
- class SimpleAnalyzerOptions : AnalyzerConfigOptionsProvider
- {
- public SimpleAnalyzerOptions ((string, string)[]? globalOptions)
- {
- globalOptions ??= Array.Empty<(string, string)> ();
- GlobalOptions = new SimpleAnalyzerConfigOptions (ImmutableDictionary.CreateRange (
- StringComparer.OrdinalIgnoreCase,
- globalOptions.Select (x => new KeyValuePair<string, string> (x.Item1, x.Item2))));
- }
-
- public override AnalyzerConfigOptions GlobalOptions { get; }
-
- public override AnalyzerConfigOptions GetOptions (SyntaxTree tree)
- => SimpleAnalyzerConfigOptions.Empty;
-
- public override AnalyzerConfigOptions GetOptions (AdditionalText textFile)
- => SimpleAnalyzerConfigOptions.Empty;
-
- class SimpleAnalyzerConfigOptions : AnalyzerConfigOptions
- {
- public static readonly SimpleAnalyzerConfigOptions Empty = new SimpleAnalyzerConfigOptions (ImmutableDictionary<string, string>.Empty);
-
- private readonly ImmutableDictionary<string, string> _dict;
- public SimpleAnalyzerConfigOptions (ImmutableDictionary<string, string> dict)
- {
- _dict = dict;
- }
-
- // Suppress warning about missing nullable attributes
-#pragma warning disable 8765
- public override bool TryGetValue (string key, out string? value)
- => _dict.TryGetValue (key, out value);
-#pragma warning restore 8765
- }
- }
-
-
}
internal static class IEnumerableExtensions
diff --git a/test/ILLink.Tasks.Tests/ILLink.Tasks.Tests.cs b/test/ILLink.Tasks.Tests/ILLink.Tasks.Tests.cs
index dbf9bb427..216dec205 100644
--- a/test/ILLink.Tasks.Tests/ILLink.Tasks.Tests.cs
+++ b/test/ILLink.Tasks.Tests/ILLink.Tasks.Tests.cs
@@ -382,7 +382,7 @@ namespace ILLink.Tasks.Tests
}
}
}
-#nullable disable
+#nullable restore
public static IEnumerable<object[]> CustomDataCases => new List<object[]> {
new object [] {
diff --git a/test/ILLink.Tasks.Tests/Mock.cs b/test/ILLink.Tasks.Tests/Mock.cs
index 681834087..dba28887b 100644
--- a/test/ILLink.Tasks.Tests/Mock.cs
+++ b/test/ILLink.Tasks.Tests/Mock.cs
@@ -101,13 +101,13 @@ namespace ILLink.Tasks.Tests
SetupContext (Logger);
}
- public LinkContext Context => context;
+ public new LinkContext Context => base.Context;
public CustomLogger Logger { get; private set; }
public IEnumerable<string> GetRootAssemblies ()
{
- foreach (var step in context.Pipeline.GetSteps ()) {
+ foreach (var step in Context.Pipeline.GetSteps ()) {
if (!(step is RootAssemblyInput))
continue;
@@ -121,7 +121,7 @@ namespace ILLink.Tasks.Tests
public IEnumerable<string> GetRootDescriptors ()
{
- foreach (var step in context.Pipeline.GetSteps ()) {
+ foreach (var step in Context.Pipeline.GetSteps ()) {
if (!(step is ResolveFromXmlStep))
continue;
@@ -133,7 +133,7 @@ namespace ILLink.Tasks.Tests
public IEnumerable<string> GetReferenceAssemblies ()
{
- return (IEnumerable<string>) typeof (AssemblyResolver).GetField ("_references", BindingFlags.NonPublic | BindingFlags.Instance).GetValue (context.Resolver);
+ return (IEnumerable<string>) typeof (AssemblyResolver).GetField ("_references", BindingFlags.NonPublic | BindingFlags.Instance).GetValue (Context.Resolver);
}
protected override void AddResolveFromXmlStep (Pipeline pipeline, string file)
@@ -150,7 +150,7 @@ namespace ILLink.Tasks.Tests
public IEnumerable<IDependencyRecorder> GetDependencyRecorders ()
{
- return (IEnumerable<IDependencyRecorder>) typeof (Tracer).GetField ("recorders", BindingFlags.NonPublic | BindingFlags.Instance).GetValue (context.Tracer);
+ return (IEnumerable<IDependencyRecorder>) typeof (Tracer).GetField ("recorders", BindingFlags.NonPublic | BindingFlags.Instance).GetValue (Context.Tracer);
}
public new bool GetOptimizationName (string optimization, out CodeOptimizations codeOptimizations)
@@ -160,13 +160,13 @@ namespace ILLink.Tasks.Tests
public CodeOptimizations GetDefaultOptimizations ()
{
- return context.Optimizations.Global;
+ return Context.Optimizations.Global;
}
public Dictionary<string, string> GetCustomData ()
{
var field = typeof (LinkContext).GetField ("_parameters", BindingFlags.NonPublic | BindingFlags.Instance);
- return (Dictionary<string, string>) field.GetValue (this.context);
+ return (Dictionary<string, string>) field.GetValue (Context);
}
protected override List<BaseStep> CreateDefaultResolvers ()
diff --git a/test/Mono.Linker.Tests.Cases.Expectations/Assertions/ProducedBy.cs b/test/Mono.Linker.Tests.Cases.Expectations/Assertions/ProducedBy.cs
index b18578c3d..fe7d6f967 100644
--- a/test/Mono.Linker.Tests.Cases.Expectations/Assertions/ProducedBy.cs
+++ b/test/Mono.Linker.Tests.Cases.Expectations/Assertions/ProducedBy.cs
@@ -5,6 +5,11 @@ using System;
namespace Mono.Linker.Tests.Cases.Expectations.Assertions
{
+ /// <summary>
+ /// Used to specify which tool produces a warning. This can either be the trimmer, a specific analyzer, or both.
+ /// Currently we have all existing diagnostic analyzers listed in here so that we can leave out some expected warnings
+ /// when testing analyzers which do not produce them.
+ /// </summary>
[Flags]
public enum ProducedBy
{
diff --git a/test/Mono.Linker.Tests.Cases/Interop/PInvoke/Warnings/ComPInvokeWarning.cs b/test/Mono.Linker.Tests.Cases/Interop/PInvoke/Warnings/ComPInvokeWarning.cs
index 720ad738b..d64847908 100644
--- a/test/Mono.Linker.Tests.Cases/Interop/PInvoke/Warnings/ComPInvokeWarning.cs
+++ b/test/Mono.Linker.Tests.Cases/Interop/PInvoke/Warnings/ComPInvokeWarning.cs
@@ -15,6 +15,7 @@ namespace Mono.Linker.Tests.Cases.Interop.PInvoke.Warnings
[UnconditionalSuppressMessage ("trim", "IL2026")]
static void Main ()
{
+ Call_SomeMethodReturningAutoLayoutClass ();
Call_SomeMethodTakingInterface ();
Call_SomeMethodTakingObject ();
Call_SomeMethodTakingArray ();
@@ -38,6 +39,7 @@ namespace Mono.Linker.Tests.Cases.Interop.PInvoke.Warnings
{
SomeMethodTakingInterface (null);
}
+
[DllImport ("Foo")]
static extern void SomeMethodTakingInterface (IFoo foo);
@@ -46,6 +48,7 @@ namespace Mono.Linker.Tests.Cases.Interop.PInvoke.Warnings
{
SomeMethodTakingObject (null);
}
+
[DllImport ("Foo")]
static extern void SomeMethodTakingObject ([MarshalAs (UnmanagedType.IUnknown)] object obj);
@@ -54,6 +57,7 @@ namespace Mono.Linker.Tests.Cases.Interop.PInvoke.Warnings
{
SomeMethodTakingArray (null);
}
+
[DllImport ("Foo")]
static extern void SomeMethodTakingArray (Array array);
@@ -61,6 +65,7 @@ namespace Mono.Linker.Tests.Cases.Interop.PInvoke.Warnings
{
SomeMethodTakingStringBuilder (null);
}
+
[DllImport ("Foo")]
static extern void SomeMethodTakingStringBuilder (StringBuilder str);
@@ -68,6 +73,7 @@ namespace Mono.Linker.Tests.Cases.Interop.PInvoke.Warnings
{
SomeMethodTakingCriticalHandle (null);
}
+
[DllImport ("Foo")]
static extern void SomeMethodTakingCriticalHandle (MyCriticalHandle handle);
@@ -76,6 +82,7 @@ namespace Mono.Linker.Tests.Cases.Interop.PInvoke.Warnings
{
SomeMethodTakingSafeHandle (null);
}
+
[DllImport ("Foo")]
static extern void SomeMethodTakingSafeHandle (TestSafeHandle handle);
@@ -83,6 +90,7 @@ namespace Mono.Linker.Tests.Cases.Interop.PInvoke.Warnings
{
SomeMethodTakingExplicitLayout (null);
}
+
[DllImport ("Foo")]
static extern void SomeMethodTakingExplicitLayout (ExplicitLayout _class);
@@ -90,6 +98,7 @@ namespace Mono.Linker.Tests.Cases.Interop.PInvoke.Warnings
{
SomeMethodTakingSequentialLayout (null);
}
+
[DllImport ("Foo")]
static extern void SomeMethodTakingSequentialLayout (SequentialLayout _class);
@@ -98,14 +107,24 @@ namespace Mono.Linker.Tests.Cases.Interop.PInvoke.Warnings
{
SomeMethodTakingAutoLayout (null);
}
+
[DllImport ("Foo")]
static extern void SomeMethodTakingAutoLayout (AutoLayout _class);
+ [ExpectedWarning ("IL2050")]
+ static void Call_SomeMethodReturningAutoLayoutClass ()
+ {
+ SomeMethodReturningAutoLayout ();
+ }
+
+ [DllImport ("Foo")]
+ static extern AutoLayout SomeMethodReturningAutoLayout ();
static void Call_SomeMethodTakingString ()
{
SomeMethodTakingString (null);
}
+
[DllImport ("Foo")]
static extern void SomeMethodTakingString (String str);
@@ -114,6 +133,7 @@ namespace Mono.Linker.Tests.Cases.Interop.PInvoke.Warnings
{
GetInterface ();
}
+
[DllImport ("Foo")]
static extern IFoo GetInterface ();
@@ -122,6 +142,7 @@ namespace Mono.Linker.Tests.Cases.Interop.PInvoke.Warnings
{
CanSuppressWarningOnParameter (null);
}
+
[DllImport ("Foo")]
static extern void CanSuppressWarningOnParameter ([MarshalAs (UnmanagedType.IUnknown)] object obj);
@@ -130,6 +151,7 @@ namespace Mono.Linker.Tests.Cases.Interop.PInvoke.Warnings
{
CanSuppressWarningOnReturnType ();
}
+
[DllImport ("Foo")]
static extern IFoo CanSuppressWarningOnReturnType ();
diff --git a/test/Mono.Linker.Tests/TestCasesRunner/AssemblyChecker.cs b/test/Mono.Linker.Tests/TestCasesRunner/AssemblyChecker.cs
index a8b0ae06d..fcd8572fa 100644
--- a/test/Mono.Linker.Tests/TestCasesRunner/AssemblyChecker.cs
+++ b/test/Mono.Linker.Tests/TestCasesRunner/AssemblyChecker.cs
@@ -579,10 +579,22 @@ namespace Mono.Linker.Tests.TestCasesRunner
void VerifyResources (AssemblyDefinition original, AssemblyDefinition linked)
{
- var expectedResources = original.MainModule.AllDefinedTypes ()
- .SelectMany (t => GetCustomAttributeCtorValues<string> (t, nameof (KeptResourceAttribute)));
+ var expectedResourceNames = original.MainModule.AllDefinedTypes ()
+ .SelectMany (t => GetCustomAttributeCtorValues<string> (t, nameof (KeptResourceAttribute)))
+ .ToList ();
+
+ foreach (var resource in linked.MainModule.Resources) {
+ if (!expectedResourceNames.Remove (resource.Name))
+ Assert.Fail ($"Resource '{resource.Name}' should be removed.");
+
+ EmbeddedResource embeddedResource = (EmbeddedResource) resource;
+
+ var expectedResource = (EmbeddedResource) original.MainModule.Resources.First (r => r.Name == resource.Name);
+
+ Assert.That (embeddedResource.GetResourceData (), Is.EquivalentTo (expectedResource.GetResourceData ()), $"Resource '{resource.Name}' data doesn't match.");
+ }
- Assert.That (linked.MainModule.Resources.Select (r => r.Name), Is.EquivalentTo (expectedResources));
+ Assert.IsEmpty (expectedResourceNames, $"Resource '{expectedResourceNames.FirstOrDefault ()}' should be kept.");
}
void VerifyExportedTypes (AssemblyDefinition original, AssemblyDefinition linked)