diff options
author | Tlakaelel Axayakatl Ceja <tlakaelel.ceja@microsoft.com> | 2022-02-24 14:12:38 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-24 14:12:38 +0300 |
commit | 6a82f4fc670a8123e2029070910729f38a32ada1 (patch) | |
tree | 98072ca88f149225808a6195dad80538b66af476 /test/Mono.Linker.Tests.Cases | |
parent | fb64018413f8ebaa3187881b933c43cbad52a83e (diff) |
Add condition to bypass nameof usage since it will not invoke the member and instead will be translated to load an string (#2649)
Add tests
Fix ExpectedWarnings from disabled intrinsics that were producing warnings from accessing fields in a nameof call
Diffstat (limited to 'test/Mono.Linker.Tests.Cases')
-rw-r--r-- | test/Mono.Linker.Tests.Cases/RequiresCapability/BasicRequires.cs | 6 | ||||
-rw-r--r-- | test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresOnClass.cs | 17 |
2 files changed, 18 insertions, 5 deletions
diff --git a/test/Mono.Linker.Tests.Cases/RequiresCapability/BasicRequires.cs b/test/Mono.Linker.Tests.Cases/RequiresCapability/BasicRequires.cs index 972e28c49..6cfeb360d 100644 --- a/test/Mono.Linker.Tests.Cases/RequiresCapability/BasicRequires.cs +++ b/test/Mono.Linker.Tests.Cases/RequiresCapability/BasicRequires.cs @@ -30,6 +30,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability TestRequiresOnPropertyGetterAndSetter (); TestThatTrailingPeriodIsAddedToMessage (); TestThatTrailingPeriodIsNotDuplicatedInWarningMessage (); + TestRequiresFromNameOf (); OnEventMethod.Test (); RequiresOnGenerics.Test (); } @@ -137,6 +138,11 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability WarningMessageEndsWithPeriod (); } + static void TestRequiresFromNameOf () + { + _ = nameof (BasicRequires.RequiresWithMessageOnly); + } + class OnEventMethod { [ExpectedWarning ("IL2026", "--EventToTestRemove.remove--", ProducedBy = ProducedBy.Trimmer)] diff --git a/test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresOnClass.cs b/test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresOnClass.cs index 639846b80..2b7bfae37 100644 --- a/test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresOnClass.cs +++ b/test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresOnClass.cs @@ -29,6 +29,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability TestStaticMethodOnRequiresTypeSuppressedByRequiresOnMethod (); TestStaticConstructorCalls (); TestOtherMemberTypesWithRequires (); + TestNameOfDoesntWarn (); ReflectionAccessOnMethod.Test (); ReflectionAccessOnCtor.Test (); ReflectionAccessOnField.Test (); @@ -426,6 +427,14 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability MemberTypesWithRequires.Event -= null; } + static void TestNameOfDoesntWarn () + { + _ = nameof (ClassWithRequires.StaticMethod); + _ = nameof (MemberTypesWithRequires.field); + _ = nameof (MemberTypesWithRequires.Property); + _ = nameof (MemberTypesWithRequires.Event); + } + class ReflectionAccessOnMethod { // Analyzer still dont understand RUC on type @@ -591,11 +600,9 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability typeof (DerivedWithRequires).RequiresPublicFields (); } - [ExpectedWarning ("IL2026", "WithRequires.StaticField")] - // Analyzer does not recognize the binding flags + [ExpectedWarning ("IL2026", "WithRequires.StaticField", ProducedBy = ProducedBy.Trimmer)] [ExpectedWarning ("IL2026", "WithRequires.PrivateStaticField", ProducedBy = ProducedBy.Trimmer)] - [ExpectedWarning ("IL2026", "DerivedWithRequires.DerivedStaticField")] - [ExpectedWarning ("IL2026", "DerivedWithRequires.DerivedStaticField", ProducedBy = ProducedBy.Analyzer)] + [ExpectedWarning ("IL2026", "DerivedWithRequires.DerivedStaticField", ProducedBy = ProducedBy.Trimmer)] static void TestDirectReflectionAccess () { typeof (WithRequires).GetField (nameof (WithRequires.StaticField)); @@ -606,7 +613,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability typeof (DerivedWithRequires).GetField (nameof (DerivedWithRequires.DerivedStaticField)); } - [ExpectedWarning ("IL2026", "WithRequires.StaticField")] + [ExpectedWarning ("IL2026", "WithRequires.StaticField", ProducedBy = ProducedBy.Trimmer)] [ExpectedWarning ("IL2026", "WithRequires.StaticField", ProducedBy = ProducedBy.Trimmer)] [ExpectedWarning ("IL2026", "WithRequires.StaticField", ProducedBy = ProducedBy.Trimmer)] [DynamicDependency (nameof (WithRequires.StaticField), typeof (WithRequires))] |