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:
authorTlakaelel Axayakatl Ceja <tlakaelel.ceja@microsoft.com>2021-10-29 22:20:39 +0300
committerGitHub <noreply@github.com>2021-10-29 22:20:39 +0300
commitc702d0337dc1db26a74c482f19a367ad9ddb7b89 (patch)
tree1974e00be6d908bdef6694beffb2f36948205418 /test
parentf74fcd2428ba25f88c926ed7d365ed01a121c9c8 (diff)
Ruc on type analyzer part 1 (#2330)
Add logic to check some of the Ruc on type analysis warnings Change field and event signature to match analyzer and linker to a single signature mode Add class as a diagnostic target Fix issue where attributes ProducedBy.Trimmer/ProducedBy.All are skipped if they are surrounded by ProducedBy.Analyzer attributes Bring IsConstructor and IsStaticConstructor from Roslyn source Remove special case for printing warnings in the event instead of the caller of the event accessor Scenarios of Ruc on type that are not addressed by this PR: Dealing with interfaces with RUC and having a class implementing it DAM interaction with RUC Reflection patterns, some of the tests work because they use typeof() but in general, they are not supported
Diffstat (limited to 'test')
-rw-r--r--test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresCapability.cs69
-rw-r--r--test/Mono.Linker.Tests/TestCasesRunner/ResultChecker.cs2
2 files changed, 38 insertions, 33 deletions
diff --git a/test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresCapability.cs b/test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresCapability.cs
index f6b21bca6..f7155e5fe 100644
--- a/test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresCapability.cs
+++ b/test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresCapability.cs
@@ -744,24 +744,26 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
class OnEventMethod
{
- [ExpectedWarning ("IL2026", "--EventToTestRemove.remove--")]
+ [ExpectedWarning ("IL2026", "--EventToTestRemove.remove--", ProducedBy = ProducedBy.Trimmer)]
static event EventHandler EventToTestRemove {
add { }
[RequiresUnreferencedCode ("Message for --EventToTestRemove.remove--")]
remove { }
}
- [ExpectedWarning ("IL2026", "--EventToTestAdd.add--")]
+ [ExpectedWarning ("IL2026", "--EventToTestAdd.add--", ProducedBy = ProducedBy.Trimmer)]
static event EventHandler EventToTestAdd {
[RequiresUnreferencedCode ("Message for --EventToTestAdd.add--")]
add { }
remove { }
}
+ [ExpectedWarning ("IL2026", "--EventToTestRemove.remove--")]
+ [ExpectedWarning ("IL2026", "--EventToTestAdd.add--")]
public static void Test ()
{
- EventToTestRemove += (sender, e) => { };
- EventToTestAdd -= (sender, e) => { };
+ EventToTestRemove -= (sender, e) => { };
+ EventToTestAdd += (sender, e) => { };
}
}
@@ -924,7 +926,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
}
}
- [ExpectedWarning ("IL2026", "RequiresOnClass.StaticCtor.StaticCtor()", "Message for --StaticCtor--", ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2026", "RequiresOnClass.StaticCtor.StaticCtor()", "Message for --StaticCtor--")]
static void TestStaticCctorRequires ()
{
_ = new StaticCtor ();
@@ -941,13 +943,13 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
public static int field;
}
- [ExpectedWarning ("IL2026", "StaticCtorTriggeredByFieldAccess.field", "Message for --StaticCtorTriggeredByFieldAccess--", ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2026", "StaticCtorTriggeredByFieldAccess.field", "Message for --StaticCtorTriggeredByFieldAccess--")]
static void TestStaticCtorMarkingIsTriggeredByFieldAccessWrite ()
{
StaticCtorTriggeredByFieldAccess.field = 1;
}
- [ExpectedWarning ("IL2026", "StaticCtorTriggeredByFieldAccess.field", "Message for --StaticCtorTriggeredByFieldAccess--", ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2026", "StaticCtorTriggeredByFieldAccess.field", "Message for --StaticCtorTriggeredByFieldAccess--")]
static void TestStaticCtorMarkingTriggeredOnSecondAccessWrite ()
{
StaticCtorTriggeredByFieldAccess.field = 2;
@@ -971,7 +973,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
public static int field = 42;
}
- [ExpectedWarning ("IL2026", "StaticCCtorTriggeredByFieldAccessRead.field", "Message for --StaticCCtorTriggeredByFieldAccessRead--", ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2026", "StaticCCtorTriggeredByFieldAccessRead.field", "Message for --StaticCCtorTriggeredByFieldAccessRead--")]
static void TestStaticCtorMarkingIsTriggeredByFieldAccessRead ()
{
var _ = StaticCCtorTriggeredByFieldAccessRead.field;
@@ -989,7 +991,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
}
}
- [ExpectedWarning ("IL2026", "StaticCtorTriggeredByCtorCalls.StaticCtorTriggeredByCtorCalls()", ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2026", "StaticCtorTriggeredByCtorCalls.StaticCtorTriggeredByCtorCalls()")]
static void TestStaticCtorTriggeredByCtorCall ()
{
new StaticCtorTriggeredByCtorCalls ();
@@ -1001,7 +1003,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
public int field = 42;
}
- [ExpectedWarning ("IL2026", "ClassWithInstanceField.ClassWithInstanceField()", ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2026", "ClassWithInstanceField.ClassWithInstanceField()")]
static void TestInstanceFieldCallDontWarn ()
{
ClassWithInstanceField instance = new ClassWithInstanceField ();
@@ -1101,13 +1103,13 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
}
}
- [ExpectedWarning ("IL2026", "RequiresOnClass.ClassWithRequires.StaticMethod()", "--ClassWithRequires--", ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2026", "RequiresOnClass.ClassWithRequires.StaticMethod()", "--ClassWithRequires--")]
static void TestRequiresInClassAccessedByStaticMethod ()
{
ClassWithRequires.StaticMethod ();
}
- [ExpectedWarning ("IL2026", "RequiresOnClass.ClassWithRequires", "--ClassWithRequires--", ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2026", "RequiresOnClass.ClassWithRequires", "--ClassWithRequires--")]
static void TestRequiresInClassAccessedByCctor ()
{
var classObject = new ClassWithRequires ();
@@ -1118,10 +1120,10 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
ClassWithRequires.NestedClass.NestedStaticMethod ();
}
- [ExpectedWarning ("IL2026", "RequiresOnClass.ClassWithRequires.StaticMethod()", "--ClassWithRequires--", ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2026", "RequiresOnClass.ClassWithRequires.StaticMethod()", "--ClassWithRequires--")]
// 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--", ProducedBy = ProducedBy.Trimmer)]
- [ExpectedWarning ("IL2026", "ClassWithRequires.Instance", "--ClassWithRequires--", ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2026", "RequiresOnClass.ClassWithRequires.CallMethodWithRequires()", "--ClassWithRequires--")]
+ [ExpectedWarning ("IL2026", "ClassWithRequires.Instance", "--ClassWithRequires--")]
static void TestRequiresOnBaseButNotOnDerived ()
{
DerivedWithoutRequires.StaticMethodInInheritedClass ();
@@ -1135,7 +1137,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
DerivedWithoutRequires2.StaticMethod ();
}
- [ExpectedWarning ("IL2026", "RequiresOnClass.DerivedWithRequires.StaticMethodInInheritedClass()", "--DerivedWithRequires--", ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2026", "RequiresOnClass.DerivedWithRequires.StaticMethodInInheritedClass()", "--DerivedWithRequires--")]
static void TestRequiresOnDerivedButNotOnBase ()
{
DerivedWithRequires.StaticMethodInInheritedClass ();
@@ -1144,8 +1146,8 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
DerivedWithRequires.NestedClass.NestedStaticMethod ();
}
- [ExpectedWarning ("IL2026", "RequiresOnClass.DerivedWithRequires2.StaticMethodInInheritedClass()", "--DerivedWithRequires2--", ProducedBy = ProducedBy.Trimmer)]
- [ExpectedWarning ("IL2026", "RequiresOnClass.ClassWithRequires.StaticMethod()", "--ClassWithRequires--", ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2026", "RequiresOnClass.DerivedWithRequires2.StaticMethodInInheritedClass()", "--DerivedWithRequires2--")]
+ [ExpectedWarning ("IL2026", "RequiresOnClass.ClassWithRequires.StaticMethod()", "--ClassWithRequires--")]
static void TestRequiresOnBaseAndDerived ()
{
DerivedWithRequires2.StaticMethodInInheritedClass ();
@@ -1154,7 +1156,8 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
DerivedWithRequires2.NestedClass.NestedStaticMethod ();
}
- [ExpectedWarning ("IL2026", "RequiresOnClass.ClassWithRequires.TestSuppressions(Type[])", ProducedBy = ProducedBy.Trimmer)]
+ // TODO: Parameter signature differs between linker and analyzer
+ [ExpectedWarning ("IL2026", "RequiresOnClass.ClassWithRequires.TestSuppressions(", "Type[])")]
static void TestSuppressionsOnClass ()
{
ClassWithRequires.TestSuppressions (new[] { typeof (ClassWithRequires) });
@@ -1192,14 +1195,14 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
public static int Property { get; set; }
// These should not be reported https://github.com/mono/linker/issues/2218
- [ExpectedWarning ("IL2026", "add_Event", ProducedBy = ProducedBy.Trimmer)]
- [ExpectedWarning ("IL2026", "remove_Event", ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2026", "MemberTypesWithRequires.Event.add", ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2026", "MemberTypesWithRequires.Event.remove", ProducedBy = ProducedBy.Trimmer)]
public static event EventHandler Event;
}
- [ExpectedWarning ("IL2026", "MemberTypesWithRequires.field", ProducedBy = ProducedBy.Trimmer)]
- [ExpectedWarning ("IL2026", "MemberTypesWithRequires.Property.set", ProducedBy = ProducedBy.Trimmer)]
- [ExpectedWarning ("IL2026", "MemberTypesWithRequires.remove_Event", ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2026", "MemberTypesWithRequires.field")]
+ [ExpectedWarning ("IL2026", "MemberTypesWithRequires.Property.set")]
+ [ExpectedWarning ("IL2026", "MemberTypesWithRequires.Event.remove")]
static void TestOtherMemberTypesWithRequires ()
{
MemberTypesWithRequires.field = 1;
@@ -1340,7 +1343,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
[RequiresUnreferencedCode ("--WithRequiresOnlyInstanceFields--")]
class WithRequiresOnlyInstanceFields
{
- public int InstnaceField;
+ public int InstanceField;
}
[ExpectedWarning ("IL2109", "ReflectionAccessOnField/DerivedWithoutRequires", "ReflectionAccessOnField.WithRequires", ProducedBy = ProducedBy.Trimmer)]
@@ -1367,20 +1370,22 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
typeof (DerivedWithRequires).RequiresPublicFields ();
}
- [ExpectedWarning ("IL2026", "WithRequires.StaticField", ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2026", "WithRequires.StaticField")]
+ // Analyzer does not recognize the binding flags
[ExpectedWarning ("IL2026", "WithRequires.PrivateStaticField", ProducedBy = ProducedBy.Trimmer)]
- [ExpectedWarning ("IL2026", "DerivedWithRequires.DerivedStaticField", ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2026", "DerivedWithRequires.DerivedStaticField")]
+ [ExpectedWarning ("IL2026", "DerivedWithRequires.DerivedStaticField", ProducedBy = ProducedBy.Analyzer)]
static void TestDirectReflectionAccess ()
{
typeof (WithRequires).GetField (nameof (WithRequires.StaticField));
typeof (WithRequires).GetField (nameof (WithRequires.InstanceField)); // Doesn't warn
typeof (WithRequires).GetField ("PrivateStaticField", BindingFlags.NonPublic);
- typeof (WithRequiresOnlyInstanceFields).GetField (nameof (WithRequiresOnlyInstanceFields.InstnaceField)); // Doesn't warn
+ typeof (WithRequiresOnlyInstanceFields).GetField (nameof (WithRequiresOnlyInstanceFields.InstanceField)); // Doesn't warn
typeof (DerivedWithoutRequires).GetField (nameof (DerivedWithRequires.DerivedStaticField)); // Doesn't warn
typeof (DerivedWithRequires).GetField (nameof (DerivedWithRequires.DerivedStaticField));
}
- [ExpectedWarning ("IL2026", "WithRequires.StaticField", ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2026", "WithRequires.StaticField")]
[DynamicDependency (nameof (WithRequires.StaticField), typeof (WithRequires))]
[DynamicDependency (nameof (WithRequires.InstanceField), typeof (WithRequires))] // Doesn't warn
[DynamicDependency (DynamicallyAccessedMemberTypes.PublicFields, typeof (DerivedWithoutRequires))] // Doesn't warn
@@ -1432,12 +1437,12 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
{
// These should be reported only in TestDirectReflectionAccess
// https://github.com/mono/linker/issues/2218
- [ExpectedWarning ("IL2026", "add_StaticEvent", ProducedBy = ProducedBy.Trimmer)]
- [ExpectedWarning ("IL2026", "remove_StaticEvent", ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2026", "StaticEvent.add", ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2026", "StaticEvent.remove", ProducedBy = ProducedBy.Trimmer)]
public static event EventHandler StaticEvent;
}
- [ExpectedWarning ("IL2026", "add_StaticEvent", ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2026", "StaticEvent.add", ProducedBy = ProducedBy.Trimmer)]
static void TestDirectReflectionAccess ()
{
typeof (WithRequires).GetEvent (nameof (WithRequires.StaticEvent));
diff --git a/test/Mono.Linker.Tests/TestCasesRunner/ResultChecker.cs b/test/Mono.Linker.Tests/TestCasesRunner/ResultChecker.cs
index fe2b6bf8e..bab3a4f59 100644
--- a/test/Mono.Linker.Tests/TestCasesRunner/ResultChecker.cs
+++ b/test/Mono.Linker.Tests/TestCasesRunner/ResultChecker.cs
@@ -679,7 +679,7 @@ namespace Mono.Linker.Tests.TestCasesRunner
bool foundReflectionAccessPatternAttributesToVerify = false;
foreach (var attr in attrProvider.CustomAttributes) {
if (!IsProducedByLinker (attr))
- break;
+ continue;
switch (attr.AttributeType.Name) {