diff options
Diffstat (limited to 'test/Mono.Linker.Tests.Cases/DataFlow/GetTypeDataFlow.cs')
-rw-r--r-- | test/Mono.Linker.Tests.Cases/DataFlow/GetTypeDataFlow.cs | 79 |
1 files changed, 28 insertions, 51 deletions
diff --git a/test/Mono.Linker.Tests.Cases/DataFlow/GetTypeDataFlow.cs b/test/Mono.Linker.Tests.Cases/DataFlow/GetTypeDataFlow.cs index 5dc272f0f..289916c27 100644 --- a/test/Mono.Linker.Tests.Cases/DataFlow/GetTypeDataFlow.cs +++ b/test/Mono.Linker.Tests.Cases/DataFlow/GetTypeDataFlow.cs @@ -6,12 +6,14 @@ using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Text; using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Helpers; namespace Mono.Linker.Tests.Cases.DataFlow { // Note: this test's goal is to validate that the product correctly reports unrecognized patterns - // - so the main validation is done by the UnrecognizedReflectionAccessPattern attributes. + // - so the main validation is done by the ExpectedWarning attributes. [SkipKeptItemsValidation] + [ExpectedNoWarnings] public class GetTypeDataFlow { public static void Main () @@ -35,59 +37,59 @@ namespace Mono.Linker.Tests.Cases.DataFlow // Type.GetType over two params } - [UnrecognizedReflectionAccessPattern (typeof (GetTypeDataFlow), nameof (RequirePublicConstructors), new Type[] { typeof (Type) }, messageCode: "IL2072")] - [UnrecognizedReflectionAccessPattern (typeof (GetTypeDataFlow), nameof (RequireNonPublicConstructors), new Type[] { typeof (Type) }, messageCode: "IL2072")] + [ExpectedWarning ("IL2072", nameof (DataFlowTypeExtensions.RequiresPublicConstructors))] + [ExpectedWarning ("IL2072", nameof (DataFlowTypeExtensions.RequiresNonPublicConstructors))] static void TestPublicParameterlessConstructor () { Type type = Type.GetType (GetStringTypeWithPublicParameterlessConstructor ()); - RequirePublicParameterlessConstructor (type); - RequirePublicConstructors (type); - RequireNonPublicConstructors (type); - RequireNothing (type); + type.RequiresPublicParameterlessConstructor (); + type.RequiresPublicConstructors (); + type.RequiresNonPublicConstructors (); + type.RequiresNone (); } - [UnrecognizedReflectionAccessPattern (typeof (GetTypeDataFlow), nameof (RequireNonPublicConstructors), new Type[] { typeof (Type) }, messageCode: "IL2072")] + [ExpectedWarning ("IL2072", nameof (DataFlowTypeExtensions.RequiresNonPublicConstructors))] static void TestPublicConstructors () { Type type = Type.GetType (GetStringTypeWithPublicConstructors ()); - RequirePublicParameterlessConstructor (type); - RequirePublicConstructors (type); - RequireNonPublicConstructors (type); - RequireNothing (type); + type.RequiresPublicParameterlessConstructor (); + type.RequiresPublicConstructors (); + type.RequiresNonPublicConstructors (); + type.RequiresNone (); } - [UnrecognizedReflectionAccessPattern (typeof (GetTypeDataFlow), nameof (RequirePublicParameterlessConstructor), new Type[] { typeof (Type) }, messageCode: "IL2072")] - [UnrecognizedReflectionAccessPattern (typeof (GetTypeDataFlow), nameof (RequirePublicConstructors), new Type[] { typeof (Type) }, messageCode: "IL2072")] + [ExpectedWarning ("IL2072", nameof (DataFlowTypeExtensions.RequiresPublicParameterlessConstructor))] + [ExpectedWarning ("IL2072", nameof (DataFlowTypeExtensions.RequiresPublicConstructors))] static void TestConstructors () { Type type = Type.GetType (GetStringTypeWithNonPublicConstructors ()); - RequirePublicParameterlessConstructor (type); - RequirePublicConstructors (type); - RequireNonPublicConstructors (type); - RequireNothing (type); + type.RequiresPublicParameterlessConstructor (); + type.RequiresPublicConstructors (); + type.RequiresNonPublicConstructors (); + type.RequiresNone (); } - [UnrecognizedReflectionAccessPattern (typeof (Type), nameof (GetType), new Type[] { typeof (string) }, messageCode: "IL2057")] + [ExpectedWarning ("IL2057", nameof (GetType))] static void TestUnknownType () { Type type = Type.GetType (GetStringUnkownType ()); } - [UnrecognizedReflectionAccessPattern (typeof (GetTypeDataFlow), nameof (RequirePublicConstructors), new Type[] { typeof (Type) }, messageCode: "IL2072")] + [ExpectedWarning ("IL2072", nameof (DataFlowTypeExtensions.RequiresPublicConstructors))] static void TestTypeNameFromParameter ( [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] string typeName) { - RequirePublicConstructors (Type.GetType (typeName)); + Type.GetType (typeName).RequiresPublicConstructors (); } [DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] static string _typeNameWithPublicParameterlessConstructor; - [UnrecognizedReflectionAccessPattern (typeof (GetTypeDataFlow), nameof (RequirePublicConstructors), new Type[] { typeof (Type) }, messageCode: "IL2072")] + [ExpectedWarning ("IL2072", nameof (DataFlowTypeExtensions.RequiresPublicConstructors))] static void TestTypeNameFromField () { - RequirePublicConstructors (Type.GetType (_typeNameWithPublicParameterlessConstructor)); + Type.GetType (_typeNameWithPublicParameterlessConstructor).RequiresPublicConstructors (); } static int _switchOnField; @@ -113,16 +115,13 @@ namespace Mono.Linker.Tests.Cases.DataFlow Type.GetType (typeName); } - [RecognizedReflectionAccessPattern] static void TestStringEmpty () { Type.GetType (string.Empty); } - [UnrecognizedReflectionAccessPattern (typeof (GetTypeDataFlow), nameof (RequireNonPublicConstructors), new Type[] { typeof (Type) }, - messageCode: "IL2072", message: new string[] { "GetType" })] - [UnrecognizedReflectionAccessPattern (typeof (Type), nameof (Type.GetType), new Type[] { typeof (string) }, - messageCode: "IL2057", message: new string[] { "System.Type.GetType(String)" })] + [ExpectedWarning ("IL2072", nameof (DataFlowTypeExtensions.RequiresNonPublicConstructors), nameof (Type.GetType))] + [ExpectedWarning ("IL2057", "System.Type.GetType(String)")] static void TestMultipleMixedValues () { string typeName = null; @@ -141,29 +140,7 @@ namespace Mono.Linker.Tests.Cases.DataFlow break; } - RequireNonPublicConstructors (Type.GetType (typeName)); - } - - private static void RequirePublicParameterlessConstructor ( - [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] - Type type) - { - } - - private static void RequirePublicConstructors ( - [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] - Type type) - { - } - - private static void RequireNonPublicConstructors ( - [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.NonPublicConstructors)] - Type type) - { - } - - private static void RequireNothing (Type type) - { + Type.GetType (typeName).RequiresNonPublicConstructors (); } [return: DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] |