diff options
author | Marek Safar <marek.safar@gmail.com> | 2021-03-30 15:11:02 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-30 15:11:02 +0300 |
commit | be4aa1e22006c294f6736e2479f506d2a5d6dafa (patch) | |
tree | 9898cb7e6dae06e42bb39657de4d5b6c10f08b65 /test | |
parent | 26d9440e6683b44c4db5f45b25e9c857a6563bb8 (diff) |
Improve external custom attribute annotations support (#1923)
Diffstat (limited to 'test')
13 files changed, 273 insertions, 17 deletions
diff --git a/test/Mono.Linker.Tests.Cases/DataFlow/SuppressWarningWithLinkAttributes.xml b/test/Mono.Linker.Tests.Cases/DataFlow/SuppressWarningWithLinkAttributes.xml index 57889aafd..ea59e779d 100644 --- a/test/Mono.Linker.Tests.Cases/DataFlow/SuppressWarningWithLinkAttributes.xml +++ b/test/Mono.Linker.Tests.Cases/DataFlow/SuppressWarningWithLinkAttributes.xml @@ -11,7 +11,7 @@ <argument>0</argument> </attribute> <attribute fullname="System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute"> - <argument>PublicParameterlessConstructor</argument> + <argument type="System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes">PublicParameterlessConstructor</argument> </attribute> </field> </type> diff --git a/test/Mono.Linker.Tests.Cases/DataFlow/XmlAnnotations.cs b/test/Mono.Linker.Tests.Cases/DataFlow/XmlAnnotations.cs index 40bac152b..fa71478a8 100644 --- a/test/Mono.Linker.Tests.Cases/DataFlow/XmlAnnotations.cs +++ b/test/Mono.Linker.Tests.Cases/DataFlow/XmlAnnotations.cs @@ -13,7 +13,7 @@ namespace Mono.Linker.Tests.Cases.DataFlow { [SkipKeptItemsValidation] [SetupLinkAttributesFile ("XmlAnnotations.xml")] - [ExpectedWarning ("IL2031", "System.DoesNotExistAttribute", FileName = "XmlAnnotations.xml")] + [ExpectedWarning ("IL2031", "Attribute type 'System.DoesNotExistAttribute' could not be found", FileName = "XmlAnnotations.xml")] [LogDoesNotContain ("IL2067: Mono.Linker.Tests.Cases.DataFlow.XmlAnnotations.ReadFromInstanceField():*", true)] class XmlAnnotations { diff --git a/test/Mono.Linker.Tests.Cases/DataFlow/XmlAnnotations.xml b/test/Mono.Linker.Tests.Cases/DataFlow/XmlAnnotations.xml index 2108bcebd..210c702a8 100644 --- a/test/Mono.Linker.Tests.Cases/DataFlow/XmlAnnotations.xml +++ b/test/Mono.Linker.Tests.Cases/DataFlow/XmlAnnotations.xml @@ -13,51 +13,51 @@ <argument>0</argument> </attribute> <attribute fullname="System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute"> - <argument>PublicParameterlessConstructor</argument> + <argument type="System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes">PublicParameterlessConstructor</argument> </attribute> </field> <method signature="System.Void TwoAnnotatedParameters(System.Type,System.Type)"> <parameter name="type"> <attribute fullname="System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute"> - <argument>PublicParameterlessConstructor</argument> + <argument type="System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes">PublicParameterlessConstructor</argument> </attribute> </parameter> <parameter name="type2"> <attribute fullname="System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute"> - <argument>PublicConstructors</argument> + <argument type="System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes">PublicConstructors</argument> </attribute> </parameter> </method> <method signature="SpacesBetweenParametersWrongArgument (System.Type, System.Boolean)"> <parameter name="type"> <attribute fullname="System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute"> - <argument>NonValidArgument</argument> + <argument type="System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes">0</argument> </attribute> </parameter> </method> <method signature="GenericMethod<T>(T,System.Type)"> <parameter name="type"> <attribute fullname="System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute"> - <argument>PublicParameterlessConstructor</argument> + <argument type="System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes">PublicParameterlessConstructor</argument> </attribute> </parameter> </method> <method name="ReturnConstructorsFailure"> <return> <attribute fullname="System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute"> - <argument>PublicParameterlessConstructor</argument> + <argument type="System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes">PublicParameterlessConstructor</argument> </attribute> </return> </method> <property name="PropertyWithPublicParameterlessConstructor"> <attribute fullname="System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute"> - <argument>PublicParameterlessConstructor</argument> + <argument type="System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes">PublicParameterlessConstructor</argument> </attribute> </property> <type name="NestedType"> <field name="_typeWithPublicParameterlessConstructor"> <attribute fullname="System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute"> - <argument>PublicParameterlessConstructor</argument> + <argument type="System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes">PublicParameterlessConstructor</argument> </attribute> </field> </type> diff --git a/test/Mono.Linker.Tests.Cases/DynamicDependencies/DynamicDependencyFromAttributeXml.cs b/test/Mono.Linker.Tests.Cases/DynamicDependencies/DynamicDependencyFromAttributeXml.cs index 4bee904fe..b523e34ff 100644 --- a/test/Mono.Linker.Tests.Cases/DynamicDependencies/DynamicDependencyFromAttributeXml.cs +++ b/test/Mono.Linker.Tests.Cases/DynamicDependencies/DynamicDependencyFromAttributeXml.cs @@ -22,6 +22,7 @@ namespace Mono.Linker.Tests.Cases.DynamicDependencies public static void Main () { DependencyToUnusedMethod (); + DependencyToUnusedType (); } [Kept] @@ -33,5 +34,23 @@ namespace Mono.Linker.Tests.Cases.DynamicDependencies static void UnusedMethod () { } + + [Kept] + static void DependencyToUnusedType () + { + } + + class NonUsedType + { + [Kept] + public NonUsedType () + { + } + + [Kept] + public static void PleasePreserveThisMethod () + { + } + } } } diff --git a/test/Mono.Linker.Tests.Cases/DynamicDependencies/DynamicDependencyFromAttributeXml.mono.Attributes.xml b/test/Mono.Linker.Tests.Cases/DynamicDependencies/DynamicDependencyFromAttributeXml.mono.Attributes.xml index cbf1c08ba..eb7285606 100644 --- a/test/Mono.Linker.Tests.Cases/DynamicDependencies/DynamicDependencyFromAttributeXml.mono.Attributes.xml +++ b/test/Mono.Linker.Tests.Cases/DynamicDependencies/DynamicDependencyFromAttributeXml.mono.Attributes.xml @@ -7,6 +7,12 @@ <argument>UnusedMethod</argument> </attribute> </method> + <method name="DependencyToUnusedType"> + <attribute fullname="System.Diagnostics.CodeAnalysis.DynamicDependencyAttribute" assembly="Mono.Linker.Tests.Cases.Expectations"> + <argument type="System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes, test">All</argument> + <argument type="System.Type">Mono.Linker.Tests.Cases.DynamicDependencies.DynamicDependencyFromAttributeXml/NonUsedType</argument> + </attribute> + </method> </type> </assembly> </linker>
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/DynamicDependencies/DynamicDependencyFromAttributeXml.netcore.Attributes.xml b/test/Mono.Linker.Tests.Cases/DynamicDependencies/DynamicDependencyFromAttributeXml.netcore.Attributes.xml index 3d7f8cce5..e6624a8d3 100644 --- a/test/Mono.Linker.Tests.Cases/DynamicDependencies/DynamicDependencyFromAttributeXml.netcore.Attributes.xml +++ b/test/Mono.Linker.Tests.Cases/DynamicDependencies/DynamicDependencyFromAttributeXml.netcore.Attributes.xml @@ -7,6 +7,12 @@ <argument>UnusedMethod</argument> </attribute> </method> + <method name="DependencyToUnusedType"> + <attribute fullname="System.Diagnostics.CodeAnalysis.DynamicDependencyAttribute"> + <argument type="System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes">All</argument> + <argument type="System.Type">Mono.Linker.Tests.Cases.DynamicDependencies.DynamicDependencyFromAttributeXml/NonUsedType, test</argument> + </attribute> + </method> </type> </assembly> </linker>
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/LinkAttributes/EmbeddedLinkAttributes.xml b/test/Mono.Linker.Tests.Cases/LinkAttributes/EmbeddedLinkAttributes.xml index 00916a338..b006fe2c0 100644 --- a/test/Mono.Linker.Tests.Cases/LinkAttributes/EmbeddedLinkAttributes.xml +++ b/test/Mono.Linker.Tests.Cases/LinkAttributes/EmbeddedLinkAttributes.xml @@ -3,7 +3,7 @@ <type fullname="Mono.Linker.Tests.Cases.LinkAttributes.EmbeddedLinkAttributes"> <field name="_typeWithPublicParameterlessConstructor"> <attribute fullname="System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute"> - <argument>PublicParameterlessConstructor</argument> + <argument type="System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes">PublicParameterlessConstructor</argument> </attribute> </field> </type> @@ -11,7 +11,7 @@ <type fullname="Mono.Linker.Tests.Cases.LinkAttributes.EmbeddedLinkAttributes"> <field name="_typeWithPublicFields"> <attribute fullname="System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute"> - <argument>PublicFields</argument> + <argument type="System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes">PublicFields</argument> </attribute> </field> </type> diff --git a/test/Mono.Linker.Tests.Cases/LinkAttributes/LinkAttributeErrorCases.cs b/test/Mono.Linker.Tests.Cases/LinkAttributes/LinkAttributeErrorCases.cs index 0be400309..dd05d4052 100644 --- a/test/Mono.Linker.Tests.Cases/LinkAttributes/LinkAttributeErrorCases.cs +++ b/test/Mono.Linker.Tests.Cases/LinkAttributes/LinkAttributeErrorCases.cs @@ -15,15 +15,12 @@ namespace Mono.Linker.Tests.Cases.LinkAttributes [ExpectedWarning ("IL2030", "NonExistentAssembly1", FileName = "LinkAttributeErrorCases.xml")] [ExpectedWarning ("IL2030", "MalformedAssemblyName, thisiswrong", FileName = "LinkAttributeErrorCases.xml")] [ExpectedWarning ("IL2031", "NonExistentAttribute", FileName = "LinkAttributeErrorCases.xml")] - [ExpectedWarning ("IL2054", "NonExistentEnumValue", "AttributeWithEnumParameterAttribute", "AttributeEnum", FileName = "LinkAttributeErrorCases.xml")] - [ExpectedWarning ("IL2054", "NotANumber", "AttributeWithIntParameterAttribute", "System.Int32", FileName = "LinkAttributeErrorCases.xml")] - [ExpectedWarning ("IL2022", "AttributeWithNoParametersAttribute", "1", FileName = "LinkAttributeErrorCases.xml")] + [ExpectedWarning ("IL2022", "AttributeWithNoParametersAttribute", FileName = "LinkAttributeErrorCases.xml")] [ExpectedWarning ("IL2023", "GetTypeMethod", FileName = "LinkAttributeErrorCases.xml")] [ExpectedWarning ("IL2024", "methodParameter", "MethodWithParameter", FileName = "LinkAttributeErrorCases.xml")] [ExpectedWarning ("IL2029", FileName = "LinkAttributeErrorCases.xml")] [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 diff --git a/test/Mono.Linker.Tests.Cases/LinkAttributes/TypedArguments.cs b/test/Mono.Linker.Tests.Cases/LinkAttributes/TypedArguments.cs new file mode 100644 index 000000000..c89948c37 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/LinkAttributes/TypedArguments.cs @@ -0,0 +1,123 @@ +using System; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.LinkAttributes +{ + [SetupLinkAttributesFile ("TypedArguments.xml")] + [IgnoreLinkAttributes (false)] + [SetupLinkerArgument ("--verbose")] + + [LogContains ("Assigning external custom attribute 'Mono.Linker.Tests.Cases.LinkAttributes.TypedArguments.ObjectAttribute.ObjectAttribute(Object) { args: System.Object Mono.Cecil.CustomAttributeArgument }' instance to 'System.Object Mono.Linker.Tests.Cases.LinkAttributes.TypedArguments::field1'")] + [LogContains ("Assigning external custom attribute 'Mono.Linker.Tests.Cases.LinkAttributes.TypedArguments.ObjectAttribute.ObjectAttribute(Object) { args: System.Object Mono.Cecil.CustomAttributeArgument }' instance to 'System.Object Mono.Linker.Tests.Cases.LinkAttributes.TypedArguments::field2'")] + [LogContains ("Assigning external custom attribute 'Mono.Linker.Tests.Cases.LinkAttributes.TypedArguments.EnumAttribute.EnumAttribute(TypedArgumentsEnumA) { args: Mono.Linker.Tests.Cases.LinkAttributes.TypedArgumentsEnumA 3 }' instance to 'System.Object Mono.Linker.Tests.Cases.LinkAttributes.TypedArguments::field3'")] + [LogContains ("Assigning external custom attribute 'Mono.Linker.Tests.Cases.LinkAttributes.TypedArguments.ByteAttribute.ByteAttribute(Byte) { args: System.Byte 6 }' instance to 'System.Object Mono.Linker.Tests.Cases.LinkAttributes.TypedArguments::field4'")] + [LogContains ("Assigning external custom attribute 'Mono.Linker.Tests.Cases.LinkAttributes.TypedArguments.StringAttribute.StringAttribute(String) { args: System.String str }' instance to 'System.Object Mono.Linker.Tests.Cases.LinkAttributes.TypedArguments::field5'")] + [LogContains ("Assigning external custom attribute 'Mono.Linker.Tests.Cases.LinkAttributes.TypedArguments.TypeAttribute.TypeAttribute(Type) { args: System.Type System.DateTime }' instance to 'System.Object Mono.Linker.Tests.Cases.LinkAttributes.TypedArguments::field6'")] + class TypedArguments + { + [Kept] + static object field1; + + [Kept] + static object field2; + + [Kept] + static object field3; + + [Kept] + static object field4; + + [Kept] + static object field5; + + [Kept] + static object field6; + + public static void Main () + { + field1 = null; + field2 = null; + field3 = null; + field4 = null; + field5 = null; + field6 = null; + } + + public class ObjectAttribute : Attribute + { + public ObjectAttribute (object objectValue) + { + } + + public ObjectAttribute (string stringValue) + { + } + } + + public class ByteAttribute : Attribute + { + public ByteAttribute (uint intValue) + { + } + + public ByteAttribute (byte byteValue) + { + } + + public ByteAttribute (object objectValue) + { + } + } + + public class EnumAttribute : Attribute + { + public EnumAttribute (int intValue) + { + } + + public EnumAttribute (object objectValue) + { + } + + public EnumAttribute (TypedArgumentsEnumA enumA) + { + } + + public EnumAttribute (TypedArgumentsEnumB enumB) + { + } + } + + public class StringAttribute : Attribute + { + public StringAttribute (string stringValue) + { + } + + public StringAttribute (object objectValue) + { + } + } + + public class TypeAttribute : Attribute + { + public TypeAttribute (string stringValue) + { + } + + public TypeAttribute (Type typeValue) + { + } + } + } + + enum TypedArgumentsEnumA + { + Value = 2 + } + + enum TypedArgumentsEnumB + { + } +} diff --git a/test/Mono.Linker.Tests.Cases/LinkAttributes/TypedArguments.xml b/test/Mono.Linker.Tests.Cases/LinkAttributes/TypedArguments.xml new file mode 100644 index 000000000..639bb02f8 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/LinkAttributes/TypedArguments.xml @@ -0,0 +1,40 @@ +<linker> + <assembly fullname="test"> + <type fullname="Mono.Linker.Tests.Cases.LinkAttributes.TypedArguments"> + <field name="field1"> + <attribute fullname="Mono.Linker.Tests.Cases.LinkAttributes.TypedArguments/ObjectAttribute"> + <argument type="System.Object"> + <argument type="System.String">StringValue</argument> + </argument> + </attribute> + </field> + <field name="field2"> + <attribute fullname="Mono.Linker.Tests.Cases.LinkAttributes.TypedArguments/ObjectAttribute"> + <argument type="System.Object"> + <argument type="System.Char">9</argument> + </argument> + </attribute> + </field> + <field name="field3"> + <attribute fullname="Mono.Linker.Tests.Cases.LinkAttributes.TypedArguments/EnumAttribute"> + <argument type="Mono.Linker.Tests.Cases.LinkAttributes.TypedArgumentsEnumA">3</argument> + </attribute> + </field> + <field name="field4"> + <attribute fullname="Mono.Linker.Tests.Cases.LinkAttributes.TypedArguments/ByteAttribute"> + <argument type="System.Byte">6</argument> + </attribute> + </field> + <field name="field5"> + <attribute fullname="Mono.Linker.Tests.Cases.LinkAttributes.TypedArguments/StringAttribute"> + <argument type="System.String">str</argument> + </attribute> + </field> + <field name="field6"> + <attribute fullname="Mono.Linker.Tests.Cases.LinkAttributes.TypedArguments/TypeAttribute"> + <argument type="System.Type">System.DateTime</argument> + </attribute> + </field> + </type> + </assembly> +</linker> diff --git a/test/Mono.Linker.Tests.Cases/LinkAttributes/TypedArgumentsErrors.cs b/test/Mono.Linker.Tests.Cases/LinkAttributes/TypedArgumentsErrors.cs new file mode 100644 index 000000000..44513d83e --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/LinkAttributes/TypedArgumentsErrors.cs @@ -0,0 +1,35 @@ +using System; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.LinkAttributes +{ + [SetupLinkAttributesFile ("TypedArgumentsErrors.xml")] + [IgnoreLinkAttributes (false)] + [NoLinkedOutput] + + [LogContains ("The type 'System.NoOBJECT' used with attribute value 'str' could not be found")] + [LogContains ("Cannot convert value 'str' to type 'System.Int32'")] + [LogContains ("Custom attribute argument for 'System.Object' requires nested 'argument' node")] + [LogContains ("The type 'System.Bar' used with attribute value 'str4' could not be found")] + [LogContains ("Could not resolve custom attribute type value 'str5'")] + class TypedArgumentsErrors + { + static object field; + + public static void Main () + { + } + + public class ObjectAttribute : Attribute + { + public ObjectAttribute (object objectValue) + { + } + + public ObjectAttribute (string stringValue) + { + } + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/LinkAttributes/TypedArgumentsErrors.xml b/test/Mono.Linker.Tests.Cases/LinkAttributes/TypedArgumentsErrors.xml new file mode 100644 index 000000000..e71703e19 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/LinkAttributes/TypedArgumentsErrors.xml @@ -0,0 +1,31 @@ +<linker> + <assembly fullname="test"> + <type fullname="Mono.Linker.Tests.Cases.LinkAttributes.TypedArgumentsErrors"> + <field name="field"> + <attribute fullname="Mono.Linker.Tests.Cases.LinkAttributes.TypedArgumentsErrors/ObjectAttribute"> + <argument type="System.NoOBJECT">str</argument> + </attribute> + </field> + <field name="field"> + <attribute fullname="Mono.Linker.Tests.Cases.LinkAttributes.TypedArgumentsErrors/ObjectAttribute"> + <argument type="System.Int32">str</argument> + </attribute> + </field> + <field name="field"> + <attribute fullname="Mono.Linker.Tests.Cases.LinkAttributes.TypedArgumentsErrors/ObjectAttribute"> + <argument type="System.Object">str</argument> + </attribute> + </field> + <field name="field"> + <attribute fullname="Mono.Linker.Tests.Cases.LinkAttributes.TypedArgumentsErrors/ObjectAttribute"> + <argument type="System.Bar">str4</argument> + </attribute> + </field> + <field name="field"> + <attribute fullname="Mono.Linker.Tests.Cases.LinkAttributes.TypedArgumentsErrors/ObjectAttribute"> + <argument type="System.Type">str5</argument> + </attribute> + </field> + </type> + </assembly> +</linker> diff --git a/test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresUnreferencedCodeCapability.cs b/test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresUnreferencedCodeCapability.cs index 68e6df6f7..7e3e008d4 100644 --- a/test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresUnreferencedCodeCapability.cs +++ b/test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresUnreferencedCodeCapability.cs @@ -156,7 +156,6 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability class TestType { } [ExpectedWarning ("IL2026", "--MethodWithDuplicateRequiresAttribute--")] - [LogDoesNotContain ("Message for MethodWithDuplicateRequiresAttribute from link attributes XML")] static void TestDuplicateRequiresAttribute () { MethodWithDuplicateRequiresAttribute (); |