From 7d149f673b921ecc23372a5741082c9cd0a6b70a Mon Sep 17 00:00:00 2001 From: Vitek Karas Date: Wed, 20 May 2020 08:23:01 -0700 Subject: Implement support for RequiresUnreferencedCodeAttribute (#1204) Introduces a cache of "linker attributes", currently only RequiresUnreferencedCodeAttribute is supported, but it's highly likely we will need this for other attributes as well (DynamicDependency, future AOT/Single-file related attributes, UnconditionalSuppressMessage, ...). The cache is on Annotations class and should also act as a natural point to unify attribute and XML based inputs (once we have the XML based attribute injection). RequiresUnreferencedCode now causes a linker warning whenever a method with it is called. It also auto-suppresses warnings within the method with this attribute - it actually disables data flow analysis on the method right now. In the future when we have AOT/Single-File related analysis we will need to modify this to selectively support a subset and only auto-suppress warnings related to the relevant subsets. Extends the LogContains/LogDoesNotContain test attributes so that they can appear on anything within the test class. Functionality is still the same as if they're on the class, but it makes it easier to structure the tests and make them more readable. Once we have solid warning origins, we could also auto-validate that the warning came from the method it is on. Added support for multiple attributes of the same type. Added logic to detect multiple instances of attribute where there should only be one - in this case linker will issue a warning and use the first instance only. --- test/Mono.Linker.Tests/TestCases/TestSuites.cs | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'test/Mono.Linker.Tests/TestCases/TestSuites.cs') diff --git a/test/Mono.Linker.Tests/TestCases/TestSuites.cs b/test/Mono.Linker.Tests/TestCases/TestSuites.cs index f50995fa8..2d72ae770 100644 --- a/test/Mono.Linker.Tests/TestCases/TestSuites.cs +++ b/test/Mono.Linker.Tests/TestCases/TestSuites.cs @@ -212,6 +212,12 @@ namespace Mono.Linker.Tests.TestCases Run (testCase); } + [TestCaseSource (typeof (TestDatabase), nameof (TestDatabase.RequiresCapabilityTests))] + public void RequiresCapabilityTests (TestCase testCase) + { + Run (testCase); + } + protected virtual void Run (TestCase testCase) { var runner = new TestRunner (new ObjectFactory ()); -- cgit v1.2.3