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:
authorSven Boemer <sbomer@gmail.com>2020-12-11 00:29:23 +0300
committerGitHub <noreply@github.com>2020-12-11 00:29:23 +0300
commit9c88abd291fafd57076ca4c26deaaf3c6c0a4c7a (patch)
tree15f103a6255a493252052227f5dd6526dcc2b81f /test
parenta86658f4602e616d71e5d6db23a30940534132e2 (diff)
Restrict embedded XML (#1675)
* Restrict embedded XML Embedded attributes and substitutions may only modify the containing assembly. * Allow specifying resource name in referenced assembly In the test infrastructure. * Fix formatting * PR feedback - Allow '*' in corelib embedded attribute XML - Reword warning messages - Avoid calling virtual method from ctor * Fix test on mono Macking the core library causes problems for PEVerify: - Removed reference to corelib creates invalid typerefs - System types like Object aren't found * PR feedback * PR feedback
Diffstat (limited to 'test')
-rw-r--r--test/Mono.Linker.Tests.Cases.Expectations/Metadata/SetupCompileAfterAttribute.cs17
-rw-r--r--test/Mono.Linker.Tests.Cases.Expectations/Metadata/SetupCompileBeforeAttribute.cs32
-rw-r--r--test/Mono.Linker.Tests.Cases/DynamicDependencies/DynamicDependencyMethodInNonReferencedAssemblyWithEmbeddedXml.cs4
-rw-r--r--test/Mono.Linker.Tests.Cases/DynamicDependencies/DynamicDependencyOnUnusedMethodInNonReferencedAssemblyWithEmbeddedXml.cs4
-rw-r--r--test/Mono.Linker.Tests.Cases/LinkAttributes/Dependencies/EmbeddedAttributeErrorCases.cs6
-rw-r--r--test/Mono.Linker.Tests.Cases/LinkAttributes/Dependencies/EmbeddedAttributeErrorCases.xml10
-rw-r--r--test/Mono.Linker.Tests.Cases/LinkAttributes/Dependencies/MockCorelib.cs14
-rw-r--r--test/Mono.Linker.Tests.Cases/LinkAttributes/Dependencies/MockCorelib.xml7
-rw-r--r--test/Mono.Linker.Tests.Cases/LinkAttributes/EmbeddedLinkAttributes.cs19
-rw-r--r--test/Mono.Linker.Tests.Cases/LinkAttributes/EmbeddedLinkAttributes.xml7
-rw-r--r--test/Mono.Linker.Tests.Cases/LinkAttributes/EmbeddedLinkAttributesInCorelib.cs52
-rw-r--r--test/Mono.Linker.Tests.Cases/LinkAttributes/LinkAttributeErrorCases.cs13
-rw-r--r--test/Mono.Linker.Tests.Cases/LinkXml/EmbeddedLinkXmlFromCopyAssemblyIsProcessed.cs2
-rw-r--r--test/Mono.Linker.Tests.Cases/LinkXml/EmbeddedLinkXmlPreservesAdditionalAssemblyWithOverriddenMethod.cs4
-rw-r--r--test/Mono.Linker.Tests.Cases/LinkXml/LinkXmlErrorCases.cs1
-rw-r--r--test/Mono.Linker.Tests.Cases/LinkXml/LinkXmlErrorCases.xml3
-rw-r--r--test/Mono.Linker.Tests.Cases/PreserveDependencies/PreserveDependencyMethodInNonReferencedAssemblyWithEmbeddedXml.cs4
-rw-r--r--test/Mono.Linker.Tests.Cases/PreserveDependencies/PreserveDependencyOnUnusedMethodInNonReferencedAssemblyWithEmbeddedXml.cs4
-rw-r--r--test/Mono.Linker.Tests.Cases/Resources/Dependencies/EmbeddedLinkXmlFileIsProcessed.xml1
-rw-r--r--test/Mono.Linker.Tests.Cases/Resources/EmbeddedLinkXmlFileInReferencedAssemblyIsNotProcessedIfActionIsCopy.cs4
-rw-r--r--test/Mono.Linker.Tests.Cases/Resources/EmbeddedLinkXmlFileInReferencedAssemblyIsNotProcessedIfNameDoesNotMatchAnAssembly.cs4
-rw-r--r--test/Mono.Linker.Tests.Cases/Resources/EmbeddedLinkXmlFileInReferencedAssemblyIsProcessedIfActionIsLink.cs4
-rw-r--r--test/Mono.Linker.Tests.Cases/Resources/EmbeddedLinkXmlFileIsProcessed.cs6
-rw-r--r--test/Mono.Linker.Tests.Cases/Substitutions/Dependencies/EmbeddedSubstitutions.xml3
-rw-r--r--test/Mono.Linker.Tests.Cases/Substitutions/Dependencies/EmbeddedSubstitutionsErrorCases.cs6
-rw-r--r--test/Mono.Linker.Tests.Cases/Substitutions/Dependencies/EmbeddedSubstitutionsErrorCases.xml8
-rw-r--r--test/Mono.Linker.Tests.Cases/Substitutions/EmbeddedSubstitutions.cs11
-rw-r--r--test/Mono.Linker.Tests.Cases/Substitutions/SubstitutionsErrorCases.cs16
-rw-r--r--test/Mono.Linker.Tests.Cases/Substitutions/SubstitutionsErrorCases.xml2
-rw-r--r--test/Mono.Linker.Tests.Cases/TestFramework/CanCompileReferencesWithResources.cs6
-rw-r--r--test/Mono.Linker.Tests.Cases/TestFramework/CanCompileReferencesWithResourcesWithCsc.cs6
-rw-r--r--test/Mono.Linker.Tests.Cases/TestFramework/CanCompileReferencesWithResourcesWithMcs.cs6
-rw-r--r--test/Mono.Linker.Tests/Extensions/CecilExtensions.cs2
-rw-r--r--test/Mono.Linker.Tests/TestCasesRunner/ResultChecker.cs10
-rw-r--r--test/Mono.Linker.Tests/TestCasesRunner/SetupCompileInfo.cs4
-rw-r--r--test/Mono.Linker.Tests/TestCasesRunner/TestCaseMetadaProvider.cs25
-rw-r--r--test/Mono.Linker.Tests/TestCasesRunner/TestCaseSandbox.cs16
37 files changed, 292 insertions, 51 deletions
diff --git a/test/Mono.Linker.Tests.Cases.Expectations/Metadata/SetupCompileAfterAttribute.cs b/test/Mono.Linker.Tests.Cases.Expectations/Metadata/SetupCompileAfterAttribute.cs
index 60a54a1a8..199d9b495 100644
--- a/test/Mono.Linker.Tests.Cases.Expectations/Metadata/SetupCompileAfterAttribute.cs
+++ b/test/Mono.Linker.Tests.Cases.Expectations/Metadata/SetupCompileAfterAttribute.cs
@@ -1,4 +1,4 @@
-using System;
+using System;
namespace Mono.Linker.Tests.Cases.Expectations.Metadata
{
@@ -8,13 +8,26 @@ namespace Mono.Linker.Tests.Cases.Expectations.Metadata
[AttributeUsage (AttributeTargets.Class, AllowMultiple = true)]
public class SetupCompileAfterAttribute : BaseMetadataAttribute
{
- public SetupCompileAfterAttribute (string outputName, string[] sourceFiles, string[] references = null, string[] defines = null, string[] resources = null, string additionalArguments = null, string compilerToUse = null)
+ public SetupCompileAfterAttribute (string outputName, string[] sourceFiles, string[] references = null, string[] defines = null, object[] resources = null, string additionalArguments = null, string compilerToUse = null)
{
if (sourceFiles == null)
throw new ArgumentNullException (nameof (sourceFiles));
if (string.IsNullOrEmpty (outputName))
throw new ArgumentException ("Value cannot be null or empty.", nameof (outputName));
+
+ if (resources != null) {
+ foreach (var res in resources) {
+ if (res is string)
+ continue;
+ if (res is string[] stringArray) {
+ if (stringArray.Length != 2)
+ throw new ArgumentException ("Entry in object[] cannot be a string[] unless it has exactly two elements, for the resource path and name", nameof (resources));
+ continue;
+ }
+ throw new ArgumentException ("Each value in the object[] must be a string or a string[], either a resource path, or a path and name", nameof (resources));
+ }
+ }
}
}
}
diff --git a/test/Mono.Linker.Tests.Cases.Expectations/Metadata/SetupCompileBeforeAttribute.cs b/test/Mono.Linker.Tests.Cases.Expectations/Metadata/SetupCompileBeforeAttribute.cs
index 0ede197cf..bad07736d 100644
--- a/test/Mono.Linker.Tests.Cases.Expectations/Metadata/SetupCompileBeforeAttribute.cs
+++ b/test/Mono.Linker.Tests.Cases.Expectations/Metadata/SetupCompileBeforeAttribute.cs
@@ -1,4 +1,4 @@
-using System;
+using System;
namespace Mono.Linker.Tests.Cases.Expectations.Metadata
{
@@ -8,22 +8,48 @@ namespace Mono.Linker.Tests.Cases.Expectations.Metadata
[AttributeUsage (AttributeTargets.Class, AllowMultiple = true)]
public class SetupCompileBeforeAttribute : BaseMetadataAttribute
{
- public SetupCompileBeforeAttribute (string outputName, string[] sourceFiles, string[] references = null, string[] defines = null, string[] resources = null, string additionalArguments = null, string compilerToUse = null, bool addAsReference = true, bool removeFromLinkerInput = false)
+ public SetupCompileBeforeAttribute (string outputName, string[] sourceFiles, string[] references = null, string[] defines = null, object[] resources = null, string additionalArguments = null, string compilerToUse = null, bool addAsReference = true, bool removeFromLinkerInput = false)
{
if (sourceFiles == null)
throw new ArgumentNullException (nameof (sourceFiles));
if (string.IsNullOrEmpty (outputName))
throw new ArgumentException ("Value cannot be null or empty.", nameof (outputName));
+
+ if (resources != null) {
+ foreach (var res in resources) {
+ if (res is string)
+ continue;
+ if (res is string[] stringArray) {
+ if (stringArray.Length != 2)
+ throw new ArgumentException ("Entry in object[] cannot be a string[] unless it has exactly two elements, for the resource path and name", nameof (resources));
+ continue;
+ }
+ throw new ArgumentException ("Each value in the object[] must be a string or a string[], either a resource path, or a path and name", nameof (resources));
+ }
+ }
}
- public SetupCompileBeforeAttribute (string outputName, Type[] typesToIncludeSourceFor, string[] references = null, string[] defines = null, string[] resources = null, string additionalArguments = null, string compilerToUse = null, bool addAsReference = true, bool removeFromLinkerInput = false)
+ public SetupCompileBeforeAttribute (string outputName, Type[] typesToIncludeSourceFor, string[] references = null, string[] defines = null, object[] resources = null, string additionalArguments = null, string compilerToUse = null, bool addAsReference = true, bool removeFromLinkerInput = false)
{
if (typesToIncludeSourceFor == null)
throw new ArgumentNullException (nameof (typesToIncludeSourceFor));
if (string.IsNullOrEmpty (outputName))
throw new ArgumentException ("Value cannot be null or empty.", nameof (outputName));
+
+ if (resources != null) {
+ foreach (var res in resources) {
+ if (res is string)
+ continue;
+ if (res is string[] stringArray) {
+ if (stringArray.Length != 2)
+ throw new ArgumentException ("Entry in object[] cannot be a string[] unless it has exactly two elements, for the resource path and name", nameof (resources));
+ continue;
+ }
+ throw new ArgumentException ("Each value in the object[] must be a string or a string[], either a resource path, or a path and name", nameof (resources));
+ }
+ }
}
}
}
diff --git a/test/Mono.Linker.Tests.Cases/DynamicDependencies/DynamicDependencyMethodInNonReferencedAssemblyWithEmbeddedXml.cs b/test/Mono.Linker.Tests.Cases/DynamicDependencies/DynamicDependencyMethodInNonReferencedAssemblyWithEmbeddedXml.cs
index b596ad04c..bc66f59da 100644
--- a/test/Mono.Linker.Tests.Cases/DynamicDependencies/DynamicDependencyMethodInNonReferencedAssemblyWithEmbeddedXml.cs
+++ b/test/Mono.Linker.Tests.Cases/DynamicDependencies/DynamicDependencyMethodInNonReferencedAssemblyWithEmbeddedXml.cs
@@ -1,4 +1,4 @@
-using System.Diagnostics.CodeAnalysis;
+using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using Mono.Linker.Tests.Cases.DynamicDependencies.Dependencies;
using Mono.Linker.Tests.Cases.Expectations.Assertions;
@@ -15,7 +15,7 @@ namespace Mono.Linker.Tests.Cases.DynamicDependencies
"DynamicDependencyMethodInNonReferencedAssemblyLibrary.dll",
new[] { "Dependencies/DynamicDependencyMethodInNonReferencedAssemblyLibrary.cs" },
references: new[] { "base.dll" },
- resources: new[] { "Dependencies/DynamicDependencyMethodInNonReferencedAssemblyLibrary.xml" },
+ resources: new object[] { "Dependencies/DynamicDependencyMethodInNonReferencedAssemblyLibrary.xml" },
addAsReference: false)]
[KeptAssembly ("base.dll")]
[RemovedMemberInAssembly ("DynamicDependencyMethodInNonReferencedAssemblyLibrary.dll", "Mono.Linker.Tests.Cases.DynamicDependencies.Dependencies.DynamicDependencyMethodInNonReferencedAssemblyLibrary", "UnusedMethod()")]
diff --git a/test/Mono.Linker.Tests.Cases/DynamicDependencies/DynamicDependencyOnUnusedMethodInNonReferencedAssemblyWithEmbeddedXml.cs b/test/Mono.Linker.Tests.Cases/DynamicDependencies/DynamicDependencyOnUnusedMethodInNonReferencedAssemblyWithEmbeddedXml.cs
index 747e3362d..a1bbb263d 100644
--- a/test/Mono.Linker.Tests.Cases/DynamicDependencies/DynamicDependencyOnUnusedMethodInNonReferencedAssemblyWithEmbeddedXml.cs
+++ b/test/Mono.Linker.Tests.Cases/DynamicDependencies/DynamicDependencyOnUnusedMethodInNonReferencedAssemblyWithEmbeddedXml.cs
@@ -1,4 +1,4 @@
-using System.Diagnostics.CodeAnalysis;
+using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using Mono.Linker.Tests.Cases.DynamicDependencies.Dependencies;
using Mono.Linker.Tests.Cases.Expectations.Assertions;
@@ -15,7 +15,7 @@ namespace Mono.Linker.Tests.Cases.DynamicDependencies
"DynamicDependencyMethodInNonReferencedAssemblyLibrary.dll",
new[] { "Dependencies/DynamicDependencyMethodInNonReferencedAssemblyLibrary.cs" },
references: new[] { "base.dll" },
- resources: new[] { "Dependencies/DynamicDependencyMethodInNonReferencedAssemblyLibrary.xml" },
+ resources: new object[] { "Dependencies/DynamicDependencyMethodInNonReferencedAssemblyLibrary.xml" },
addAsReference: false)]
[KeptAssembly ("base.dll")]
[RemovedAssembly ("DynamicDependencyMethodInNonReferencedAssemblyLibrary.dll")]
diff --git a/test/Mono.Linker.Tests.Cases/LinkAttributes/Dependencies/EmbeddedAttributeErrorCases.cs b/test/Mono.Linker.Tests.Cases/LinkAttributes/Dependencies/EmbeddedAttributeErrorCases.cs
new file mode 100644
index 000000000..9943876b4
--- /dev/null
+++ b/test/Mono.Linker.Tests.Cases/LinkAttributes/Dependencies/EmbeddedAttributeErrorCases.cs
@@ -0,0 +1,6 @@
+namespace Mono.Linker.Tests.Cases.LinkAttributes.Dependencies
+{
+ public class EmbeddedAttributeErrorCases
+ {
+ }
+}
diff --git a/test/Mono.Linker.Tests.Cases/LinkAttributes/Dependencies/EmbeddedAttributeErrorCases.xml b/test/Mono.Linker.Tests.Cases/LinkAttributes/Dependencies/EmbeddedAttributeErrorCases.xml
new file mode 100644
index 000000000..bdf245917
--- /dev/null
+++ b/test/Mono.Linker.Tests.Cases/LinkAttributes/Dependencies/EmbeddedAttributeErrorCases.xml
@@ -0,0 +1,10 @@
+<linker>
+ <!-- IL2100 -->
+ <assembly fullname="*" />
+ <!-- IL2101 -->
+ <assembly fullname="test">
+ <type fullname="Mono.Linker.Tests.Cases.LinkAttributes.LinkAttributeErrorCases/ReferencedFromOtherAssembly">
+ <attribute fullname="Mono.Linker.Tests.Cases.LinkAttributes.LinkAttributeErrorCases/FirstAttribute" />
+ </type>
+ </assembly>
+</linker> \ No newline at end of file
diff --git a/test/Mono.Linker.Tests.Cases/LinkAttributes/Dependencies/MockCorelib.cs b/test/Mono.Linker.Tests.Cases/LinkAttributes/Dependencies/MockCorelib.cs
new file mode 100644
index 000000000..cd6e37a01
--- /dev/null
+++ b/test/Mono.Linker.Tests.Cases/LinkAttributes/Dependencies/MockCorelib.cs
@@ -0,0 +1,14 @@
+#if INCLUDE_MOCK_CORELIB
+
+using System;
+
+[assembly: MockCorelibAttributeToRemove]
+
+namespace System
+{
+ public class MockCorelibAttributeToRemove : Attribute
+ {
+ }
+}
+
+#endif \ No newline at end of file
diff --git a/test/Mono.Linker.Tests.Cases/LinkAttributes/Dependencies/MockCorelib.xml b/test/Mono.Linker.Tests.Cases/LinkAttributes/Dependencies/MockCorelib.xml
new file mode 100644
index 000000000..203be555e
--- /dev/null
+++ b/test/Mono.Linker.Tests.Cases/LinkAttributes/Dependencies/MockCorelib.xml
@@ -0,0 +1,7 @@
+<linker>
+ <assembly fullname="*">
+ <type fullname="System.MockCorelibAttributeToRemove">
+ <attribute internal="RemoveAttributeInstances" />
+ </type>
+ </assembly>
+</linker> \ No newline at end of file
diff --git a/test/Mono.Linker.Tests.Cases/LinkAttributes/EmbeddedLinkAttributes.cs b/test/Mono.Linker.Tests.Cases/LinkAttributes/EmbeddedLinkAttributes.cs
index 5a5f8e681..b4c5f8d3a 100644
--- a/test/Mono.Linker.Tests.Cases/LinkAttributes/EmbeddedLinkAttributes.cs
+++ b/test/Mono.Linker.Tests.Cases/LinkAttributes/EmbeddedLinkAttributes.cs
@@ -3,9 +3,7 @@
// See the LICENSE file in the project root for more information.
using System;
-using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
-using System.Text;
using Mono.Linker.Tests.Cases.Expectations.Assertions;
using Mono.Linker.Tests.Cases.Expectations.Metadata;
@@ -22,6 +20,7 @@ namespace Mono.Linker.Tests.Cases.LinkAttributes
var instance = new EmbeddedLinkAttributes ();
instance.ReadFromInstanceField ();
+ instance.ReadFromInstanceField2 ();
}
Type _typeWithPublicParameterlessConstructor;
@@ -52,5 +51,21 @@ namespace Mono.Linker.Tests.Cases.LinkAttributes
Type type)
{
}
+
+ Type _typeWithPublicFields;
+
+ [UnrecognizedReflectionAccessPattern (typeof (EmbeddedLinkAttributes), nameof (RequirePublicConstructors), new Type[] { typeof (Type) })]
+ [RecognizedReflectionAccessPattern]
+ private void ReadFromInstanceField2 ()
+ {
+ RequirePublicConstructors (_typeWithPublicFields);
+ RequirePublicFields (_typeWithPublicFields);
+ }
+
+ private static void RequirePublicFields (
+ [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields)]
+ Type type)
+ {
+ }
}
}
diff --git a/test/Mono.Linker.Tests.Cases/LinkAttributes/EmbeddedLinkAttributes.xml b/test/Mono.Linker.Tests.Cases/LinkAttributes/EmbeddedLinkAttributes.xml
index 6a3c143dc..00916a338 100644
--- a/test/Mono.Linker.Tests.Cases/LinkAttributes/EmbeddedLinkAttributes.xml
+++ b/test/Mono.Linker.Tests.Cases/LinkAttributes/EmbeddedLinkAttributes.xml
@@ -8,4 +8,11 @@
</field>
</type>
</assembly>
+ <type fullname="Mono.Linker.Tests.Cases.LinkAttributes.EmbeddedLinkAttributes">
+ <field name="_typeWithPublicFields">
+ <attribute fullname="System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute">
+ <argument>PublicFields</argument>
+ </attribute>
+ </field>
+ </type>
</linker>
diff --git a/test/Mono.Linker.Tests.Cases/LinkAttributes/EmbeddedLinkAttributesInCorelib.cs b/test/Mono.Linker.Tests.Cases/LinkAttributes/EmbeddedLinkAttributesInCorelib.cs
new file mode 100644
index 000000000..3453597c2
--- /dev/null
+++ b/test/Mono.Linker.Tests.Cases/LinkAttributes/EmbeddedLinkAttributesInCorelib.cs
@@ -0,0 +1,52 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+using System;
+using Mono.Linker.Tests.Cases.Expectations.Assertions;
+using Mono.Linker.Tests.Cases.Expectations.Metadata;
+
+namespace System
+{
+ public class MockCorelibAttributeToRemove : Attribute
+ {
+ }
+}
+
+namespace Mono.Linker.Tests.Cases.LinkAttributes
+{
+ [IgnoreLinkAttributes (false)]
+ [SetupLinkerCoreAction ("link")] // Ensure that corelib gets linked so that its attribtues are processed
+ [SetupLinkerArgument ("--skip-unresolved", "true")] // Allow unresolved references to types missing from mock corelib
+ [SetupCompileBefore (PlatformAssemblies.CoreLib, new string[] { "Dependencies/MockCorelib.cs" },
+ resources: new object[] { new string[] { "Dependencies/MockCorelib.xml", "ILLink.LinkAttributes.xml" } },
+ defines: new[] { "INCLUDE_MOCK_CORELIB" })]
+ [SkipPeVerify]
+#if NETCOREAPP
+ [RemovedAttributeInAssembly ("System.Private.CoreLib", "System.MockCorelibAttributeToRemove")]
+ [RemovedTypeInAssembly ("System.Private.CoreLib", "System.MockCorelibAttributeToRemove")]
+#else
+ [RemovedAttributeInAssembly ("mscorlib", "System.MockCorelibAttributeToRemove")]
+ [RemovedTypeInAssembly ("mscorlib", "System.MockCorelibAttributeToRemove")]
+#endif
+ class EmbeddedLinkAttributesInCorelib
+ {
+ public static void Main ()
+ {
+ AttributedMethod ();
+ var _ = new AttributedClass ();
+ }
+
+ [Kept]
+ [MockCorelibAttributeToRemove]
+ public static void AttributedMethod ()
+ {
+ }
+
+ [Kept]
+ [KeptMember (".ctor()")]
+ [MockCorelibAttributeToRemove]
+ public class AttributedClass
+ {
+ }
+ }
+}
diff --git a/test/Mono.Linker.Tests.Cases/LinkAttributes/LinkAttributeErrorCases.cs b/test/Mono.Linker.Tests.Cases/LinkAttributes/LinkAttributeErrorCases.cs
index 3d9e90262..6f2e214f7 100644
--- a/test/Mono.Linker.Tests.Cases/LinkAttributes/LinkAttributeErrorCases.cs
+++ b/test/Mono.Linker.Tests.Cases/LinkAttributes/LinkAttributeErrorCases.cs
@@ -1,14 +1,15 @@
using System;
-using System.Collections.Generic;
-using System.Text;
using Mono.Linker.Tests.Cases.Expectations.Assertions;
using Mono.Linker.Tests.Cases.Expectations.Metadata;
+using Mono.Linker.Tests.Cases.LinkAttributes.Dependencies;
namespace Mono.Linker.Tests.Cases.LinkAttributes
{
[SetupLinkAttributesFile ("LinkAttributeErrorCases.xml")]
[IgnoreLinkAttributes (false)]
[SetupLinkerArgument ("--skip-unresolved", "true")]
+ [SetupCompileBefore ("library.dll", new string[] { "Dependencies/EmbeddedAttributeErrorCases.cs" },
+ resources: new object[] { new string[] { "Dependencies/EmbeddedAttributeErrorCases.xml", "ILLink.LinkAttributes.xml" } })]
[ExpectedWarning ("IL2007", "NonExistentAssembly2", FileName = "LinkAttributeErrorCases.xml")]
[ExpectedWarning ("IL2030", "NonExistentAssembly1", FileName = "LinkAttributeErrorCases.xml")]
@@ -24,11 +25,13 @@ namespace Mono.Linker.Tests.Cases.LinkAttributes
[ExpectedWarning ("IL2051", FileName = "LinkAttributeErrorCases.xml")]
[ExpectedWarning ("IL2052", "NonExistentPropertyName", FileName = "LinkAttributeErrorCases.xml")]
[ExpectedWarning ("IL2053", "StringValue", "IntProperty", FileName = "LinkAttributeErrorCases.xml")]
+ [ExpectedWarning ("IL2100", FileName = "ILLink.LinkAttributes.xml")]
+ [ExpectedWarning ("IL2101", "library", "test", FileName = "ILLink.LinkAttributes.xml")]
class LinkAttributeErrorCases
{
public static void Main ()
{
-
+ var _ = new EmbeddedAttributeErrorCases ();
}
public enum AttributeEnum
@@ -72,5 +75,9 @@ namespace Mono.Linker.Tests.Cases.LinkAttributes
public Type GetTypeMethod () => null;
public void MethodWithParameter (int methodParameter) { }
+
+ public class ReferencedFromOtherAssembly
+ {
+ }
}
}
diff --git a/test/Mono.Linker.Tests.Cases/LinkXml/EmbeddedLinkXmlFromCopyAssemblyIsProcessed.cs b/test/Mono.Linker.Tests.Cases/LinkXml/EmbeddedLinkXmlFromCopyAssemblyIsProcessed.cs
index a5e327104..96d7e941f 100644
--- a/test/Mono.Linker.Tests.Cases/LinkXml/EmbeddedLinkXmlFromCopyAssemblyIsProcessed.cs
+++ b/test/Mono.Linker.Tests.Cases/LinkXml/EmbeddedLinkXmlFromCopyAssemblyIsProcessed.cs
@@ -8,7 +8,7 @@ namespace Mono.Linker.Tests.Cases.LinkXml
new[] { "Dependencies/EmbeddedLinkXmlFromCopyAssemblyIsProcessed/OtherLibrary.cs" })]
[SetupCompileBefore ("CopyLibrary.dll",
new[] { "Dependencies/EmbeddedLinkXmlFromCopyAssemblyIsProcessed/CopyLibrary.cs" },
- resources: new[] { "Dependencies/EmbeddedLinkXmlFromCopyAssemblyIsProcessed/CopyLibrary.xml" })]
+ resources: new object[] { "Dependencies/EmbeddedLinkXmlFromCopyAssemblyIsProcessed/CopyLibrary.xml" })]
[IgnoreDescriptors (false)]
[SetupLinkerAction ("copy", "CopyLibrary")]
diff --git a/test/Mono.Linker.Tests.Cases/LinkXml/EmbeddedLinkXmlPreservesAdditionalAssemblyWithOverriddenMethod.cs b/test/Mono.Linker.Tests.Cases/LinkXml/EmbeddedLinkXmlPreservesAdditionalAssemblyWithOverriddenMethod.cs
index 37a8265ea..99fa7f39e 100644
--- a/test/Mono.Linker.Tests.Cases/LinkXml/EmbeddedLinkXmlPreservesAdditionalAssemblyWithOverriddenMethod.cs
+++ b/test/Mono.Linker.Tests.Cases/LinkXml/EmbeddedLinkXmlPreservesAdditionalAssemblyWithOverriddenMethod.cs
@@ -1,4 +1,4 @@
-using Mono.Linker.Tests.Cases.Expectations.Assertions;
+using Mono.Linker.Tests.Cases.Expectations.Assertions;
using Mono.Linker.Tests.Cases.Expectations.Metadata;
using Mono.Linker.Tests.Cases.LinkXml.Dependencies.EmbeddedLinkXmlPreservesAdditionalAssemblyWithOverriddenMethod;
@@ -9,7 +9,7 @@ namespace Mono.Linker.Tests.Cases.LinkXml
[SetupCompileBefore ("Library1.dll",
new[] { "Dependencies/EmbeddedLinkXmlPreservesAdditionalAssemblyWithOverriddenMethod/Library1.cs" },
new[] { "Base.dll" },
- resources: new[] { "Dependencies/EmbeddedLinkXmlPreservesAdditionalAssemblyWithOverriddenMethod/Library1.xml" })]
+ resources: new object[] { "Dependencies/EmbeddedLinkXmlPreservesAdditionalAssemblyWithOverriddenMethod/Library1.xml" })]
[SetupCompileBefore ("Library2.dll",
new[] { "Dependencies/EmbeddedLinkXmlPreservesAdditionalAssemblyWithOverriddenMethod/Library2.cs" },
new[] { "Base.dll" },
diff --git a/test/Mono.Linker.Tests.Cases/LinkXml/LinkXmlErrorCases.cs b/test/Mono.Linker.Tests.Cases/LinkXml/LinkXmlErrorCases.cs
index 6b5303a5d..cd737ab4c 100644
--- a/test/Mono.Linker.Tests.Cases/LinkXml/LinkXmlErrorCases.cs
+++ b/test/Mono.Linker.Tests.Cases/LinkXml/LinkXmlErrorCases.cs
@@ -20,6 +20,7 @@ namespace Mono.Linker.Tests.Cases.LinkXml
[ExpectedWarning ("IL2025", "Event", FileName = "LinkXmlErrorCases.xml")]
[ExpectedWarning ("IL2025", "Field", FileName = "LinkXmlErrorCases.xml")]
[ExpectedWarning ("IL2025", "Property", FileName = "LinkXmlErrorCases.xml")]
+ [ExpectedWarning ("IL2100", FileName = "LinkXmlErrorCases.xml")]
class LinkXmlErrorCases
{
public static void Main ()
diff --git a/test/Mono.Linker.Tests.Cases/LinkXml/LinkXmlErrorCases.xml b/test/Mono.Linker.Tests.Cases/LinkXml/LinkXmlErrorCases.xml
index dca7c7d2d..9ae9842be 100644
--- a/test/Mono.Linker.Tests.Cases/LinkXml/LinkXmlErrorCases.xml
+++ b/test/Mono.Linker.Tests.Cases/LinkXml/LinkXmlErrorCases.xml
@@ -43,4 +43,7 @@
</assembly>
<assembly fullname="NonExistentAssembly"/>
+
+ <!-- IL2100 -->
+ <assembly fullname="*" />
</linker>
diff --git a/test/Mono.Linker.Tests.Cases/PreserveDependencies/PreserveDependencyMethodInNonReferencedAssemblyWithEmbeddedXml.cs b/test/Mono.Linker.Tests.Cases/PreserveDependencies/PreserveDependencyMethodInNonReferencedAssemblyWithEmbeddedXml.cs
index d7bd3c54f..2c3e4cebe 100644
--- a/test/Mono.Linker.Tests.Cases/PreserveDependencies/PreserveDependencyMethodInNonReferencedAssemblyWithEmbeddedXml.cs
+++ b/test/Mono.Linker.Tests.Cases/PreserveDependencies/PreserveDependencyMethodInNonReferencedAssemblyWithEmbeddedXml.cs
@@ -1,4 +1,4 @@
-using System.Runtime.CompilerServices;
+using System.Runtime.CompilerServices;
using Mono.Linker.Tests.Cases.Expectations.Assertions;
using Mono.Linker.Tests.Cases.Expectations.Metadata;
using Mono.Linker.Tests.Cases.PreserveDependencies.Dependencies;
@@ -15,7 +15,7 @@ namespace Mono.Linker.Tests.Cases.PreserveDependencies
"PreserveDependencyMethodInNonReferencedAssemblyLibrary.dll",
new[] { "Dependencies/PreserveDependencyMethodInNonReferencedAssemblyLibrary.cs" },
references: new[] { "base.dll" },
- resources: new[] { "Dependencies/PreserveDependencyMethodInNonReferencedAssemblyLibrary.xml" },
+ resources: new object[] { "Dependencies/PreserveDependencyMethodInNonReferencedAssemblyLibrary.xml" },
addAsReference: false)]
[KeptAssembly ("base.dll")]
[RemovedMemberInAssembly ("PreserveDependencyMethodInNonReferencedAssemblyLibrary.dll", "Mono.Linker.Tests.Cases.PreserveDependencies.Dependencies.PreserveDependencyMethodInNonReferencedAssemblyLibrary", "UnusedMethod()")]
diff --git a/test/Mono.Linker.Tests.Cases/PreserveDependencies/PreserveDependencyOnUnusedMethodInNonReferencedAssemblyWithEmbeddedXml.cs b/test/Mono.Linker.Tests.Cases/PreserveDependencies/PreserveDependencyOnUnusedMethodInNonReferencedAssemblyWithEmbeddedXml.cs
index 770657112..b9faa4716 100644
--- a/test/Mono.Linker.Tests.Cases/PreserveDependencies/PreserveDependencyOnUnusedMethodInNonReferencedAssemblyWithEmbeddedXml.cs
+++ b/test/Mono.Linker.Tests.Cases/PreserveDependencies/PreserveDependencyOnUnusedMethodInNonReferencedAssemblyWithEmbeddedXml.cs
@@ -1,4 +1,4 @@
-using System.Runtime.CompilerServices;
+using System.Runtime.CompilerServices;
using Mono.Linker.Tests.Cases.Expectations.Assertions;
using Mono.Linker.Tests.Cases.Expectations.Metadata;
using Mono.Linker.Tests.Cases.PreserveDependencies.Dependencies;
@@ -15,7 +15,7 @@ namespace Mono.Linker.Tests.Cases.PreserveDependencies
"PreserveDependencyMethodInNonReferencedAssemblyLibrary.dll",
new[] { "Dependencies/PreserveDependencyMethodInNonReferencedAssemblyLibrary.cs" },
references: new[] { "base.dll" },
- resources: new[] { "Dependencies/PreserveDependencyMethodInNonReferencedAssemblyLibrary.xml" },
+ resources: new object[] { "Dependencies/PreserveDependencyMethodInNonReferencedAssemblyLibrary.xml" },
addAsReference: false)]
[KeptAssembly ("base.dll")]
[RemovedAssembly ("PreserveDependencyMethodInNonReferencedAssemblyLibrary.dll")]
diff --git a/test/Mono.Linker.Tests.Cases/Resources/Dependencies/EmbeddedLinkXmlFileIsProcessed.xml b/test/Mono.Linker.Tests.Cases/Resources/Dependencies/EmbeddedLinkXmlFileIsProcessed.xml
index 518addf3d..2b04a8f94 100644
--- a/test/Mono.Linker.Tests.Cases/Resources/Dependencies/EmbeddedLinkXmlFileIsProcessed.xml
+++ b/test/Mono.Linker.Tests.Cases/Resources/Dependencies/EmbeddedLinkXmlFileIsProcessed.xml
@@ -2,4 +2,5 @@
<assembly fullname="test, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
<type fullname="Mono.Linker.Tests.Cases.Resources.EmbeddedLinkXmlFileIsProcessed/Unused" />
</assembly>
+ <type fullname="Mono.Linker.Tests.Cases.Resources.EmbeddedLinkXmlFileIsProcessed/Unused2" />
</linker> \ No newline at end of file
diff --git a/test/Mono.Linker.Tests.Cases/Resources/EmbeddedLinkXmlFileInReferencedAssemblyIsNotProcessedIfActionIsCopy.cs b/test/Mono.Linker.Tests.Cases/Resources/EmbeddedLinkXmlFileInReferencedAssemblyIsNotProcessedIfActionIsCopy.cs
index ebf100b07..2fdd8238d 100644
--- a/test/Mono.Linker.Tests.Cases/Resources/EmbeddedLinkXmlFileInReferencedAssemblyIsNotProcessedIfActionIsCopy.cs
+++ b/test/Mono.Linker.Tests.Cases/Resources/EmbeddedLinkXmlFileInReferencedAssemblyIsNotProcessedIfActionIsCopy.cs
@@ -1,4 +1,4 @@
-using Mono.Linker.Tests.Cases.Expectations.Assertions;
+using Mono.Linker.Tests.Cases.Expectations.Assertions;
using Mono.Linker.Tests.Cases.Expectations.Metadata;
using Mono.Linker.Tests.Cases.Resources.Dependencies;
@@ -7,7 +7,7 @@ namespace Mono.Linker.Tests.Cases.Resources
[SetupCompileBefore (
"EmbeddedLinkXmlFileInReferencedAssemblyIsNotProcessedIfActionIsCopy_Lib1.dll",
new[] { "Dependencies/EmbeddedLinkXmlFileInReferencedAssemblyIsNotProcessedIfActionIsCopy_Lib1.cs" },
- resources: new[] { "Dependencies/EmbeddedLinkXmlFileInReferencedAssemblyIsNotProcessedIfActionIsCopy_Lib1.xml" })]
+ resources: new object[] { "Dependencies/EmbeddedLinkXmlFileInReferencedAssemblyIsNotProcessedIfActionIsCopy_Lib1.xml" })]
[SetupLinkerAction ("copy", "EmbeddedLinkXmlFileInReferencedAssemblyIsNotProcessedIfActionIsCopy_Lib1")]
[IgnoreDescriptors (false)]
diff --git a/test/Mono.Linker.Tests.Cases/Resources/EmbeddedLinkXmlFileInReferencedAssemblyIsNotProcessedIfNameDoesNotMatchAnAssembly.cs b/test/Mono.Linker.Tests.Cases/Resources/EmbeddedLinkXmlFileInReferencedAssemblyIsNotProcessedIfNameDoesNotMatchAnAssembly.cs
index 1dcbe7870..1dc274186 100644
--- a/test/Mono.Linker.Tests.Cases/Resources/EmbeddedLinkXmlFileInReferencedAssemblyIsNotProcessedIfNameDoesNotMatchAnAssembly.cs
+++ b/test/Mono.Linker.Tests.Cases/Resources/EmbeddedLinkXmlFileInReferencedAssemblyIsNotProcessedIfNameDoesNotMatchAnAssembly.cs
@@ -1,4 +1,4 @@
-using Mono.Linker.Tests.Cases.Expectations.Assertions;
+using Mono.Linker.Tests.Cases.Expectations.Assertions;
using Mono.Linker.Tests.Cases.Expectations.Metadata;
using Mono.Linker.Tests.Cases.Resources.Dependencies;
@@ -7,7 +7,7 @@ namespace Mono.Linker.Tests.Cases.Resources
[SetupCompileBefore (
"library.dll",
new[] { "Dependencies/EmbeddedLinkXmlFileInReferencedAssemblyIsNotProcessedIfNameDoesNotMatchAnAssembly_Lib1.cs" },
- resources: new[] { "Dependencies/EmbeddedLinkXmlFileInReferencedAssemblyIsNotProcessedIfNameDoesNotMatchAnAssembly_Lib1_NotMatchingName.xml" })]
+ resources: new object[] { "Dependencies/EmbeddedLinkXmlFileInReferencedAssemblyIsNotProcessedIfNameDoesNotMatchAnAssembly_Lib1_NotMatchingName.xml" })]
[IgnoreDescriptors (false)]
[KeptResourceInAssembly ("library.dll", "EmbeddedLinkXmlFileInReferencedAssemblyIsNotProcessedIfNameDoesNotMatchAnAssembly_Lib1_NotMatchingName.xml")]
diff --git a/test/Mono.Linker.Tests.Cases/Resources/EmbeddedLinkXmlFileInReferencedAssemblyIsProcessedIfActionIsLink.cs b/test/Mono.Linker.Tests.Cases/Resources/EmbeddedLinkXmlFileInReferencedAssemblyIsProcessedIfActionIsLink.cs
index c8926980b..b1e45f250 100644
--- a/test/Mono.Linker.Tests.Cases/Resources/EmbeddedLinkXmlFileInReferencedAssemblyIsProcessedIfActionIsLink.cs
+++ b/test/Mono.Linker.Tests.Cases/Resources/EmbeddedLinkXmlFileInReferencedAssemblyIsProcessedIfActionIsLink.cs
@@ -1,4 +1,4 @@
-using Mono.Linker.Tests.Cases.Expectations.Assertions;
+using Mono.Linker.Tests.Cases.Expectations.Assertions;
using Mono.Linker.Tests.Cases.Expectations.Metadata;
using Mono.Linker.Tests.Cases.Resources.Dependencies;
@@ -7,7 +7,7 @@ namespace Mono.Linker.Tests.Cases.Resources
[SetupCompileBefore (
"EmbeddedLinkXmlFileInReferencedAssemblyIsProcessedIfActionIsLink_Lib1.dll",
new[] { "Dependencies/EmbeddedLinkXmlFileInReferencedAssemblyIsProcessedIfActionIsLink_Lib1.cs" },
- resources: new[] { "Dependencies/EmbeddedLinkXmlFileInReferencedAssemblyIsProcessedIfActionIsLink_Lib1.xml" })]
+ resources: new object[] { "Dependencies/EmbeddedLinkXmlFileInReferencedAssemblyIsProcessedIfActionIsLink_Lib1.xml" })]
[SetupLinkerAction ("link", "EmbeddedLinkXmlFileInReferencedAssemblyIsProcessedIfActionIsLink_Lib1")]
[IgnoreDescriptors (false)]
diff --git a/test/Mono.Linker.Tests.Cases/Resources/EmbeddedLinkXmlFileIsProcessed.cs b/test/Mono.Linker.Tests.Cases/Resources/EmbeddedLinkXmlFileIsProcessed.cs
index ae502329c..170ad28dd 100644
--- a/test/Mono.Linker.Tests.Cases/Resources/EmbeddedLinkXmlFileIsProcessed.cs
+++ b/test/Mono.Linker.Tests.Cases/Resources/EmbeddedLinkXmlFileIsProcessed.cs
@@ -19,5 +19,11 @@ namespace Mono.Linker.Tests.Cases.Resources
public class Unused
{
}
+
+ [Kept]
+ [KeptMember (".ctor()")]
+ public class Unused2
+ {
+ }
}
}
diff --git a/test/Mono.Linker.Tests.Cases/Substitutions/Dependencies/EmbeddedSubstitutions.xml b/test/Mono.Linker.Tests.Cases/Substitutions/Dependencies/EmbeddedSubstitutions.xml
index 3bd0175a6..00c9a0e58 100644
--- a/test/Mono.Linker.Tests.Cases/Substitutions/Dependencies/EmbeddedSubstitutions.xml
+++ b/test/Mono.Linker.Tests.Cases/Substitutions/Dependencies/EmbeddedSubstitutions.xml
@@ -4,4 +4,7 @@
<method signature="System.Void ConvertToThrowMethod()" body="remove" />
</type>
</assembly>
+ <type fullname="Mono.Linker.Tests.Cases.Substitutions.EmbeddedSubstitutions">
+ <method signature="System.Void ConvertToThrowMethod2()" body="remove" />
+ </type>
</linker> \ No newline at end of file
diff --git a/test/Mono.Linker.Tests.Cases/Substitutions/Dependencies/EmbeddedSubstitutionsErrorCases.cs b/test/Mono.Linker.Tests.Cases/Substitutions/Dependencies/EmbeddedSubstitutionsErrorCases.cs
new file mode 100644
index 000000000..ad0331b4f
--- /dev/null
+++ b/test/Mono.Linker.Tests.Cases/Substitutions/Dependencies/EmbeddedSubstitutionsErrorCases.cs
@@ -0,0 +1,6 @@
+namespace Mono.Linker.Tests.Cases.Substitutions.Dependencies
+{
+ public class EmbeddedSubstitutionsErrorCases
+ {
+ }
+}
diff --git a/test/Mono.Linker.Tests.Cases/Substitutions/Dependencies/EmbeddedSubstitutionsErrorCases.xml b/test/Mono.Linker.Tests.Cases/Substitutions/Dependencies/EmbeddedSubstitutionsErrorCases.xml
new file mode 100644
index 000000000..fdf8c332a
--- /dev/null
+++ b/test/Mono.Linker.Tests.Cases/Substitutions/Dependencies/EmbeddedSubstitutionsErrorCases.xml
@@ -0,0 +1,8 @@
+<linker>
+ <!-- IL2101 -->
+ <assembly fullname="test">
+ <type fullname="Mono.Linker.Tests.Cases.Substitutions.SubstitutionsErrorCases/ReferencedFromOtherAssembly">
+ <method signature="System.Int32 TestMethod()" body="stub" value="1" />
+ </type>
+ </assembly>
+</linker> \ No newline at end of file
diff --git a/test/Mono.Linker.Tests.Cases/Substitutions/EmbeddedSubstitutions.cs b/test/Mono.Linker.Tests.Cases/Substitutions/EmbeddedSubstitutions.cs
index 3306aee24..3faba8259 100644
--- a/test/Mono.Linker.Tests.Cases/Substitutions/EmbeddedSubstitutions.cs
+++ b/test/Mono.Linker.Tests.Cases/Substitutions/EmbeddedSubstitutions.cs
@@ -11,6 +11,7 @@ namespace Mono.Linker.Tests.Cases.Substitutions
public static void Main ()
{
ConvertToThrowMethod ();
+ ConvertToThrowMethod2 ();
}
[Kept]
@@ -22,5 +23,15 @@ namespace Mono.Linker.Tests.Cases.Substitutions
public static void ConvertToThrowMethod ()
{
}
+
+ [Kept]
+ [ExpectedInstructionSequence (new[] {
+ "ldstr",
+ "newobj",
+ "throw"
+ })]
+ public static void ConvertToThrowMethod2 ()
+ {
+ }
}
}
diff --git a/test/Mono.Linker.Tests.Cases/Substitutions/SubstitutionsErrorCases.cs b/test/Mono.Linker.Tests.Cases/Substitutions/SubstitutionsErrorCases.cs
index 1789eb963..2aa9c3064 100644
--- a/test/Mono.Linker.Tests.Cases/Substitutions/SubstitutionsErrorCases.cs
+++ b/test/Mono.Linker.Tests.Cases/Substitutions/SubstitutionsErrorCases.cs
@@ -1,10 +1,13 @@
-using System;
-using Mono.Linker.Tests.Cases.Expectations.Assertions;
+using Mono.Linker.Tests.Cases.Expectations.Assertions;
using Mono.Linker.Tests.Cases.Expectations.Metadata;
+using Mono.Linker.Tests.Cases.Substitutions.Dependencies;
namespace Mono.Linker.Tests.Cases.Substitutions
{
[SetupLinkerSubstitutionFile ("SubstitutionsErrorCases.xml")]
+ [IgnoreSubstitutions (false)]
+ [SetupCompileBefore ("library.dll", new string[] { "Dependencies/EmbeddedSubstitutionsErrorCases.cs" },
+ resources: new object[] { new string[] { "Dependencies/EmbeddedSubstitutionsErrorCases.xml", "ILLink.Substitutions.xml" } })]
[ExpectedWarning ("IL2010", "TestMethod_1", "stub", FileName = "SubstitutionsErrorCases.xml")]
[ExpectedWarning ("IL2011", "TestMethod_2", "noaction", FileName = "SubstitutionsErrorCases.xml")]
@@ -12,6 +15,8 @@ namespace Mono.Linker.Tests.Cases.Substitutions
[ExpectedWarning ("IL2014", "SubstitutionsErrorCases::IntField", FileName = "SubstitutionsErrorCases.xml")]
[ExpectedWarning ("IL2015", "SubstitutionsErrorCases::IntField", "NonNumber", FileName = "SubstitutionsErrorCases.xml")]
[ExpectedWarning ("IL2007", "NonExistentAssembly", FileName = "SubstitutionsErrorCases.xml")]
+ [ExpectedWarning ("IL2100", FileName = "SubstitutionsErrorCases.xml")]
+ [ExpectedWarning ("IL2101", "library", "test", FileName = "ILLink.Substitutions.xml")]
[KeptMember (".ctor()")]
class SubstitutionsErrorCases
@@ -24,6 +29,8 @@ namespace Mono.Linker.Tests.Cases.Substitutions
var instance = new SubstitutionsErrorCases ();
instance.InstanceField = 42;
IntField = 42;
+
+ var _ = new EmbeddedSubstitutionsErrorCases ();
}
[Kept]
@@ -37,5 +44,10 @@ namespace Mono.Linker.Tests.Cases.Substitutions
[Kept]
public static int IntField;
+
+ public class ReferencedFromOtherAssembly
+ {
+ public static int TestMethod () { return 42; }
+ }
}
}
diff --git a/test/Mono.Linker.Tests.Cases/Substitutions/SubstitutionsErrorCases.xml b/test/Mono.Linker.Tests.Cases/Substitutions/SubstitutionsErrorCases.xml
index 272ccbc30..f39691a20 100644
--- a/test/Mono.Linker.Tests.Cases/Substitutions/SubstitutionsErrorCases.xml
+++ b/test/Mono.Linker.Tests.Cases/Substitutions/SubstitutionsErrorCases.xml
@@ -11,4 +11,6 @@
</type>
</assembly>
<assembly fullname="NonExistentAssembly" />
+ <!-- IL2100 -->
+ <assembly fullname="*" />
</linker> \ No newline at end of file
diff --git a/test/Mono.Linker.Tests.Cases/TestFramework/CanCompileReferencesWithResources.cs b/test/Mono.Linker.Tests.Cases/TestFramework/CanCompileReferencesWithResources.cs
index b6bfba94a..bcbc70ec5 100644
--- a/test/Mono.Linker.Tests.Cases/TestFramework/CanCompileReferencesWithResources.cs
+++ b/test/Mono.Linker.Tests.Cases/TestFramework/CanCompileReferencesWithResources.cs
@@ -1,4 +1,4 @@
-using Mono.Linker.Tests.Cases.Expectations.Assertions;
+using Mono.Linker.Tests.Cases.Expectations.Assertions;
using Mono.Linker.Tests.Cases.Expectations.Metadata;
using Mono.Linker.Tests.Cases.TestFramework.Dependencies;
@@ -6,12 +6,12 @@ namespace Mono.Linker.Tests.Cases.TestFramework
{
[SetupCompileBefore ("library.dll",
new[] { "Dependencies/CanCompileReferencesWithResources_Lib1.cs" },
- resources: new[] { "Dependencies/CanCompileReferencesWithResources_Lib1.txt" })]
+ resources: new object[] { "Dependencies/CanCompileReferencesWithResources_Lib1.txt" })]
// Compile the same assembly again with another resource to get coverage on SetupCompileAfter
[SetupCompileAfter ("library.dll",
new[] { "Dependencies/CanCompileReferencesWithResources_Lib1.cs" },
- resources: new[] { "Dependencies/CanCompileReferencesWithResources_Lib1.txt", "Dependencies/CanCompileReferencesWithResources_Lib1.log" })]
+ resources: new object[] { "Dependencies/CanCompileReferencesWithResources_Lib1.txt", "Dependencies/CanCompileReferencesWithResources_Lib1.log" })]
[KeptResourceInAssembly ("library.dll", "CanCompileReferencesWithResources_Lib1.txt")]
[KeptResourceInAssembly ("library.dll", "CanCompileReferencesWithResources_Lib1.log")]
diff --git a/test/Mono.Linker.Tests.Cases/TestFramework/CanCompileReferencesWithResourcesWithCsc.cs b/test/Mono.Linker.Tests.Cases/TestFramework/CanCompileReferencesWithResourcesWithCsc.cs
index 62431c05b..845f353da 100644
--- a/test/Mono.Linker.Tests.Cases/TestFramework/CanCompileReferencesWithResourcesWithCsc.cs
+++ b/test/Mono.Linker.Tests.Cases/TestFramework/CanCompileReferencesWithResourcesWithCsc.cs
@@ -1,4 +1,4 @@
-using Mono.Linker.Tests.Cases.Expectations.Assertions;
+using Mono.Linker.Tests.Cases.Expectations.Assertions;
using Mono.Linker.Tests.Cases.Expectations.Metadata;
using Mono.Linker.Tests.Cases.TestFramework.Dependencies;
@@ -6,13 +6,13 @@ namespace Mono.Linker.Tests.Cases.TestFramework
{
[SetupCompileBefore ("library.dll",
new[] { "Dependencies/CanCompileReferencesWithResources_Lib1.cs" },
- resources: new[] { "Dependencies/CanCompileReferencesWithResources_Lib1.txt" },
+ resources: new object[] { "Dependencies/CanCompileReferencesWithResources_Lib1.txt" },
compilerToUse: "csc")]
// Compile the same assembly again with another resource to get coverage on SetupCompileAfter
[SetupCompileAfter ("library.dll",
new[] { "Dependencies/CanCompileReferencesWithResources_Lib1.cs" },
- resources: new[] { "Dependencies/CanCompileReferencesWithResources_Lib1.txt", "Dependencies/CanCompileReferencesWithResources_Lib1.log" },
+ resources: new object[] { "Dependencies/CanCompileReferencesWithResources_Lib1.txt", "Dependencies/CanCompileReferencesWithResources_Lib1.log" },
compilerToUse: "csc")]
[KeptResourceInAssembly ("library.dll", "CanCompileReferencesWithResources_Lib1.txt")]
diff --git a/test/Mono.Linker.Tests.Cases/TestFramework/CanCompileReferencesWithResourcesWithMcs.cs b/test/Mono.Linker.Tests.Cases/TestFramework/CanCompileReferencesWithResourcesWithMcs.cs
index 4b6a828d0..d166fb115 100644
--- a/test/Mono.Linker.Tests.Cases/TestFramework/CanCompileReferencesWithResourcesWithMcs.cs
+++ b/test/Mono.Linker.Tests.Cases/TestFramework/CanCompileReferencesWithResourcesWithMcs.cs
@@ -1,4 +1,4 @@
-using Mono.Linker.Tests.Cases.Expectations.Assertions;
+using Mono.Linker.Tests.Cases.Expectations.Assertions;
using Mono.Linker.Tests.Cases.Expectations.Metadata;
using Mono.Linker.Tests.Cases.TestFramework.Dependencies;
@@ -9,13 +9,13 @@ namespace Mono.Linker.Tests.Cases.TestFramework
#endif
[SetupCompileBefore ("library.dll",
new[] { "Dependencies/CanCompileReferencesWithResources_Lib1.cs" },
- resources: new[] { "Dependencies/CanCompileReferencesWithResources_Lib1.txt" },
+ resources: new object[] { "Dependencies/CanCompileReferencesWithResources_Lib1.txt" },
compilerToUse: "mcs")]
// Compile the same assembly again with another resource to get coverage on SetupCompileAfter
[SetupCompileAfter ("library.dll",
new[] { "Dependencies/CanCompileReferencesWithResources_Lib1.cs" },
- resources: new[] { "Dependencies/CanCompileReferencesWithResources_Lib1.txt", "Dependencies/CanCompileReferencesWithResources_Lib1.log" },
+ resources: new object[] { "Dependencies/CanCompileReferencesWithResources_Lib1.txt", "Dependencies/CanCompileReferencesWithResources_Lib1.log" },
compilerToUse: "mcs")]
[KeptResourceInAssembly ("library.dll", "CanCompileReferencesWithResources_Lib1.txt")]
diff --git a/test/Mono.Linker.Tests/Extensions/CecilExtensions.cs b/test/Mono.Linker.Tests/Extensions/CecilExtensions.cs
index 598d28789..f18803377 100644
--- a/test/Mono.Linker.Tests/Extensions/CecilExtensions.cs
+++ b/test/Mono.Linker.Tests/Extensions/CecilExtensions.cs
@@ -109,7 +109,7 @@ namespace Mono.Linker.Tests.Extensions
if (type.BaseType.Name == baseTypeName)
return true;
- return type.BaseType.Resolve ().DerivesFrom (baseTypeName);
+ return type.BaseType.Resolve ()?.DerivesFrom (baseTypeName) ?? false;
}
public static PropertyDefinition GetPropertyDefinition (this MethodDefinition method)
diff --git a/test/Mono.Linker.Tests/TestCasesRunner/ResultChecker.cs b/test/Mono.Linker.Tests/TestCasesRunner/ResultChecker.cs
index d4024f24f..ab7eb2da6 100644
--- a/test/Mono.Linker.Tests/TestCasesRunner/ResultChecker.cs
+++ b/test/Mono.Linker.Tests/TestCasesRunner/ResultChecker.cs
@@ -708,7 +708,7 @@ namespace Mono.Linker.Tests.TestCasesRunner
{
foreach (var typeWithRemoveInAssembly in original.AllDefinedTypes ()) {
foreach (var attr in typeWithRemoveInAssembly.CustomAttributes) {
- if (attr.AttributeType.Resolve ().Name == nameof (DependencyRecordedAttribute)) {
+ if (attr.AttributeType.Resolve ()?.Name == nameof (DependencyRecordedAttribute)) {
var expectedSource = (string) attr.ConstructorArguments[0].Value;
var expectedTarget = (string) attr.ConstructorArguments[1].Value;
var expectedMarked = (string) attr.ConstructorArguments[2].Value;
@@ -758,7 +758,7 @@ namespace Mono.Linker.Tests.TestCasesRunner
foreach (var expectedSourceMemberDefinition in original.MainModule.AllDefinedTypes ().SelectMany (t => t.AllMembers ().Append (t)).Distinct ()) {
bool foundAttributesToVerify = false;
foreach (var attr in expectedSourceMemberDefinition.CustomAttributes) {
- if (attr.AttributeType.Resolve ().Name == nameof (RecognizedReflectionAccessPatternAttribute)) {
+ if (attr.AttributeType.Resolve ()?.Name == nameof (RecognizedReflectionAccessPatternAttribute)) {
foundAttributesToVerify = true;
// Special case for default .ctor - just trigger the overall verification on the method
@@ -800,7 +800,7 @@ namespace Mono.Linker.Tests.TestCasesRunner
$"Potential patterns matching the reflection member: {Environment.NewLine}{reflectionMemberCandidates}{Environment.NewLine}" +
$"If there's no matches, try to specify just a part of the source member or reflection member name and rerun the test to get potential matches.");
}
- } else if (attr.AttributeType.Resolve ().Name == nameof (UnrecognizedReflectionAccessPatternAttribute) &&
+ } else if (attr.AttributeType.Resolve ()?.Name == nameof (UnrecognizedReflectionAccessPatternAttribute) &&
attr.ConstructorArguments[0].Type.MetadataType != MetadataType.String) {
foundAttributesToVerify = true;
string expectedSourceMember = GetFullMemberNameFromDefinition (expectedSourceMemberDefinition);
@@ -881,7 +881,7 @@ namespace Mono.Linker.Tests.TestCasesRunner
foreach (var typeToVerify in original.MainModule.AllDefinedTypes ()) {
foreach (var attr in typeToVerify.CustomAttributes) {
- if (attr.AttributeType.Resolve ().Name == nameof (VerifyAllReflectionAccessPatternsAreValidatedAttribute)) {
+ if (attr.AttributeType.Resolve ()?.Name == nameof (VerifyAllReflectionAccessPatternsAreValidatedAttribute)) {
// By now all verified recorded patterns were removed from the test recorder lists, so validate
// that there are no remaining patterns for this type.
var recognizedPatternsForType = reflectionPatternRecorder.RecognizedPatterns
@@ -1071,7 +1071,7 @@ namespace Mono.Linker.Tests.TestCasesRunner
bool IsTypeInOtherAssemblyAssertion (CustomAttribute attr)
{
- return attr.AttributeType.Resolve ().DerivesFrom (nameof (BaseInAssemblyAttribute));
+ return attr.AttributeType.Resolve ()?.DerivesFrom (nameof (BaseInAssemblyAttribute)) ?? false;
}
bool HasAttribute (ICustomAttributeProvider caProvider, string attributeName)
diff --git a/test/Mono.Linker.Tests/TestCasesRunner/SetupCompileInfo.cs b/test/Mono.Linker.Tests/TestCasesRunner/SetupCompileInfo.cs
index 7f1e92b64..da329fbb1 100644
--- a/test/Mono.Linker.Tests/TestCasesRunner/SetupCompileInfo.cs
+++ b/test/Mono.Linker.Tests/TestCasesRunner/SetupCompileInfo.cs
@@ -1,4 +1,4 @@
-using System;
+using System;
using Mono.Linker.Tests.Extensions;
namespace Mono.Linker.Tests.TestCasesRunner
@@ -9,7 +9,7 @@ namespace Mono.Linker.Tests.TestCasesRunner
public NPath[] SourceFiles;
public string[] Defines;
public string[] References;
- public NPath[] Resources;
+ public SourceAndDestinationPair[] Resources;
public string AdditionalArguments;
public string CompilerToUse;
public bool AddAsReference;
diff --git a/test/Mono.Linker.Tests/TestCasesRunner/TestCaseMetadaProvider.cs b/test/Mono.Linker.Tests/TestCasesRunner/TestCaseMetadaProvider.cs
index e1474914d..5f0e362ec 100644
--- a/test/Mono.Linker.Tests/TestCasesRunner/TestCaseMetadaProvider.cs
+++ b/test/Mono.Linker.Tests/TestCasesRunner/TestCaseMetadaProvider.cs
@@ -1,4 +1,4 @@
-using System;
+using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
@@ -329,7 +329,7 @@ namespace Mono.Linker.Tests.TestCasesRunner
SourceFiles = SourceFilesForAttributeArgument (ctorArguments[1]),
References = ((CustomAttributeArgument[]) ctorArguments[2].Value)?.Select (arg => arg.Value.ToString ()).ToArray (),
Defines = ((CustomAttributeArgument[]) ctorArguments[3].Value)?.Select (arg => arg.Value.ToString ()).ToArray (),
- Resources = ((CustomAttributeArgument[]) ctorArguments[4].Value)?.Select (arg => MakeSourceTreeFilePathAbsolute (arg.Value.ToString ())).ToArray (),
+ Resources = ResourcesForAttributeArgument (ctorArguments[4]),
AdditionalArguments = (string) ctorArguments[5].Value,
CompilerToUse = (string) ctorArguments[6].Value,
AddAsReference = ctorArguments.Count >= 8 ? (bool) ctorArguments[7].Value : true,
@@ -350,6 +350,27 @@ namespace Mono.Linker.Tests.TestCasesRunner
.ToArray ();
}
+ protected SourceAndDestinationPair[] ResourcesForAttributeArgument (CustomAttributeArgument attributeArgument)
+ {
+ return ((CustomAttributeArgument[]) attributeArgument.Value)
+ ?.Select (arg => {
+ var referenceArg = (CustomAttributeArgument) arg.Value;
+ if (referenceArg.Value is string source) {
+ var fullSource = MakeSourceTreeFilePathAbsolute (source);
+ return new SourceAndDestinationPair {
+ Source = fullSource,
+ DestinationFileName = fullSource.FileName
+ };
+ }
+ var sourceAndDestination = (CustomAttributeArgument[]) referenceArg.Value;
+ return new SourceAndDestinationPair {
+ Source = MakeSourceTreeFilePathAbsolute (sourceAndDestination[0].Value.ToString ()),
+ DestinationFileName = sourceAndDestination[1].Value.ToString ()
+ };
+ })
+ ?.ToArray ();
+ }
+
protected virtual NPath SourceFileForAttributeArgumentValue (object value)
{
if (value is TypeReference valueAsTypeRef) {
diff --git a/test/Mono.Linker.Tests/TestCasesRunner/TestCaseSandbox.cs b/test/Mono.Linker.Tests/TestCasesRunner/TestCaseSandbox.cs
index 5c8b2900f..5ad5eed4d 100644
--- a/test/Mono.Linker.Tests/TestCasesRunner/TestCaseSandbox.cs
+++ b/test/Mono.Linker.Tests/TestCasesRunner/TestCaseSandbox.cs
@@ -1,4 +1,4 @@
-using System;
+using System;
using System.Collections.Generic;
using System.IO;
using Mono.Linker.Tests.Cases.Expectations.Assertions;
@@ -113,7 +113,12 @@ namespace Mono.Linker.Tests.TestCasesRunner
compileRefInfo.SourceFiles.Copy (destination);
destination = BeforeReferenceResourceDirectoryFor (compileRefInfo.OutputName).EnsureDirectoryExists ();
- compileRefInfo.Resources?.Copy (destination);
+
+ if (compileRefInfo.Resources == null)
+ continue;
+
+ foreach (var res in compileRefInfo.Resources)
+ res.Source.FileMustExist ().Copy (destination.Combine (res.DestinationFileName));
}
foreach (var compileRefInfo in metadataProvider.GetSetupCompileAssembliesAfter ()) {
@@ -121,7 +126,12 @@ namespace Mono.Linker.Tests.TestCasesRunner
compileRefInfo.SourceFiles.Copy (destination);
destination = AfterReferenceResourceDirectoryFor (compileRefInfo.OutputName).EnsureDirectoryExists ();
- compileRefInfo.Resources?.Copy (destination);
+
+ if (compileRefInfo.Resources == null)
+ continue;
+
+ foreach (var res in compileRefInfo.Resources)
+ res.Source.FileMustExist ().Copy (destination.Combine (res.DestinationFileName));
}
}