diff options
Diffstat (limited to 'test/Mono.Linker.Tests.Cases')
-rw-r--r-- | test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresOnClass.cs | 60 |
1 files changed, 58 insertions, 2 deletions
diff --git a/test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresOnClass.cs b/test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresOnClass.cs index 64fed96f2..9f1dc8b45 100644 --- a/test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresOnClass.cs +++ b/test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresOnClass.cs @@ -39,6 +39,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability } [RequiresUnreferencedCode ("Message for --ClassWithRequires--")] + [RequiresDynamicCode ("Message for --ClassWithRequires--")] class ClassWithRequires { public static object Instance; @@ -58,6 +59,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability // This warning doesn't get suppressed since the declaring type NestedClass is not annotated with Requires [ExpectedWarning ("IL2026", "RequiresOnClass.RequiresOnMethod.MethodWithRequires()", "MethodWithRequires")] + [ExpectedWarning ("IL3050", "RequiresOnClass.RequiresOnMethod.MethodWithRequires()", "MethodWithRequires", ProducedBy = ProducedBy.Analyzer)] public static void CallMethodWithRequires () => RequiresOnMethod.MethodWithRequires (); } @@ -86,6 +88,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability class RequiresOnMethod { [RequiresUnreferencedCode ("MethodWithRequires")] + [RequiresDynamicCode ("MethodWithRequires")] public static void MethodWithRequires () { } } @@ -134,6 +137,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability } [RequiresUnreferencedCode ("Message for --StaticCtor--")] + [RequiresDynamicCode ("Message for --StaticCtor--")] class StaticCtor { static StaticCtor () @@ -142,12 +146,14 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability } [ExpectedWarning ("IL2026", "RequiresOnClass.StaticCtor.StaticCtor()", "Message for --StaticCtor--")] + [ExpectedWarning ("IL3050", "RequiresOnClass.StaticCtor.StaticCtor()", "Message for --StaticCtor--", ProducedBy = ProducedBy.Analyzer)] static void TestStaticCctorRequires () { _ = new StaticCtor (); } [RequiresUnreferencedCode ("Message for --StaticCtorTriggeredByFieldAccess--")] + [RequiresDynamicCode ("Message for --StaticCtorTriggeredByFieldAccess--")] class StaticCtorTriggeredByFieldAccess { static StaticCtorTriggeredByFieldAccess () @@ -159,42 +165,49 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability } [ExpectedWarning ("IL2026", "StaticCtorTriggeredByFieldAccess.field", "Message for --StaticCtorTriggeredByFieldAccess--")] + [ExpectedWarning ("IL3050", "StaticCtorTriggeredByFieldAccess.field", "Message for --StaticCtorTriggeredByFieldAccess--", ProducedBy = ProducedBy.Analyzer)] static void TestStaticCtorMarkingIsTriggeredByFieldAccessWrite () { StaticCtorTriggeredByFieldAccess.field = 1; } [ExpectedWarning ("IL2026", "StaticCtorTriggeredByFieldAccess.field", "Message for --StaticCtorTriggeredByFieldAccess--")] + [ExpectedWarning ("IL3050", "StaticCtorTriggeredByFieldAccess.field", "Message for --StaticCtorTriggeredByFieldAccess--", ProducedBy = ProducedBy.Analyzer)] static void TestStaticCtorMarkingTriggeredOnSecondAccessWrite () { StaticCtorTriggeredByFieldAccess.field = 2; } [RequiresUnreferencedCode ("--TestStaticRequiresFieldAccessSuppressedByRequiresOnMethod_Inner--")] + [RequiresDynamicCode ("--TestStaticRequiresFieldAccessSuppressedByRequiresOnMethod_Inner--")] static void TestStaticRequiresFieldAccessSuppressedByRequiresOnMethod_Inner () { StaticCtorTriggeredByFieldAccess.field = 3; } [UnconditionalSuppressMessage ("test", "IL2026")] + [UnconditionalSuppressMessage ("test", "IL3050")] static void TestStaticRequiresFieldAccessSuppressedByRequiresOnMethod () { TestStaticRequiresFieldAccessSuppressedByRequiresOnMethod_Inner (); } [RequiresUnreferencedCode ("Message for --StaticCCtorTriggeredByFieldAccessRead--")] + [RequiresDynamicCode ("Message for --StaticCCtorTriggeredByFieldAccessRead--")] class StaticCCtorTriggeredByFieldAccessRead { public static int field = 42; } [ExpectedWarning ("IL2026", "StaticCCtorTriggeredByFieldAccessRead.field", "Message for --StaticCCtorTriggeredByFieldAccessRead--")] + [ExpectedWarning ("IL3050", "StaticCCtorTriggeredByFieldAccessRead.field", "Message for --StaticCCtorTriggeredByFieldAccessRead--", ProducedBy = ProducedBy.Analyzer)] static void TestStaticCtorMarkingIsTriggeredByFieldAccessRead () { var _ = StaticCCtorTriggeredByFieldAccessRead.field; } [RequiresUnreferencedCode ("Message for --StaticCtorTriggeredByCtorCalls--")] + [RequiresDynamicCode ("Message for --StaticCtorTriggeredByCtorCalls--")] class StaticCtorTriggeredByCtorCalls { static StaticCtorTriggeredByCtorCalls () @@ -207,18 +220,21 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability } [ExpectedWarning ("IL2026", "StaticCtorTriggeredByCtorCalls.StaticCtorTriggeredByCtorCalls()")] + [ExpectedWarning ("IL3050", "StaticCtorTriggeredByCtorCalls.StaticCtorTriggeredByCtorCalls()", ProducedBy = ProducedBy.Analyzer)] static void TestStaticCtorTriggeredByCtorCall () { new StaticCtorTriggeredByCtorCalls (); } [RequiresUnreferencedCode ("Message for --ClassWithInstanceField--")] + [RequiresDynamicCode ("Message for --ClassWithInstanceField--")] class ClassWithInstanceField { public int field = 42; } [ExpectedWarning ("IL2026", "ClassWithInstanceField.ClassWithInstanceField()")] + [ExpectedWarning ("IL3050", "ClassWithInstanceField.ClassWithInstanceField()", ProducedBy = ProducedBy.Analyzer)] static void TestInstanceFieldCallDontWarn () { ClassWithInstanceField instance = new ClassWithInstanceField (); @@ -226,6 +242,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability } [RequiresUnreferencedCode ("Message for --StaticCtorTriggeredByMethodCall2--")] + [RequiresDynamicCode ("Message for --StaticCtorTriggeredByMethodCall2--")] class StaticCtorTriggeredByMethodCall2 { static StaticCtorTriggeredByMethodCall2 () @@ -244,6 +261,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability } [RequiresUnreferencedCode ("Message for --DerivedWithRequires--")] + [RequiresDynamicCode ("Message for --DerivedWithRequires--")] private class DerivedWithRequires : ClassWithoutRequires { public static void StaticMethodInInheritedClass () { } @@ -255,6 +273,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability } [RequiresUnreferencedCode ("Message for --DerivedWithRequires2--")] + [RequiresDynamicCode ("Message for --DerivedWithRequires2--")] private class DerivedWithRequires2 : ClassWithRequires { public static void StaticMethodInInheritedClass () { } @@ -271,22 +290,26 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability class BaseWithoutRequiresOnType { [RequiresUnreferencedCode ("RUC")] + [RequiresDynamicCode ("RDC")] public virtual void Method () { } } [RequiresUnreferencedCode ("RUC")] + [RequiresDynamicCode ("RDC")] class DerivedWithRequiresOnType : BaseWithoutRequiresOnType { public override void Method () { } } [RequiresUnreferencedCode ("RUC")] + [RequiresDynamicCode ("RDC")] class BaseWithRequiresOnType { public virtual void Method () { } } [RequiresUnreferencedCode ("RUC")] + [RequiresDynamicCode ("RDC")] class DerivedWithoutRequiresOnType : BaseWithRequiresOnType { public override void Method () { } @@ -295,16 +318,19 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability public interface InterfaceWithoutRequires { [RequiresUnreferencedCode ("RUC")] + [RequiresDynamicCode ("RDC")] static int Method () { return 0; } [RequiresUnreferencedCode ("RUC")] + [RequiresDynamicCode ("RDC")] int Method (int a); } [RequiresUnreferencedCode ("RUC")] + [RequiresDynamicCode ("RDC")] class ImplementationWithRequiresOnType : InterfaceWithoutRequires { public static int Method () @@ -319,12 +345,14 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability } [ExpectedWarning ("IL2026", "RequiresOnClass.ClassWithRequires.StaticMethod()", "--ClassWithRequires--")] + [ExpectedWarning ("IL3050", "RequiresOnClass.ClassWithRequires.StaticMethod()", "--ClassWithRequires--", ProducedBy = ProducedBy.Analyzer)] static void TestRequiresInClassAccessedByStaticMethod () { ClassWithRequires.StaticMethod (); } [ExpectedWarning ("IL2026", "RequiresOnClass.ClassWithRequires", "--ClassWithRequires--")] + [ExpectedWarning ("IL3050", "RequiresOnClass.ClassWithRequires", "--ClassWithRequires--", ProducedBy = ProducedBy.Analyzer)] static void TestRequiresInClassAccessedByCctor () { var classObject = new ClassWithRequires (); @@ -336,9 +364,12 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability } [ExpectedWarning ("IL2026", "RequiresOnClass.ClassWithRequires.StaticMethod()", "--ClassWithRequires--")] + [ExpectedWarning ("IL3050", "RequiresOnClass.ClassWithRequires.StaticMethod()", "--ClassWithRequires--", ProducedBy = ProducedBy.Analyzer)] // Although we suppress the warning from RequiresOnMethod.MethodWithRequires () we still get a warning because we call CallRequiresMethod() which is an static method on a type with RUC [ExpectedWarning ("IL2026", "RequiresOnClass.ClassWithRequires.CallMethodWithRequires()", "--ClassWithRequires--")] + [ExpectedWarning ("IL3050", "RequiresOnClass.ClassWithRequires.CallMethodWithRequires()", "--ClassWithRequires--", ProducedBy = ProducedBy.Analyzer)] [ExpectedWarning ("IL2026", "ClassWithRequires.Instance", "--ClassWithRequires--")] + [ExpectedWarning ("IL3050", "ClassWithRequires.Instance", "--ClassWithRequires--", ProducedBy = ProducedBy.Analyzer)] static void TestRequiresOnBaseButNotOnDerived () { DerivedWithoutRequires.StaticMethodInInheritedClass (); @@ -353,6 +384,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability } [ExpectedWarning ("IL2026", "RequiresOnClass.DerivedWithRequires.StaticMethodInInheritedClass()", "--DerivedWithRequires--")] + [ExpectedWarning ("IL3050", "RequiresOnClass.DerivedWithRequires.StaticMethodInInheritedClass()", "--DerivedWithRequires--", ProducedBy = ProducedBy.Analyzer)] static void TestRequiresOnDerivedButNotOnBase () { DerivedWithRequires.StaticMethodInInheritedClass (); @@ -362,7 +394,9 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability } [ExpectedWarning ("IL2026", "RequiresOnClass.DerivedWithRequires2.StaticMethodInInheritedClass()", "--DerivedWithRequires2--")] + [ExpectedWarning ("IL3050", "RequiresOnClass.DerivedWithRequires2.StaticMethodInInheritedClass()", "--DerivedWithRequires2--", ProducedBy = ProducedBy.Analyzer)] [ExpectedWarning ("IL2026", "RequiresOnClass.ClassWithRequires.StaticMethod()", "--ClassWithRequires--")] + [ExpectedWarning ("IL3050", "RequiresOnClass.ClassWithRequires.StaticMethod()", "--ClassWithRequires--", ProducedBy = ProducedBy.Analyzer)] static void TestRequiresOnBaseAndDerived () { DerivedWithRequires2.StaticMethodInInheritedClass (); @@ -373,6 +407,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability // TODO: Parameter signature differs between linker and analyzer [ExpectedWarning ("IL2026", "RequiresOnClass.ClassWithRequires.TestSuppressions(", "Type[])")] + [ExpectedWarning ("IL3050", "RequiresOnClass.ClassWithRequires.TestSuppressions(", "Type[])", ProducedBy = ProducedBy.Analyzer)] static void TestSuppressionsOnClass () { ClassWithRequires.TestSuppressions (new[] { typeof (ClassWithRequires) }); @@ -380,12 +415,14 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability } [RequiresUnreferencedCode ("--StaticMethodOnRequiresTypeSuppressedByRequiresOnMethod--")] + [RequiresDynamicCode ("--StaticMethodOnRequiresTypeSuppressedByRequiresOnMethod--")] static void StaticMethodOnRequiresTypeSuppressedByRequiresOnMethod () { DerivedWithRequires.StaticMethodInInheritedClass (); } [UnconditionalSuppressMessage ("test", "IL2026")] + [UnconditionalSuppressMessage ("test", "IL3050")] static void TestStaticMethodOnRequiresTypeSuppressedByRequiresOnMethod () { StaticMethodOnRequiresTypeSuppressedByRequiresOnMethod (); @@ -404,6 +441,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability } [RequiresUnreferencedCode ("--MemberTypesWithRequires--")] + [RequiresDynamicCode ("--MemberTypesWithRequires--")] class MemberTypesWithRequires { public static int field; @@ -418,8 +456,11 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability } [ExpectedWarning ("IL2026", "MemberTypesWithRequires.field")] + [ExpectedWarning ("IL3050", "MemberTypesWithRequires.field", ProducedBy = ProducedBy.Analyzer)] [ExpectedWarning ("IL2026", "MemberTypesWithRequires.Property.set")] + [ExpectedWarning ("IL3050", "MemberTypesWithRequires.Property.set", ProducedBy = ProducedBy.Analyzer)] [ExpectedWarning ("IL2026", "MemberTypesWithRequires.Event.remove")] + [ExpectedWarning ("IL3050", "MemberTypesWithRequires.Event.remove", ProducedBy = ProducedBy.Analyzer)] static void TestOtherMemberTypesWithRequires () { MemberTypesWithRequires.field = 1; @@ -437,7 +478,6 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability class ReflectionAccessOnMethod { - // Analyzer still dont understand RUC on type [ExpectedWarning ("IL2026", "BaseWithoutRequiresOnType.Method()")] [ExpectedWarning ("IL2026", "BaseWithoutRequiresOnType.Method()")] [ExpectedWarning ("IL2026", "InterfaceWithoutRequires.Method(Int32)")] @@ -445,7 +485,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability [ExpectedWarning ("IL2026", "ImplementationWithRequiresOnType.Method()")] static void TestDAMAccess () { - // Warns because BaseWithoutRequiresOnType.Method as RUC on the method + // Warns because BaseWithoutRequiresOnType.Method has Requires on the method typeof (BaseWithoutRequiresOnType).RequiresPublicMethods (); // Doesn't warn because DerivedWithRequiresOnType doesn't have any static methods @@ -493,6 +533,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability class ReflectionAccessOnCtor { [RequiresUnreferencedCode ("--BaseWithRequires--")] + [RequiresDynamicCode ("--BaseWithRequires--")] class BaseWithRequires { public BaseWithRequires () { } @@ -506,6 +547,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability } [RequiresUnreferencedCode ("--DerivedWithRequiresOnBaseWithRequires--")] + [RequiresDynamicCode ("--DerivedWithRequiresOnBaseWithRequires--")] class DerivedWithRequiresOnBaseWithRequires : BaseWithRequires { // No warning - suppressed by the Requires on this type @@ -515,6 +557,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability class BaseWithoutRequires { } [RequiresUnreferencedCode ("--DerivedWithRequiresOnBaseWithout--")] + [RequiresDynamicCode ("--DerivedWithRequiresOnBaseWithout--")] class DerivedWithRequiresOnBaseWithoutRequires : BaseWithoutRequires { public DerivedWithRequiresOnBaseWithoutRequires () { } @@ -561,6 +604,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability class ReflectionAccessOnField { [RequiresUnreferencedCode ("--WithRequires--")] + [RequiresDynamicCode ("--WithRequires--")] class WithRequires { public int InstanceField; @@ -569,6 +613,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability } [RequiresUnreferencedCode ("--WithRequiresOnlyInstanceFields--")] + [RequiresDynamicCode ("--WithRequiresOnlyInstanceFields--")] class WithRequiresOnlyInstanceFields { public int InstanceField; @@ -581,6 +626,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability } [RequiresUnreferencedCode ("--DerivedWithRequires--")] + [RequiresDynamicCode ("--DerivedWithRequires--")] class DerivedWithRequires : WithRequires { public static int DerivedStaticField; @@ -626,6 +672,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability } [RequiresUnreferencedCode ("This class is dangerous")] + [RequiresDynamicCode ("This class is dangerous")] class BaseForDAMAnnotatedClass { public static int baseField; @@ -633,6 +680,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability [DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.NonPublicFields)] [RequiresUnreferencedCode ("This class is dangerous")] + [RequiresDynamicCode ("This class is dangerous")] [ExpectedWarning ("IL2113", "BaseForDAMAnnotatedClass.baseField", ProducedBy = ProducedBy.Trimmer)] class DAMAnnotatedClass : BaseForDAMAnnotatedClass { @@ -663,6 +711,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability // So for now keeping just a very simple test [RequiresUnreferencedCode ("--WithRequires--")] + [RequiresDynamicCode ("--WithRequires--")] class WithRequires { // These should be reported only in TestDirectReflectionAccess @@ -693,6 +742,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability class ReflectionAccessOnProperties { [RequiresUnreferencedCode ("--WithRequires--")] + [RequiresDynamicCode ("--WithRequires--")] class WithRequires { public int InstanceProperty { get; set; } @@ -701,6 +751,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability } [RequiresUnreferencedCode ("--WithRequiresOnlyInstanceProperties--")] + [RequiresDynamicCode ("--WithRequiresOnlyInstanceProperties--")] class WithRequiresOnlyInstanceProperties { public int InstnaceProperty { get; set; } @@ -713,6 +764,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability } [RequiresUnreferencedCode ("--DerivedWithRequires--")] + [RequiresDynamicCode ("--DerivedWithRequires--")] class DerivedWithRequires : WithRequires { public static int DerivedStaticProperty { get; set; } @@ -770,6 +822,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability } [RequiresUnreferencedCode ("This class is dangerous")] + [RequiresDynamicCode ("This class is dangerous")] class BaseForDAMAnnotatedClass { public static int baseProperty { get; set; } @@ -777,6 +830,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability [DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicProperties | DynamicallyAccessedMemberTypes.NonPublicProperties)] [RequiresUnreferencedCode ("This class is dangerous")] + [RequiresDynamicCode ("This class is dangerous")] [ExpectedWarning ("IL2113", "BaseForDAMAnnotatedClass.baseProperty.get", ProducedBy = ProducedBy.Trimmer)] [ExpectedWarning ("IL2113", "BaseForDAMAnnotatedClass.baseProperty.set", ProducedBy = ProducedBy.Trimmer)] class DAMAnnotatedClass : BaseForDAMAnnotatedClass @@ -811,6 +865,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability } [RequiresUnreferencedCode ("The attribute is dangerous")] + [RequiresDynamicCode ("The attribute is dangerous")] public class AttributeWithRequires : Attribute { public static int field; @@ -826,6 +881,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability [AttributeWithRequires (PropertyOnAttribute = 42)] [ExpectedWarning ("IL2026", "AttributeWithRequires.AttributeWithRequires()")] + [ExpectedWarning ("IL3050", "AttributeWithRequires.AttributeWithRequires()", ProducedBy = ProducedBy.Analyzer)] static void KeepFieldOnAttribute () { } } } |