diff options
author | Mike Voorhees <mrvoorhe@users.noreply.github.com> | 2021-09-11 09:42:45 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-11 09:42:45 +0300 |
commit | be8ec96d897e0817cb89578405c154b4f9252ac5 (patch) | |
tree | 62ccf9327a06883569a8038c31425ab14947e08a /test | |
parent | 0c359eadea75bde0de74d784fdc45788b3668e73 (diff) |
Refactor how test case metadata is obtained. (#2268)
Diffstat (limited to 'test')
76 files changed, 797 insertions, 724 deletions
diff --git a/test/Mono.Linker.Tests.Cases.Expectations/Assertions/TestCaseRequirementsAttribute.cs b/test/Mono.Linker.Tests.Cases.Expectations/Assertions/TestCaseRequirementsAttribute.cs new file mode 100644 index 000000000..687e230df --- /dev/null +++ b/test/Mono.Linker.Tests.Cases.Expectations/Assertions/TestCaseRequirementsAttribute.cs @@ -0,0 +1,18 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; + +namespace Mono.Linker.Tests.Cases.Expectations.Assertions +{ + [AttributeUsage (AttributeTargets.Class)] + public class TestCaseRequirementsAttribute : BaseExpectedLinkedBehaviorAttribute + { + public TestCaseRequirementsAttribute (TestRunCharacteristics targetFrameworkCharacteristics, string reason) + { + if (reason == null) + throw new ArgumentNullException (nameof (reason)); + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases.Expectations/Assertions/TestRunCharacteristics.cs b/test/Mono.Linker.Tests.Cases.Expectations/Assertions/TestRunCharacteristics.cs new file mode 100644 index 000000000..18d77a12f --- /dev/null +++ b/test/Mono.Linker.Tests.Cases.Expectations/Assertions/TestRunCharacteristics.cs @@ -0,0 +1,18 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; + +namespace Mono.Linker.Tests.Cases.Expectations.Assertions +{ + [Flags] + public enum TestRunCharacteristics + { + TargetingNetFramework = 1, + TargetingNetCore = 2, + SupportsDefaultInterfaceMethods = 8, + SupportsStaticInterfaceMethods = 16, + TestFrameworkSupportsMcs = 32 + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Attributes/NoSecurity/CoreLibrarySecurityAttributeTypesAreRemoved.cs b/test/Mono.Linker.Tests.Cases/Attributes/NoSecurity/CoreLibrarySecurityAttributeTypesAreRemoved.cs index c7738db8a..2644b5dbb 100644 --- a/test/Mono.Linker.Tests.Cases/Attributes/NoSecurity/CoreLibrarySecurityAttributeTypesAreRemoved.cs +++ b/test/Mono.Linker.Tests.Cases/Attributes/NoSecurity/CoreLibrarySecurityAttributeTypesAreRemoved.cs @@ -7,9 +7,7 @@ using Mono.Linker.Tests.Cases.Expectations.Metadata; namespace Mono.Linker.Tests.Cases.Attributes.NoSecurity { -#if NETCOREAPP - [IgnoreTestCase ("Not important for .NET Core build")] -#endif + [TestCaseRequirements (TestRunCharacteristics.TargetingNetFramework, "Not important for .NET Core build")] [SetupLinkerTrimMode ("link")] [SetupLinkerArgument ("--strip-security", "true")] [Reference ("System.dll")] diff --git a/test/Mono.Linker.Tests.Cases/Attributes/OnlyKeepUsed/ComAttributesAreRemovedWhenFeatureExcluded.cs b/test/Mono.Linker.Tests.Cases/Attributes/OnlyKeepUsed/ComAttributesAreRemovedWhenFeatureExcluded.cs index e33e7d27f..36877e80c 100644 --- a/test/Mono.Linker.Tests.Cases/Attributes/OnlyKeepUsed/ComAttributesAreRemovedWhenFeatureExcluded.cs +++ b/test/Mono.Linker.Tests.Cases/Attributes/OnlyKeepUsed/ComAttributesAreRemovedWhenFeatureExcluded.cs @@ -4,9 +4,7 @@ using Mono.Linker.Tests.Cases.Expectations.Metadata; namespace Mono.Linker.Tests.Cases.Attributes.OnlyKeepUsed { -#if NETCOREAPP - [IgnoreTestCase ("--exclude-feature is not supported on .NET Core")] -#endif + [TestCaseRequirements (TestRunCharacteristics.TargetingNetFramework, "--exclude-feature is not supported on .NET Core")] [SetupLinkerArgument ("--used-attrs-only", "true")] [SetupLinkerArgument ("--exclude-feature", "com")] public class ComAttributesAreRemovedWhenFeatureExcluded diff --git a/test/Mono.Linker.Tests.Cases/Attributes/TypeWithDynamicInterfaceCastableImplementationAttributeIsKept.cs b/test/Mono.Linker.Tests.Cases/Attributes/TypeWithDynamicInterfaceCastableImplementationAttributeIsKept.cs index fdc1b590d..f1c1f9f04 100644 --- a/test/Mono.Linker.Tests.Cases/Attributes/TypeWithDynamicInterfaceCastableImplementationAttributeIsKept.cs +++ b/test/Mono.Linker.Tests.Cases/Attributes/TypeWithDynamicInterfaceCastableImplementationAttributeIsKept.cs @@ -9,9 +9,7 @@ using Mono.Linker.Tests.Cases.Expectations.Assertions; using Mono.Linker.Tests.Cases.Expectations.Metadata; namespace Mono.Linker.Tests.Cases.Attributes { -#if !NETCOREAPP - [IgnoreTestCase ("Requires support for default interface methods")] -#endif + [TestCaseRequirements (TestRunCharacteristics.TargetingNetCore, "Requires net5 or newer")] [SetupCompileBefore ("interface.dll", new[] { "Dependencies/IReferencedAssembly.cs" })] [SetupCompileBefore ("impl.dll", new[] { "Dependencies/IReferencedAssemblyImpl.cs" }, references: new[] { "interface.dll" }, addAsReference: false)] diff --git a/test/Mono.Linker.Tests.Cases/BCLFeatures/ETW/BaseRemovedEventSource.cs b/test/Mono.Linker.Tests.Cases/BCLFeatures/ETW/BaseRemovedEventSource.cs index 8bb85bda8..deafdd3a8 100644 --- a/test/Mono.Linker.Tests.Cases/BCLFeatures/ETW/BaseRemovedEventSource.cs +++ b/test/Mono.Linker.Tests.Cases/BCLFeatures/ETW/BaseRemovedEventSource.cs @@ -5,9 +5,7 @@ using Mono.Linker.Tests.Cases.Expectations.Metadata; namespace Mono.Linker.Tests.Cases.BCLFeatures.ETW { -#if NETCOREAPP - [IgnoreTestCase ("--exclude-feature is not supported on .NET Core")] -#endif + [TestCaseRequirements (TestRunCharacteristics.TargetingNetFramework, "--exclude-feature is not supported on .NET Core")] [SetupLinkerArgument ("--exclude-feature", "etw")] // Keep framework code that calls EventSource methods like OnEventCommand [SetupLinkerTrimMode ("skip")] diff --git a/test/Mono.Linker.Tests.Cases/BCLFeatures/ETW/BaseRemovedEventSourceEmptyBody.cs b/test/Mono.Linker.Tests.Cases/BCLFeatures/ETW/BaseRemovedEventSourceEmptyBody.cs index cb6e83ed4..b72b66afb 100644 --- a/test/Mono.Linker.Tests.Cases/BCLFeatures/ETW/BaseRemovedEventSourceEmptyBody.cs +++ b/test/Mono.Linker.Tests.Cases/BCLFeatures/ETW/BaseRemovedEventSourceEmptyBody.cs @@ -4,9 +4,7 @@ using Mono.Linker.Tests.Cases.Expectations.Metadata; namespace Mono.Linker.Tests.Cases.BCLFeatures.ETW { -#if NETCOREAPP - [IgnoreTestCase ("--exclude-feature is not supported on .NET Core")] -#endif + [TestCaseRequirements (TestRunCharacteristics.TargetingNetFramework, "--exclude-feature is not supported on .NET Core")] [SetupLinkerArgument ("--exclude-feature", "etw")] // Keep framework code that calls EventSource methods like OnEventCommand [SetupLinkerTrimMode ("skip")] diff --git a/test/Mono.Linker.Tests.Cases/BCLFeatures/ETW/BaseRemovedEventSourceNonVoidReturn.cs b/test/Mono.Linker.Tests.Cases/BCLFeatures/ETW/BaseRemovedEventSourceNonVoidReturn.cs index 6adb3e217..d6ac1d1ad 100644 --- a/test/Mono.Linker.Tests.Cases/BCLFeatures/ETW/BaseRemovedEventSourceNonVoidReturn.cs +++ b/test/Mono.Linker.Tests.Cases/BCLFeatures/ETW/BaseRemovedEventSourceNonVoidReturn.cs @@ -4,9 +4,7 @@ using Mono.Linker.Tests.Cases.Expectations.Metadata; namespace Mono.Linker.Tests.Cases.BCLFeatures.ETW { -#if NETCOREAPP - [IgnoreTestCase ("--exclude-feature is not supported on .NET Core")] -#endif + [TestCaseRequirements (TestRunCharacteristics.TargetingNetFramework, "--exclude-feature is not supported on .NET Core")] [SetupLinkerArgument ("--exclude-feature", "etw")] // Keep framework code that calls EventSource methods like OnEventCommand [SetupLinkerTrimMode ("skip")] diff --git a/test/Mono.Linker.Tests.Cases/BCLFeatures/ETW/Excluded.cs b/test/Mono.Linker.Tests.Cases/BCLFeatures/ETW/Excluded.cs index 7256d8066..e09f837cf 100644 --- a/test/Mono.Linker.Tests.Cases/BCLFeatures/ETW/Excluded.cs +++ b/test/Mono.Linker.Tests.Cases/BCLFeatures/ETW/Excluded.cs @@ -5,9 +5,7 @@ using Mono.Linker.Tests.Cases.Expectations.Metadata; namespace Mono.Linker.Tests.Cases.BCLFeatures.ETW { -#if NETCOREAPP - [IgnoreTestCase ("--exclude-feature is not supported on .NET Core")] -#endif + [TestCaseRequirements (TestRunCharacteristics.TargetingNetFramework, "--exclude-feature is not supported on .NET Core")] [SetupLinkerArgument ("--exclude-feature", "etw")] // Keep framework code that calls EventSource methods like OnEventCommand [SetupLinkerTrimMode ("skip")] diff --git a/test/Mono.Linker.Tests.Cases/BCLFeatures/ETW/LocalsOfModifiedMethodAreRemoved.cs b/test/Mono.Linker.Tests.Cases/BCLFeatures/ETW/LocalsOfModifiedMethodAreRemoved.cs index ed61c571e..ea9788dbc 100644 --- a/test/Mono.Linker.Tests.Cases/BCLFeatures/ETW/LocalsOfModifiedMethodAreRemoved.cs +++ b/test/Mono.Linker.Tests.Cases/BCLFeatures/ETW/LocalsOfModifiedMethodAreRemoved.cs @@ -4,9 +4,7 @@ using Mono.Linker.Tests.Cases.Expectations.Metadata; namespace Mono.Linker.Tests.Cases.BCLFeatures.ETW { -#if NETCOREAPP - [IgnoreTestCase ("--exclude-feature is not supported on .NET Core")] -#endif + [TestCaseRequirements (TestRunCharacteristics.TargetingNetFramework, "--exclude-feature is not supported on .NET Core")] [SetupLinkerArgument ("--exclude-feature", "etw")] // Keep framework code that calls EventSource methods like OnEventCommand [SetupLinkerTrimMode ("skip")] diff --git a/test/Mono.Linker.Tests.Cases/BCLFeatures/ETW/NonEventWithLog.cs b/test/Mono.Linker.Tests.Cases/BCLFeatures/ETW/NonEventWithLog.cs index c986cb167..f02daab28 100644 --- a/test/Mono.Linker.Tests.Cases/BCLFeatures/ETW/NonEventWithLog.cs +++ b/test/Mono.Linker.Tests.Cases/BCLFeatures/ETW/NonEventWithLog.cs @@ -5,9 +5,7 @@ using Mono.Linker.Tests.Cases.Expectations.Metadata; namespace Mono.Linker.Tests.Cases.BCLFeatures.ETW { -#if NETCOREAPP - [IgnoreTestCase ("--exclude-feature is not supported on .NET Core")] -#endif + [TestCaseRequirements (TestRunCharacteristics.TargetingNetFramework, "--exclude-feature is not supported on .NET Core")] [SetupLinkerArgument ("--exclude-feature", "etw")] // Used to avoid different compilers generating different IL which can mess up the instruction asserts [SetupCompileArgument ("/optimize+")] diff --git a/test/Mono.Linker.Tests.Cases/BCLFeatures/ETW/StubbedMethodWithExceptionHandlers.cs b/test/Mono.Linker.Tests.Cases/BCLFeatures/ETW/StubbedMethodWithExceptionHandlers.cs index 73c6820a9..a38256f9b 100644 --- a/test/Mono.Linker.Tests.Cases/BCLFeatures/ETW/StubbedMethodWithExceptionHandlers.cs +++ b/test/Mono.Linker.Tests.Cases/BCLFeatures/ETW/StubbedMethodWithExceptionHandlers.cs @@ -5,9 +5,7 @@ using Mono.Linker.Tests.Cases.Expectations.Metadata; namespace Mono.Linker.Tests.Cases.BCLFeatures.ETW { -#if NETCOREAPP - [IgnoreTestCase ("--exclude-feature is not supported on .NET Core")] -#endif + [TestCaseRequirements (TestRunCharacteristics.TargetingNetFramework, "--exclude-feature is not supported on .NET Core")] [SetupLinkerArgument ("--exclude-feature", "etw")] // Keep framework code that calls EventSource methods like OnEventCommand [SetupLinkerTrimMode ("skip")] diff --git a/test/Mono.Linker.Tests.Cases/CommandLine/AddCustomStep.cs b/test/Mono.Linker.Tests.Cases/CommandLine/AddCustomStep.cs index 79271dcfb..b2d10ed2c 100644 --- a/test/Mono.Linker.Tests.Cases/CommandLine/AddCustomStep.cs +++ b/test/Mono.Linker.Tests.Cases/CommandLine/AddCustomStep.cs @@ -3,12 +3,7 @@ using Mono.Linker.Tests.Cases.Expectations.Metadata; namespace Mono.Linker.Tests.Cases.CommandLine { - -#if !NETCOREAPP - [IgnoreTestCase ("Can be enabled once MonoBuild produces a dll from which we can grab the types in the Mono.Linker namespace.")] -#else [SetupCompileBefore ("CustomStepDummy.dll", new[] { "Dependencies/CustomStepDummy.cs" }, new[] { "illink.dll" })] -#endif [SetupLinkerArgument ("--custom-step", "CustomStep.CustomStepDummy,CustomStepDummy.dll")] [SetupLinkerArgument ("--custom-step", "-CleanStep:CustomStep.CustomStepDummy,CustomStepDummy.dll")] [SetupLinkerArgument ("--custom-step", "+CleanStep:CustomStep.CustomStepDummy,CustomStepDummy.dll")] diff --git a/test/Mono.Linker.Tests.Cases/CommandLine/CustomStepData.cs b/test/Mono.Linker.Tests.Cases/CommandLine/CustomStepData.cs index 2530b7e62..296803bf8 100644 --- a/test/Mono.Linker.Tests.Cases/CommandLine/CustomStepData.cs +++ b/test/Mono.Linker.Tests.Cases/CommandLine/CustomStepData.cs @@ -3,12 +3,7 @@ using Mono.Linker.Tests.Cases.Expectations.Metadata; namespace Mono.Linker.Tests.Cases.CommandLine { - -#if !NETCOREAPP - [IgnoreTestCase ("Can be enabled once MonoBuild produces a dll from which we can grab the types in the Mono.Linker namespace.")] -#else [SetupCompileBefore ("CustomStepUser.dll", new[] { "Dependencies/CustomStepUser.cs" }, new[] { "illink.dll" })] -#endif [SetupLinkerArgument ("--custom-step", "CustomStep.CustomStepUser,CustomStepUser.dll")] [SetupLinkerArgument ("--custom-data", "NewKey=UserValue")] [SetupLinkerArgument ("--verbose")] diff --git a/test/Mono.Linker.Tests.Cases/CoreLink/DelegateAndMulticastDelegateKeepInstantiatedReqs.cs b/test/Mono.Linker.Tests.Cases/CoreLink/DelegateAndMulticastDelegateKeepInstantiatedReqs.cs index 2cc14fb20..86890e5cb 100644 --- a/test/Mono.Linker.Tests.Cases/CoreLink/DelegateAndMulticastDelegateKeepInstantiatedReqs.cs +++ b/test/Mono.Linker.Tests.Cases/CoreLink/DelegateAndMulticastDelegateKeepInstantiatedReqs.cs @@ -7,9 +7,7 @@ using Mono.Linker.Tests.Cases.Expectations.Metadata; namespace Mono.Linker.Tests.Cases.CoreLink { -#if !NETCOREAPP - [IgnoreTestCase ("Only for .NET Core for some reason")] -#endif + [TestCaseRequirements (TestRunCharacteristics.TargetingNetCore, "Only for .NET Core")] /// <summary> /// Delegate and is created from /// </summary> diff --git a/test/Mono.Linker.Tests.Cases/CoreLink/LinkingOfCoreLibrariesRemovesUnusedMethods.cs b/test/Mono.Linker.Tests.Cases/CoreLink/LinkingOfCoreLibrariesRemovesUnusedMethods.cs index 74826cd34..873fed9bc 100644 --- a/test/Mono.Linker.Tests.Cases/CoreLink/LinkingOfCoreLibrariesRemovesUnusedMethods.cs +++ b/test/Mono.Linker.Tests.Cases/CoreLink/LinkingOfCoreLibrariesRemovesUnusedMethods.cs @@ -7,9 +7,7 @@ using Mono.Linker.Tests.Cases.Expectations.Metadata; namespace Mono.Linker.Tests.Cases.CoreLink { -#if NETCOREAPP - [IgnoreTestCase ("Not important for .NET Core build")] -#endif + [TestCaseRequirements (TestRunCharacteristics.TargetingNetFramework, "Not important for .NET Core build")] [SetupLinkerTrimMode ("link")] [KeptAssembly (PlatformAssemblies.CoreLib)] diff --git a/test/Mono.Linker.Tests.Cases/CoreLink/LinkingOfCoreLibrariesRemovesUnusedTypes.cs b/test/Mono.Linker.Tests.Cases/CoreLink/LinkingOfCoreLibrariesRemovesUnusedTypes.cs index e05755374..f90b3ac43 100644 --- a/test/Mono.Linker.Tests.Cases/CoreLink/LinkingOfCoreLibrariesRemovesUnusedTypes.cs +++ b/test/Mono.Linker.Tests.Cases/CoreLink/LinkingOfCoreLibrariesRemovesUnusedTypes.cs @@ -6,9 +6,7 @@ using Mono.Linker.Tests.Cases.Expectations.Metadata; namespace Mono.Linker.Tests.Cases.CoreLink { -#if NETCOREAPP - [IgnoreTestCase ("Not important for .NET Core build")] -#endif + [TestCaseRequirements (TestRunCharacteristics.TargetingNetFramework, "Not important for .NET Core build")] [SetupLinkerTrimMode ("link")] [Reference ("System.dll")] diff --git a/test/Mono.Linker.Tests.Cases/CoreLink/NoSecurityPlusOnlyKeepUsedRemovesAllSecurityAttributesFromCoreLibraries.cs b/test/Mono.Linker.Tests.Cases/CoreLink/NoSecurityPlusOnlyKeepUsedRemovesAllSecurityAttributesFromCoreLibraries.cs index b76a18c05..6b0e4bf50 100644 --- a/test/Mono.Linker.Tests.Cases/CoreLink/NoSecurityPlusOnlyKeepUsedRemovesAllSecurityAttributesFromCoreLibraries.cs +++ b/test/Mono.Linker.Tests.Cases/CoreLink/NoSecurityPlusOnlyKeepUsedRemovesAllSecurityAttributesFromCoreLibraries.cs @@ -7,9 +7,7 @@ using Mono.Linker.Tests.Cases.Expectations.Metadata; namespace Mono.Linker.Tests.Cases.CoreLink { -#if NETCOREAPP - [IgnoreTestCase ("Not important for .NET Core build")] -#endif + [TestCaseRequirements (TestRunCharacteristics.TargetingNetFramework, "Not important for .NET Core build")] [SetupLinkerTrimMode ("link")] [SetupLinkerArgument ("--strip-security", "true")] [SetupLinkerArgument ("--used-attrs-only", "true")] diff --git a/test/Mono.Linker.Tests.Cases/Extensibility/CustomStepCanPreserveMethodsAfterMark.cs b/test/Mono.Linker.Tests.Cases/Extensibility/CustomStepCanPreserveMethodsAfterMark.cs index d3e32e816..277fe0c28 100644 --- a/test/Mono.Linker.Tests.Cases/Extensibility/CustomStepCanPreserveMethodsAfterMark.cs +++ b/test/Mono.Linker.Tests.Cases/Extensibility/CustomStepCanPreserveMethodsAfterMark.cs @@ -3,9 +3,6 @@ using Mono.Linker.Tests.Cases.Expectations.Metadata; namespace Mono.Linker.Tests.Cases.Extensibility { -#if !NETCOREAPP - [IgnoreTestCase ("Specific to the illink build")] -#endif [SetupCompileBefore ("CustomStepAfterMark.dll", new[] { "Dependencies/PreserveMethodsSubStep.cs" }, new[] { "illink.dll", "Mono.Cecil.dll", "netstandard.dll" })] [SetupLinkerArgument ("--custom-step", "+MarkStep:PreserveMethodsSubStep,CustomStepAfterMark.dll")] public class CustomStepCanPreserveMethodsAfterMark diff --git a/test/Mono.Linker.Tests.Cases/Extensibility/CustomStepCanPreserveMethodsBeforeMark.cs b/test/Mono.Linker.Tests.Cases/Extensibility/CustomStepCanPreserveMethodsBeforeMark.cs index d479cfcc9..409e23d7e 100644 --- a/test/Mono.Linker.Tests.Cases/Extensibility/CustomStepCanPreserveMethodsBeforeMark.cs +++ b/test/Mono.Linker.Tests.Cases/Extensibility/CustomStepCanPreserveMethodsBeforeMark.cs @@ -3,9 +3,6 @@ using Mono.Linker.Tests.Cases.Expectations.Metadata; namespace Mono.Linker.Tests.Cases.Extensibility { -#if !NETCOREAPP - [IgnoreTestCase ("Specific to the illink build")] -#endif [SetupCompileBefore ("CustomStepBeforeMark.dll", new[] { "Dependencies/PreserveMethodsSubStep.cs" }, new[] { "illink.dll", "Mono.Cecil.dll", "netstandard.dll" })] [SetupLinkerArgument ("--custom-step", "-MarkStep:PreserveMethodsSubStep,CustomStepBeforeMark.dll")] public class CustomStepCanPreserveMethodsBeforeMark diff --git a/test/Mono.Linker.Tests.Cases/Extensibility/SubStepDispatcherFields.cs b/test/Mono.Linker.Tests.Cases/Extensibility/SubStepDispatcherFields.cs index 74fb34927..f84b1facd 100644 --- a/test/Mono.Linker.Tests.Cases/Extensibility/SubStepDispatcherFields.cs +++ b/test/Mono.Linker.Tests.Cases/Extensibility/SubStepDispatcherFields.cs @@ -3,9 +3,6 @@ using Mono.Linker.Tests.Cases.Expectations.Metadata; namespace Mono.Linker.Tests.Cases.Extensibility { -#if !NETCOREAPP - [IgnoreTestCase ("Specific to the illink build")] -#endif [SetupCompileBefore ("MyDispatcherFields.dll", new[] { "Dependencies/MyDispatcher.cs", "Dependencies/CustomSubStepFields.cs" }, new[] { "illink.dll", "Mono.Cecil.dll", "netstandard.dll" })] [SetupLinkerArgument ("--custom-step", "-MarkStep:MyDispatcher,MyDispatcherFields.dll")] public class SubStepDispatcherFields diff --git a/test/Mono.Linker.Tests.Cases/Extensibility/SubStepDispatcherUsage.cs b/test/Mono.Linker.Tests.Cases/Extensibility/SubStepDispatcherUsage.cs index 7dbdbc994..20ab3b356 100644 --- a/test/Mono.Linker.Tests.Cases/Extensibility/SubStepDispatcherUsage.cs +++ b/test/Mono.Linker.Tests.Cases/Extensibility/SubStepDispatcherUsage.cs @@ -3,9 +3,6 @@ using Mono.Linker.Tests.Cases.Expectations.Metadata; namespace Mono.Linker.Tests.Cases.Extensibility { -#if !NETCOREAPP - [IgnoreTestCase ("Specific to the illink build")] -#endif [SetupCompileBefore ("MyDispatcherUsage.dll", new[] { "Dependencies/MyDispatcher.cs", "Dependencies/CustomSubStep.cs" }, new[] { "illink.dll", "Mono.Cecil.dll", "netstandard.dll" })] [SetupLinkerArgument ("--custom-step", "-MarkStep:MyDispatcher,MyDispatcherUsage.dll")] public class SubStepDispatcherUsage diff --git a/test/Mono.Linker.Tests.Cases/FeatureSettings/FeatureDescriptors.cs b/test/Mono.Linker.Tests.Cases/FeatureSettings/FeatureDescriptors.cs index d70c2eca4..5023372e6 100644 --- a/test/Mono.Linker.Tests.Cases/FeatureSettings/FeatureDescriptors.cs +++ b/test/Mono.Linker.Tests.Cases/FeatureSettings/FeatureDescriptors.cs @@ -4,9 +4,7 @@ using Mono.Linker.Tests.Cases.Expectations.Metadata; namespace Mono.Linker.Tests.Cases.FeatureSettings { -#if !NETCOREAPP - [IgnoreTestCase ("Feature settings in descriptors are not supported on Mono.")] -#endif + [TestCaseRequirements (TestRunCharacteristics.TargetingNetCore, "Feature settings in descriptors are not supported on Mono.")] [SetupLinkerDescriptorFile ("FeatureDescriptorsGlobalTrue.xml")] [SetupLinkerDescriptorFile ("FeatureDescriptorsGlobalFalse.xml")] [SetupLinkerDescriptorFile ("FeatureDescriptors.xml")] diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/DefaultInterfaceMethods/DefaultInterfaceMethodCallIntoClass.cs b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/DefaultInterfaceMethods/DefaultInterfaceMethodCallIntoClass.cs index c5e8e3ee7..c09e07322 100644 --- a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/DefaultInterfaceMethods/DefaultInterfaceMethodCallIntoClass.cs +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/DefaultInterfaceMethods/DefaultInterfaceMethodCallIntoClass.cs @@ -6,19 +6,17 @@ using Mono.Linker.Tests.Cases.Expectations.Metadata; namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces.DefaultInterfaceMethods { -#if !NETCOREAPP - [IgnoreTestCase ("Requires support for default interface methods")] -#endif + [TestCaseRequirements (TestRunCharacteristics.SupportsDefaultInterfaceMethods, "Requires support for default interface methods")] class DefaultInterfaceMethodCallIntoClass { public static void Main () { -#if NETCOREAPP +#if SUPPORTS_DEFAULT_INTERFACE_METHODS ((IBase) new Derived ()).Frob (); #endif } -#if NETCOREAPP +#if SUPPORTS_DEFAULT_INTERFACE_METHODS [Kept] interface IBase { diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/DefaultInterfaceMethods/GenericDefaultInterfaceMethods.cs b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/DefaultInterfaceMethods/GenericDefaultInterfaceMethods.cs index 6e4d6f1ab..4584297ad 100644 --- a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/DefaultInterfaceMethods/GenericDefaultInterfaceMethods.cs +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/DefaultInterfaceMethods/GenericDefaultInterfaceMethods.cs @@ -5,20 +5,18 @@ using Mono.Linker.Tests.Cases.Expectations.Assertions; namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces.DefaultInterfaceMethods { -#if !NETCOREAPP - [IgnoreTestCase ("Requires support for default interface methods")] -#endif + [TestCaseRequirements (TestRunCharacteristics.SupportsDefaultInterfaceMethods, "Requires support for default interface methods")] class GenericDefaultInterfaceMethods { public static void Main () { -#if NETCOREAPP +#if SUPPORTS_DEFAULT_INTERFACE_METHODS ((IFoo<int>) new Bar ()).Method (12); ((IFoo<int>) new Baz ()).Method (12); #endif } -#if NETCOREAPP +#if SUPPORTS_DEFAULT_INTERFACE_METHODS [Kept] interface IFoo<T> { diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/DefaultInterfaceMethods/InterfaceWithAttributeOnImplementation.cs b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/DefaultInterfaceMethods/InterfaceWithAttributeOnImplementation.cs index d280d090d..cd6553578 100644 --- a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/DefaultInterfaceMethods/InterfaceWithAttributeOnImplementation.cs +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/DefaultInterfaceMethods/InterfaceWithAttributeOnImplementation.cs @@ -7,9 +7,7 @@ using Mono.Linker.Tests.Cases.Expectations.Metadata; namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces.DefaultInterfaceMethods { [SetupLinkerArgument ("--skip-unresolved", "true")] -#if !NETCOREAPP - [IgnoreTestCase ("Only for .NET Core for some reason")] -#endif + [TestCaseRequirements (TestRunCharacteristics.SupportsDefaultInterfaceMethods, "Requires support for default interface methods")] [Define ("IL_ASSEMBLY_AVAILABLE")] [SetupCompileBefore ("library.dll", new[] { "Dependencies/InterfaceWithAttributeOnImpl.il" })] class InterfaceWithAttributeOnImplementation diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/DefaultInterfaceMethods/SimpleDefaultInterfaceMethod.cs b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/DefaultInterfaceMethods/SimpleDefaultInterfaceMethod.cs index 7838085d3..08fafadb2 100644 --- a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/DefaultInterfaceMethods/SimpleDefaultInterfaceMethod.cs +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/DefaultInterfaceMethods/SimpleDefaultInterfaceMethod.cs @@ -6,19 +6,17 @@ using Mono.Linker.Tests.Cases.Expectations.Metadata; namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces.DefaultInterfaceMethods { -#if !NETCOREAPP - [IgnoreTestCase ("Requires support for default interface methods")] -#endif + [TestCaseRequirements (TestRunCharacteristics.SupportsDefaultInterfaceMethods, "Requires support for default interface methods")] class SimpleDefaultInterfaceMethod { public static void Main () { -#if NETCOREAPP +#if SUPPORTS_DEFAULT_INTERFACE_METHODS ((IBasic) new Basic ()).DoSomething (); #endif } -#if NETCOREAPP +#if SUPPORTS_DEFAULT_INTERFACE_METHODS [Kept] interface IBasic { diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/DefaultInterfaceMethods/UnusedDefaultInterfaceImplementation.cs b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/DefaultInterfaceMethods/UnusedDefaultInterfaceImplementation.cs index 15114d3c5..46ed48963 100644 --- a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/DefaultInterfaceMethods/UnusedDefaultInterfaceImplementation.cs +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/DefaultInterfaceMethods/UnusedDefaultInterfaceImplementation.cs @@ -5,19 +5,17 @@ using Mono.Linker.Tests.Cases.Expectations.Assertions; namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces.DefaultInterfaceMethods { -#if !NETCOREAPP - [IgnoreTestCase ("Requires support for default interface methods")] -#endif + [TestCaseRequirements (TestRunCharacteristics.SupportsDefaultInterfaceMethods, "Requires support for default interface methods")] class UnusedDefaultInterfaceImplementation { public static void Main () { -#if NETCOREAPP +#if SUPPORTS_DEFAULT_INTERFACE_METHODS ((IFoo) new Foo ()).InterfaceMethod (); #endif } -#if NETCOREAPP +#if SUPPORTS_DEFAULT_INTERFACE_METHODS [Kept] interface IFoo { diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/UnusedComInterfaceIsRemovedWhenComFeatureExcluded.cs b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/UnusedComInterfaceIsRemovedWhenComFeatureExcluded.cs index 3f0d5b8ca..35afe034f 100644 --- a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/UnusedComInterfaceIsRemovedWhenComFeatureExcluded.cs +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/UnusedComInterfaceIsRemovedWhenComFeatureExcluded.cs @@ -4,9 +4,7 @@ using Mono.Linker.Tests.Cases.Expectations.Metadata; namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType { -#if NETCOREAPP - [IgnoreTestCase ("--exclude-feature is not supported on .NET Core")] -#endif + [TestCaseRequirements (TestRunCharacteristics.TargetingNetFramework, "--exclude-feature is not supported on .NET Core")] [SetupLinkerArgument ("--exclude-feature", "com")] public class UnusedComInterfaceIsRemovedWhenComFeatureExcluded { diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/StaticInterfaceMethods/GenericsBasic_Delegate.cs b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/StaticInterfaceMethods/GenericsBasic_Delegate.cs index d49454468..0b41b8034 100644 --- a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/StaticInterfaceMethods/GenericsBasic_Delegate.cs +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/StaticInterfaceMethods/GenericsBasic_Delegate.cs @@ -7,9 +7,7 @@ using Mono.Linker.Tests.Cases.Expectations.Metadata; namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces.StaticInterfaceMethods { [SetupLinkerArgument ("--skip-unresolved", "true")] -#if !NETCOREAPP - [IgnoreTestCase("Only for .NET Core for some reason")] -#endif + [TestCaseRequirements (TestRunCharacteristics.SupportsStaticInterfaceMethods, "Requires a framework that supports static interface methods")] [Define ("IL_ASSEMBLY_AVAILABLE")] [SetupCompileBefore ("library.dll", new[] { "Dependencies/GenericsBasic_Delegate.il" })] [KeptTypeInAssembly ("library.dll", "IFaceNonGeneric")] diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/StaticInterfaceMethods/GenericsBasic_Direct.cs b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/StaticInterfaceMethods/GenericsBasic_Direct.cs index a59472989..3c3de21e2 100644 --- a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/StaticInterfaceMethods/GenericsBasic_Direct.cs +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/StaticInterfaceMethods/GenericsBasic_Direct.cs @@ -7,9 +7,7 @@ using Mono.Linker.Tests.Cases.Expectations.Metadata; namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces.StaticInterfaceMethods { [SetupLinkerArgument ("--skip-unresolved", "true")] -#if !NETCOREAPP - [IgnoreTestCase("Only for .NET Core for some reason")] -#endif + [TestCaseRequirements (TestRunCharacteristics.SupportsStaticInterfaceMethods, "Requires a framework that supports static interface methods")] [Define ("IL_ASSEMBLY_AVAILABLE")] [SetupCompileBefore ("library.dll", new[] { "Dependencies/GenericsBasic_Direct.il" })] [KeptTypeInAssembly ("library.dll", "IFaceNonGeneric")] diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/StaticInterfaceMethods/GenericsBasic_Ldftn.cs b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/StaticInterfaceMethods/GenericsBasic_Ldftn.cs index 66b6932e8..2ccdb9ab9 100644 --- a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/StaticInterfaceMethods/GenericsBasic_Ldftn.cs +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/StaticInterfaceMethods/GenericsBasic_Ldftn.cs @@ -7,9 +7,7 @@ using Mono.Linker.Tests.Cases.Expectations.Metadata; namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces.StaticInterfaceMethods { [SetupLinkerArgument ("--skip-unresolved", "true")] -#if !NETCOREAPP - [IgnoreTestCase("Only for .NET Core for some reason")] -#endif + [TestCaseRequirements (TestRunCharacteristics.SupportsStaticInterfaceMethods, "Requires a framework that supports static interface methods")] [Define ("IL_ASSEMBLY_AVAILABLE")] [SetupCompileBefore ("library.dll", new[] { "Dependencies/GenericsBasic_Ldftn.il" })] [KeptTypeInAssembly ("library.dll", "IFaceNonGeneric")] diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/StaticInterfaceMethods/GenericsFull.cs b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/StaticInterfaceMethods/GenericsFull.cs index 2361b535c..6bf22b528 100644 --- a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/StaticInterfaceMethods/GenericsFull.cs +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/StaticInterfaceMethods/GenericsFull.cs @@ -7,9 +7,7 @@ using Mono.Linker.Tests.Cases.Expectations.Metadata; namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces.StaticInterfaceMethods { [SetupLinkerArgument ("--skip-unresolved", "true")] -#if !NETCOREAPP - [IgnoreTestCase("Only for .NET Core for some reason")] -#endif + [TestCaseRequirements (TestRunCharacteristics.SupportsStaticInterfaceMethods, "Requires a framework that supports static interface methods")] [Define ("IL_ASSEMBLY_AVAILABLE")] [SetupCompileBefore ("library.dll", new[] { "Dependencies/GenericsFull.il" })] [KeptTypeInAssembly ("library.dll", "IFaceNonGeneric")] diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/StaticInterfaceMethods/TypeHierarchyBasic.cs b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/StaticInterfaceMethods/TypeHierarchyBasic.cs index 15c89c6ce..b5a73ab1b 100644 --- a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/StaticInterfaceMethods/TypeHierarchyBasic.cs +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/StaticInterfaceMethods/TypeHierarchyBasic.cs @@ -7,9 +7,7 @@ using Mono.Linker.Tests.Cases.Expectations.Metadata; namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces.StaticInterfaceMethods { [SetupLinkerArgument ("--skip-unresolved", "true")] -#if !NETCOREAPP - [IgnoreTestCase("Only for .NET Core for some reason")] -#endif + [TestCaseRequirements (TestRunCharacteristics.SupportsStaticInterfaceMethods, "Requires a framework that supports static interface methods")] [Define ("IL_ASSEMBLY_AVAILABLE")] [SetupCompileBefore ("library.dll", new[] { "Dependencies/TypeHierarchyBasic.il" })] [KeptMemberInAssembly ("library.dll", "InterfaceScenario1", "Method()")] diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/StaticInterfaceMethods/TypeHierarchyFull.cs b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/StaticInterfaceMethods/TypeHierarchyFull.cs index 201a09e31..24750e982 100644 --- a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/StaticInterfaceMethods/TypeHierarchyFull.cs +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/StaticInterfaceMethods/TypeHierarchyFull.cs @@ -7,9 +7,7 @@ using Mono.Linker.Tests.Cases.Expectations.Metadata; namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces.StaticInterfaceMethods { [SetupLinkerArgument ("--skip-unresolved", "true")] -#if !NETCOREAPP - [IgnoreTestCase("Only for .NET Core for some reason")] -#endif + [TestCaseRequirements (TestRunCharacteristics.SupportsStaticInterfaceMethods, "Requires a framework that supports static interface methods")] [Define ("IL_ASSEMBLY_AVAILABLE")] [SetupCompileBefore ("library.dll", new[] { "Dependencies/TypeHierarchyFull.il" })] diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/StaticInterfaceMethods/VarianceBasic.cs b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/StaticInterfaceMethods/VarianceBasic.cs index 35c3fadde..414290e39 100644 --- a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/StaticInterfaceMethods/VarianceBasic.cs +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/StaticInterfaceMethods/VarianceBasic.cs @@ -7,9 +7,7 @@ using Mono.Linker.Tests.Cases.Expectations.Metadata; namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces.StaticInterfaceMethods { [SetupLinkerArgument ("--skip-unresolved", "true")] -#if !NETCOREAPP - [IgnoreTestCase("Only for .NET Core for some reason")] -#endif + [TestCaseRequirements (TestRunCharacteristics.SupportsStaticInterfaceMethods, "Requires a framework that supports static interface methods")] [Define ("IL_ASSEMBLY_AVAILABLE")] [SetupCompileBefore ("library.dll", new[] { "Dependencies/VarianceBasic.il" })] diff --git a/test/Mono.Linker.Tests.Cases/Libraries/CopyUsedAssemblyWithMainEntryRoot.cs b/test/Mono.Linker.Tests.Cases/Libraries/CopyUsedAssemblyWithMainEntryRoot.cs index 7373fa05c..1aa6bdace 100644 --- a/test/Mono.Linker.Tests.Cases/Libraries/CopyUsedAssemblyWithMainEntryRoot.cs +++ b/test/Mono.Linker.Tests.Cases/Libraries/CopyUsedAssemblyWithMainEntryRoot.cs @@ -4,9 +4,6 @@ using Mono.Linker.Tests.Cases.Libraries.Dependencies; namespace Mono.Linker.Tests.Cases.Libraries { -#if !NETCOREAPP - [IgnoreTestCase ("Correctly handled by illink only")] -#endif [Kept] [KeptMember (".ctor()")] [SetupLinkerAction ("copyused", "test")] diff --git a/test/Mono.Linker.Tests.Cases/Libraries/CopyUsedAssemblyWithPublicRoots.cs b/test/Mono.Linker.Tests.Cases/Libraries/CopyUsedAssemblyWithPublicRoots.cs index 32f5cae83..b3e7bca6b 100644 --- a/test/Mono.Linker.Tests.Cases/Libraries/CopyUsedAssemblyWithPublicRoots.cs +++ b/test/Mono.Linker.Tests.Cases/Libraries/CopyUsedAssemblyWithPublicRoots.cs @@ -3,9 +3,6 @@ using Mono.Linker.Tests.Cases.Expectations.Metadata; namespace Mono.Linker.Tests.Cases.Libraries { -#if !NETCOREAPP - [IgnoreTestCase ("Correctly handled by illink only")] -#endif [Kept] [KeptMember (".ctor()")] [SetupLinkerAction ("copyused", "test")] diff --git a/test/Mono.Linker.Tests.Cases/Libraries/RootLibraryInternalsWithIVT.cs b/test/Mono.Linker.Tests.Cases/Libraries/RootLibraryInternalsWithIVT.cs index 4e96cb92c..4e0fa2deb 100644 --- a/test/Mono.Linker.Tests.Cases/Libraries/RootLibraryInternalsWithIVT.cs +++ b/test/Mono.Linker.Tests.Cases/Libraries/RootLibraryInternalsWithIVT.cs @@ -10,9 +10,6 @@ using Mono.Linker.Tests.Cases.Expectations.Metadata; namespace Mono.Linker.Tests.Cases.Libraries { -#if !NETCOREAPP - [IgnoreTestCase ("Build with illink")] -#endif [Kept] [KeptMember (".ctor()")] [SetupLinkerLinkPublicAndFamily] diff --git a/test/Mono.Linker.Tests.Cases/Libraries/RootLibraryVisibleAndDescriptor.cs b/test/Mono.Linker.Tests.Cases/Libraries/RootLibraryVisibleAndDescriptor.cs index 0535e45ce..0f3309358 100644 --- a/test/Mono.Linker.Tests.Cases/Libraries/RootLibraryVisibleAndDescriptor.cs +++ b/test/Mono.Linker.Tests.Cases/Libraries/RootLibraryVisibleAndDescriptor.cs @@ -4,9 +4,6 @@ using Mono.Linker.Tests.Cases.Expectations.Metadata; namespace Mono.Linker.Tests.Cases.Libraries { -#if !NETCOREAPP - [IgnoreTestCase ("Build with illink")] -#endif [Kept] [KeptMember (".ctor()")] [SetupLinkerLinkPublicAndFamily] diff --git a/test/Mono.Linker.Tests.Cases/Libraries/RootLibraryVisibleForwarders.cs b/test/Mono.Linker.Tests.Cases/Libraries/RootLibraryVisibleForwarders.cs index c82831501..09e3fed90 100644 --- a/test/Mono.Linker.Tests.Cases/Libraries/RootLibraryVisibleForwarders.cs +++ b/test/Mono.Linker.Tests.Cases/Libraries/RootLibraryVisibleForwarders.cs @@ -8,9 +8,6 @@ using Mono.Linker.Tests.Cases.Expectations.Metadata; namespace Mono.Linker.Tests.Cases.Libraries { -#if !NETCOREAPP - [IgnoreTestCase ("Build with illink")] -#endif [SetupCompileBefore ("library.dll", new[] { "Dependencies/RootLibraryVisibleForwarders_Lib.cs" })] [SetupLinkerLinkPublicAndFamily] [Define ("RootLibraryVisibleForwarders")] diff --git a/test/Mono.Linker.Tests.Cases/Libraries/RootLibraryVisibleForwardersWithoutReference.cs b/test/Mono.Linker.Tests.Cases/Libraries/RootLibraryVisibleForwardersWithoutReference.cs index 877d2a289..bf566ead6 100644 --- a/test/Mono.Linker.Tests.Cases/Libraries/RootLibraryVisibleForwardersWithoutReference.cs +++ b/test/Mono.Linker.Tests.Cases/Libraries/RootLibraryVisibleForwardersWithoutReference.cs @@ -8,9 +8,6 @@ using Mono.Linker.Tests.Cases.Expectations.Metadata; namespace Mono.Linker.Tests.Cases.Libraries { -#if !NETCOREAPP - [IgnoreTestCase ("Build with illink")] -#endif [SetupCompileBefore ("library.dll", new[] { "Dependencies/RootLibraryVisibleForwarders_Lib.cs" }, outputSubFolder: "isolated")] [SetupLinkerLinkPublicAndFamily] [SetupLinkerArgument ("-a", "isolated/library.dll", "visible")] // Checks for no-eager exported type resolving diff --git a/test/Mono.Linker.Tests.Cases/LinkXml/CanPreserveExcludedFeatureCom.cs b/test/Mono.Linker.Tests.Cases/LinkXml/CanPreserveExcludedFeatureCom.cs index 223741227..169da0b98 100644 --- a/test/Mono.Linker.Tests.Cases/LinkXml/CanPreserveExcludedFeatureCom.cs +++ b/test/Mono.Linker.Tests.Cases/LinkXml/CanPreserveExcludedFeatureCom.cs @@ -5,9 +5,7 @@ using Mono.Linker.Tests.Cases.Expectations.Metadata; namespace Mono.Linker.Tests.Cases.LinkXml { -#if NETCOREAPP - [IgnoreTestCase ("--exclude-feature is not supported on .NET Core")] -#endif + [TestCaseRequirements (TestRunCharacteristics.TargetingNetFramework, "--exclude-feature is not supported on .NET Core")] [SetupLinkerArgument ("--exclude-feature", "com")] [SetupLinkerDescriptorFile ("CanPreserveExcludedFeatureCom.xml")] public class CanPreserveExcludedFeatureCom diff --git a/test/Mono.Linker.Tests.Cases/LinkXml/FeatureExclude/OnAssembly.cs b/test/Mono.Linker.Tests.Cases/LinkXml/FeatureExclude/OnAssembly.cs index 7cc91f8f6..6f53fcf0a 100644 --- a/test/Mono.Linker.Tests.Cases/LinkXml/FeatureExclude/OnAssembly.cs +++ b/test/Mono.Linker.Tests.Cases/LinkXml/FeatureExclude/OnAssembly.cs @@ -4,9 +4,7 @@ using Mono.Linker.Tests.Cases.LinkXml.FeatureExclude.Dependencies; namespace Mono.Linker.Tests.Cases.LinkXml.FeatureExclude { -#if NETCOREAPP - [IgnoreTestCase ("--exclude-feature is not supported on .NET Core")] -#endif + [TestCaseRequirements (TestRunCharacteristics.TargetingNetFramework, "--exclude-feature is not supported on .NET Core")] [SetupLinkerArgument ("--exclude-feature", "one")] [SetupCompileBefore ("library1.dll", new[] { typeof (OnAssembly_Lib1) })] [SetupCompileBefore ("library2.dll", new[] { typeof (OnAssembly_Lib2) })] diff --git a/test/Mono.Linker.Tests.Cases/LinkXml/FeatureExclude/OnEvent.cs b/test/Mono.Linker.Tests.Cases/LinkXml/FeatureExclude/OnEvent.cs index ad5116cbf..47ae4e649 100644 --- a/test/Mono.Linker.Tests.Cases/LinkXml/FeatureExclude/OnEvent.cs +++ b/test/Mono.Linker.Tests.Cases/LinkXml/FeatureExclude/OnEvent.cs @@ -4,9 +4,7 @@ using Mono.Linker.Tests.Cases.Expectations.Metadata; namespace Mono.Linker.Tests.Cases.LinkXml.FeatureExclude { -#if NETCOREAPP - [IgnoreTestCase ("--exclude-feature is not supported on .NET Core")] -#endif + [TestCaseRequirements (TestRunCharacteristics.TargetingNetFramework, "--exclude-feature is not supported on .NET Core")] [SetupLinkerArgument ("--exclude-feature", "one")] [SetupLinkerDescriptorFile ("OnEvent.xml")] public class OnEvent diff --git a/test/Mono.Linker.Tests.Cases/LinkXml/FeatureExclude/OnField.cs b/test/Mono.Linker.Tests.Cases/LinkXml/FeatureExclude/OnField.cs index 319e53092..0fcea8b37 100644 --- a/test/Mono.Linker.Tests.Cases/LinkXml/FeatureExclude/OnField.cs +++ b/test/Mono.Linker.Tests.Cases/LinkXml/FeatureExclude/OnField.cs @@ -3,9 +3,7 @@ using Mono.Linker.Tests.Cases.Expectations.Metadata; namespace Mono.Linker.Tests.Cases.LinkXml.FeatureExclude { -#if NETCOREAPP - [IgnoreTestCase ("--exclude-feature is not supported on .NET Core")] -#endif + [TestCaseRequirements (TestRunCharacteristics.TargetingNetFramework, "--exclude-feature is not supported on .NET Core")] [SetupLinkerArgument ("--exclude-feature", "one")] [SetupLinkerDescriptorFile ("OnField.xml")] public class OnField diff --git a/test/Mono.Linker.Tests.Cases/LinkXml/FeatureExclude/OnMethod.cs b/test/Mono.Linker.Tests.Cases/LinkXml/FeatureExclude/OnMethod.cs index a59b3d8f0..503a5a483 100644 --- a/test/Mono.Linker.Tests.Cases/LinkXml/FeatureExclude/OnMethod.cs +++ b/test/Mono.Linker.Tests.Cases/LinkXml/FeatureExclude/OnMethod.cs @@ -3,9 +3,7 @@ using Mono.Linker.Tests.Cases.Expectations.Metadata; namespace Mono.Linker.Tests.Cases.LinkXml.FeatureExclude { -#if NETCOREAPP - [IgnoreTestCase ("--exclude-feature is not supported on .NET Core")] -#endif + [TestCaseRequirements (TestRunCharacteristics.TargetingNetFramework, "--exclude-feature is not supported on .NET Core")] [SetupLinkerArgument ("--exclude-feature", "one")] [SetupLinkerDescriptorFile ("OnMethod.xml")] public class OnMethod diff --git a/test/Mono.Linker.Tests.Cases/LinkXml/FeatureExclude/OnProperty.cs b/test/Mono.Linker.Tests.Cases/LinkXml/FeatureExclude/OnProperty.cs index 59618d9ba..eae178bae 100644 --- a/test/Mono.Linker.Tests.Cases/LinkXml/FeatureExclude/OnProperty.cs +++ b/test/Mono.Linker.Tests.Cases/LinkXml/FeatureExclude/OnProperty.cs @@ -3,9 +3,7 @@ using Mono.Linker.Tests.Cases.Expectations.Metadata; namespace Mono.Linker.Tests.Cases.LinkXml.FeatureExclude { -#if NETCOREAPP - [IgnoreTestCase ("--exclude-feature is not supported on .NET Core")] -#endif + [TestCaseRequirements (TestRunCharacteristics.TargetingNetFramework, "--exclude-feature is not supported on .NET Core")] [SetupLinkerArgument ("--exclude-feature", "one")] [SetupLinkerDescriptorFile ("OnProperty.xml")] public class OnProperty diff --git a/test/Mono.Linker.Tests.Cases/LinkXml/FeatureExclude/OnType.cs b/test/Mono.Linker.Tests.Cases/LinkXml/FeatureExclude/OnType.cs index b789958f6..d21e10c4e 100644 --- a/test/Mono.Linker.Tests.Cases/LinkXml/FeatureExclude/OnType.cs +++ b/test/Mono.Linker.Tests.Cases/LinkXml/FeatureExclude/OnType.cs @@ -3,9 +3,7 @@ using Mono.Linker.Tests.Cases.Expectations.Metadata; namespace Mono.Linker.Tests.Cases.LinkXml.FeatureExclude { -#if NETCOREAPP - [IgnoreTestCase ("--exclude-feature is not supported on .NET Core")] -#endif + [TestCaseRequirements (TestRunCharacteristics.TargetingNetFramework, "--exclude-feature is not supported on .NET Core")] [SetupLinkerArgument ("--exclude-feature", "one")] [SetupLinkerDescriptorFile ("OnType.xml")] public class OnType diff --git a/test/Mono.Linker.Tests.Cases/Logging/CommonLogs.cs b/test/Mono.Linker.Tests.Cases/Logging/CommonLogs.cs index 1ced566df..a65685c90 100644 --- a/test/Mono.Linker.Tests.Cases/Logging/CommonLogs.cs +++ b/test/Mono.Linker.Tests.Cases/Logging/CommonLogs.cs @@ -3,12 +3,7 @@ using Mono.Linker.Tests.Cases.Expectations.Metadata; namespace Mono.Linker.Tests.Cases.Logging { - -#if !NETCOREAPP - [IgnoreTestCase ("Can be enabled once MonoBuild produces a dll from which we can grab the types in the Mono.Linker namespace.")] -#else [SetupCompileBefore ("LogStep.dll", new[] { "Dependencies/LogStep.cs" }, new[] { "illink.dll", "Mono.Cecil.dll" })] -#endif [SetupLinkerArgument ("--custom-step", "Log.LogStep,LogStep.dll")] [SetupLinkerArgument ("--verbose")] [LogContains ("ILLink: error IL6001: Error")] diff --git a/test/Mono.Linker.Tests.Cases/Mono.Linker.Tests.Cases.csproj b/test/Mono.Linker.Tests.Cases/Mono.Linker.Tests.Cases.csproj index 71a33ea86..29cde9ab6 100644 --- a/test/Mono.Linker.Tests.Cases/Mono.Linker.Tests.Cases.csproj +++ b/test/Mono.Linker.Tests.Cases/Mono.Linker.Tests.Cases.csproj @@ -1,7 +1,7 @@ <Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> - <DefineConstants>$(DefineConstants);INCLUDE_EXPECTATIONS</DefineConstants> + <DefineConstants>$(DefineConstants);INCLUDE_EXPECTATIONS;SUPPORTS_DEFAULT_INTERFACE_METHODS</DefineConstants> <WarningLevel>0</WarningLevel> <AnalysisLevel>0</AnalysisLevel> <AllowUnsafeBlocks>true</AllowUnsafeBlocks> diff --git a/test/Mono.Linker.Tests.Cases/PreserveDependencies/PreserveDependencyDeprecated.cs b/test/Mono.Linker.Tests.Cases/PreserveDependencies/PreserveDependencyDeprecated.cs index 90bd398d4..20d204586 100644 --- a/test/Mono.Linker.Tests.Cases/PreserveDependencies/PreserveDependencyDeprecated.cs +++ b/test/Mono.Linker.Tests.Cases/PreserveDependencies/PreserveDependencyDeprecated.cs @@ -4,9 +4,7 @@ using Mono.Linker.Tests.Cases.Expectations.Metadata; namespace Mono.Linker.Tests.Cases.PreserveDependencies { -#if !NETCOREAPP - [IgnoreTestCase ("This test checks that PreserveDependency correctly issues a warning on .NET Core where it is deprecated.")] -#endif + [TestCaseRequirements (TestRunCharacteristics.TargetingNetCore, "This test checks that PreserveDependency correctly issues a warning on .NET Core where it is deprecated.")] [SetupCompileBefore ("FakeSystemAssembly.dll", new[] { "Dependencies/PreserveDependencyAttribute.cs" })] class PreserveDependencyDeprecated { diff --git a/test/Mono.Linker.Tests.Cases/References/ReferencesAreRemovedWhenAllUsagesAreRemoved.cs b/test/Mono.Linker.Tests.Cases/References/ReferencesAreRemovedWhenAllUsagesAreRemoved.cs index 31f8502c7..045607bc9 100644 --- a/test/Mono.Linker.Tests.Cases/References/ReferencesAreRemovedWhenAllUsagesAreRemoved.cs +++ b/test/Mono.Linker.Tests.Cases/References/ReferencesAreRemovedWhenAllUsagesAreRemoved.cs @@ -5,9 +5,7 @@ using Mono.Linker.Tests.Cases.Expectations.Metadata; namespace Mono.Linker.Tests.Cases.References { -#if NETCOREAPP - [IgnoreTestCase ("Asserts are specific to .NET Framework")] -#endif + [TestCaseRequirements (TestRunCharacteristics.TargetingNetFramework, "Asserts are specific to .NET Framework")] [SetupLinkerTrimMode ("link")] // Il8n & the blacklist step pollute the results with extra stuff that didn't need to be // preserved for this test case so we need to disable them diff --git a/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithMdbAndSymbolLinkingEnabled.cs b/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithMdbAndSymbolLinkingEnabled.cs index faa78652c..c01959493 100644 --- a/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithMdbAndSymbolLinkingEnabled.cs +++ b/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithMdbAndSymbolLinkingEnabled.cs @@ -5,9 +5,7 @@ using Mono.Linker.Tests.Cases.Symbols.Dependencies; namespace Mono.Linker.Tests.Cases.Symbols { -#if NETCOREAPP - [IgnoreTestCase ("mdb files are not supported with .NET Core")] -#endif + [TestCaseRequirements (TestRunCharacteristics.TargetingNetFramework, "mdb files are not supported with .NET Core")] [Reference ("Dependencies/LibraryWithMdb/LibraryWithMdb.dll")] [ReferenceDependency ("Dependencies/LibraryWithMdb/LibraryWithMdb.dll.mdb")] [SetupLinkerLinkSymbols ("true")] diff --git a/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithMdbAndSymbolLinkingEnabledAndDeterministicMvid.cs b/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithMdbAndSymbolLinkingEnabledAndDeterministicMvid.cs index 6f7bff937..bb477b7b0 100644 --- a/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithMdbAndSymbolLinkingEnabledAndDeterministicMvid.cs +++ b/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithMdbAndSymbolLinkingEnabledAndDeterministicMvid.cs @@ -4,9 +4,7 @@ using Mono.Linker.Tests.Cases.Symbols.Dependencies; namespace Mono.Linker.Tests.Cases.Symbols { -#if NETCOREAPP - [IgnoreTestCase ("mdb files are not supported with .NET Core")] -#endif + [TestCaseRequirements (TestRunCharacteristics.TargetingNetFramework, "mdb files are not supported with .NET Core")] [Reference ("Dependencies/LibraryWithMdb/LibraryWithMdb.dll")] [ReferenceDependency ("Dependencies/LibraryWithMdb/LibraryWithMdb.dll.mdb")] [SetupLinkerLinkSymbols ("true")] diff --git a/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithMdbAndSymbolLinkingEnabledAndNewMvid.cs b/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithMdbAndSymbolLinkingEnabledAndNewMvid.cs index bf9c60540..68291c12b 100644 --- a/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithMdbAndSymbolLinkingEnabledAndNewMvid.cs +++ b/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithMdbAndSymbolLinkingEnabledAndNewMvid.cs @@ -4,9 +4,7 @@ using Mono.Linker.Tests.Cases.Symbols.Dependencies; namespace Mono.Linker.Tests.Cases.Symbols { -#if NETCOREAPP - [IgnoreTestCase ("mdb files are not supported with .NET Core")] -#endif + [TestCaseRequirements (TestRunCharacteristics.TargetingNetFramework, "mdb files are not supported with .NET Core")] [Reference ("Dependencies/LibraryWithMdb/LibraryWithMdb.dll")] [ReferenceDependency ("Dependencies/LibraryWithMdb/LibraryWithMdb.dll.mdb")] [SetupLinkerLinkSymbols ("true")] diff --git a/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithMdbCopyActionAndSymbolLinkingEnabled.cs b/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithMdbCopyActionAndSymbolLinkingEnabled.cs index af8638778..04eeb8452 100644 --- a/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithMdbCopyActionAndSymbolLinkingEnabled.cs +++ b/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithMdbCopyActionAndSymbolLinkingEnabled.cs @@ -4,9 +4,7 @@ using Mono.Linker.Tests.Cases.Symbols.Dependencies; namespace Mono.Linker.Tests.Cases.Symbols { -#if NETCOREAPP - [IgnoreTestCase ("mdb files are not supported with .NET Core")] -#endif + [TestCaseRequirements (TestRunCharacteristics.TargetingNetFramework, "mdb files are not supported with .NET Core")] [Reference ("Dependencies/LibraryWithMdb/LibraryWithMdb.dll")] [ReferenceDependency ("Dependencies/LibraryWithMdb/LibraryWithMdb.dll.mdb")] [SetupLinkerLinkSymbols ("true")] diff --git a/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithPdbCopyActionAndSymbolLinkingEnabled.cs b/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithPdbCopyActionAndSymbolLinkingEnabled.cs index e457b9952..f7b3e6864 100644 --- a/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithPdbCopyActionAndSymbolLinkingEnabled.cs +++ b/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithPdbCopyActionAndSymbolLinkingEnabled.cs @@ -4,13 +4,14 @@ using Mono.Linker.Tests.Cases.Symbols.Dependencies; namespace Mono.Linker.Tests.Cases.Symbols { -#if NETCOREAPP && !WIN32 +#if !WIN32 // .NET Core type forwarders cause the assembly action to be // changed from "copy" to "save" (to remove references to removed // typeforwarders). However, saving the native PDB is only // supported on windows. - [IgnoreTestCase ("Only supported on Windows on .NET Core.")] + [IgnoreTestCase ("Only supported on Windows")] #endif + [TestCaseRequirements (TestRunCharacteristics.TargetingNetFramework, "Only supported on Windows on .NET Framework.")] [Reference ("Dependencies/LibraryWithPdb/LibraryWithPdb.dll")] [ReferenceDependency ("Dependencies/LibraryWithPdb/LibraryWithPdb.pdb")] [SetupLinkerLinkSymbols ("true")] diff --git a/test/Mono.Linker.Tests.Cases/Symbols/ReferencesWithMixedSymbolTypesAndSymbolLinkingEnabled.cs b/test/Mono.Linker.Tests.Cases/Symbols/ReferencesWithMixedSymbolTypesAndSymbolLinkingEnabled.cs index 0cc9358bc..646cbaf5e 100644 --- a/test/Mono.Linker.Tests.Cases/Symbols/ReferencesWithMixedSymbolTypesAndSymbolLinkingEnabled.cs +++ b/test/Mono.Linker.Tests.Cases/Symbols/ReferencesWithMixedSymbolTypesAndSymbolLinkingEnabled.cs @@ -6,11 +6,6 @@ using Mono.Linker.Tests.Cases.Symbols.Dependencies; namespace Mono.Linker.Tests.Cases.Symbols { [SetupLinkerArgument ("--skip-unresolved", "true")] -#if !NETCOREAPP - [Reference ("Dependencies/LibraryWithMdb/LibraryWithMdb.dll")] - [ReferenceDependency ("Dependencies/LibraryWithMdb/LibraryWithMdb.dll.mdb")] -#endif - [Reference ("Dependencies/LibraryWithPdb/LibraryWithPdb.dll")] [ReferenceDependency ("Dependencies/LibraryWithPdb/LibraryWithPdb.pdb")] @@ -22,9 +17,6 @@ namespace Mono.Linker.Tests.Cases.Symbols [SetupLinkerLinkSymbols ("true")] [KeptSymbols ("test.exe")] -#if !NETCOREAPP - [KeptSymbols ("LibraryWithMdb.dll")] -#endif #if WIN32 [KeptSymbols ("LibraryWithPdb.dll")] #else @@ -34,12 +26,6 @@ namespace Mono.Linker.Tests.Cases.Symbols [KeptSymbols ("LibraryWithEmbeddedPdbSymbols.dll")] [KeptSymbols ("LibraryWithPortablePdbSymbols.dll")] - -#if !NETCOREAPP - [KeptMemberInAssembly ("LibraryWithMdb.dll", typeof (LibraryWithMdb), "SomeMethod()")] - [RemovedMemberInAssembly ("LibraryWithMdb.dll", typeof (LibraryWithMdb), "NotUsed()")] -#endif - [KeptMemberInAssembly ("LibraryWithPdb.dll", typeof (LibraryWithPdb), "SomeMethod()")] [RemovedMemberInAssembly ("LibraryWithPdb.dll", typeof (LibraryWithPdb), "NotUsed()")] @@ -59,9 +45,6 @@ namespace Mono.Linker.Tests.Cases.Symbols SomeMethod (); LibraryWithCompilerDefaultSymbols.SomeMethod (); LibraryWithPdb.SomeMethod (); -#if !NETCOREAPP - LibraryWithMdb.SomeMethod (); -#endif LibraryWithEmbeddedPdbSymbols.SomeMethod (); LibraryWithPortablePdbSymbols.SomeMethod (); } diff --git a/test/Mono.Linker.Tests.Cases/Symbols/ReferencesWithMixedSymbolTypesWithMdbAndSymbolLinkingEnabled.cs b/test/Mono.Linker.Tests.Cases/Symbols/ReferencesWithMixedSymbolTypesWithMdbAndSymbolLinkingEnabled.cs new file mode 100644 index 000000000..179e6be96 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Symbols/ReferencesWithMixedSymbolTypesWithMdbAndSymbolLinkingEnabled.cs @@ -0,0 +1,73 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; +using Mono.Linker.Tests.Cases.Symbols.Dependencies; + +namespace Mono.Linker.Tests.Cases.Symbols +{ + [TestCaseRequirements (TestRunCharacteristics.TargetingNetFramework, "mdb files are not supported with .NET Core")] + [SetupLinkerArgument ("--skip-unresolved", "true")] + [Reference ("Dependencies/LibraryWithMdb/LibraryWithMdb.dll")] + [ReferenceDependency ("Dependencies/LibraryWithMdb/LibraryWithMdb.dll.mdb")] + + [Reference ("Dependencies/LibraryWithPdb/LibraryWithPdb.dll")] + [ReferenceDependency ("Dependencies/LibraryWithPdb/LibraryWithPdb.pdb")] + + [SetupCompileBefore ("LibraryWithCompilerDefaultSymbols.dll", new[] { "Dependencies/LibraryWithCompilerDefaultSymbols.cs" }, additionalArguments: "/debug:full")] + [SetupCompileBefore ("LibraryWithPortablePdbSymbols.dll", new[] { "Dependencies/LibraryWithPortablePdbSymbols.cs" }, additionalArguments: "/debug:portable", compilerToUse: "csc")] + [SetupCompileBefore ("LibraryWithEmbeddedPdbSymbols.dll", new[] { "Dependencies/LibraryWithEmbeddedPdbSymbols.cs" }, additionalArguments: "/debug:embedded", compilerToUse: "csc")] + + [SetupCompileArgument ("/debug:full")] + [SetupLinkerLinkSymbols ("true")] + + [KeptSymbols ("test.exe")] + [KeptSymbols ("LibraryWithMdb.dll")] +#if WIN32 + [KeptSymbols ("LibraryWithPdb.dll")] +#else + [RemovedSymbols ("LibraryWithPdb.dll")] +#endif + [KeptSymbols ("LibraryWithCompilerDefaultSymbols.dll")] + [KeptSymbols ("LibraryWithEmbeddedPdbSymbols.dll")] + [KeptSymbols ("LibraryWithPortablePdbSymbols.dll")] + + [KeptMemberInAssembly ("LibraryWithMdb.dll", typeof (LibraryWithMdb), "SomeMethod()")] + [RemovedMemberInAssembly ("LibraryWithMdb.dll", typeof (LibraryWithMdb), "NotUsed()")] + + [KeptMemberInAssembly ("LibraryWithPdb.dll", typeof (LibraryWithPdb), "SomeMethod()")] + [RemovedMemberInAssembly ("LibraryWithPdb.dll", typeof (LibraryWithPdb), "NotUsed()")] + + [KeptMemberInAssembly ("LibraryWithCompilerDefaultSymbols.dll", typeof (LibraryWithCompilerDefaultSymbols), "SomeMethod()")] + [RemovedMemberInAssembly ("LibraryWithCompilerDefaultSymbols.dll", typeof (LibraryWithCompilerDefaultSymbols), "NotUsed()")] + + [KeptMemberInAssembly ("LibraryWithEmbeddedPdbSymbols.dll", typeof (LibraryWithEmbeddedPdbSymbols), "SomeMethod()")] + [RemovedMemberInAssembly ("LibraryWithEmbeddedPdbSymbols.dll", typeof (LibraryWithEmbeddedPdbSymbols), "NotUsed()")] + + [KeptMemberInAssembly ("LibraryWithPortablePdbSymbols.dll", typeof (LibraryWithPortablePdbSymbols), "SomeMethod()")] + [RemovedMemberInAssembly ("LibraryWithPortablePdbSymbols.dll", typeof (LibraryWithPortablePdbSymbols), "NotUsed()")] + public class ReferencesWithMixedSymbolTypesWithMdbAndSymbolLinkingEnabled + { + static void Main () + { + // Use some stuff so that we can verify that the linker output correct results + SomeMethod (); + LibraryWithCompilerDefaultSymbols.SomeMethod (); + LibraryWithPdb.SomeMethod (); + LibraryWithMdb.SomeMethod (); + LibraryWithEmbeddedPdbSymbols.SomeMethod (); + LibraryWithPortablePdbSymbols.SomeMethod (); + } + + [Kept] + static void SomeMethod () + { + } + + static void NotUsed () + { + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/TestFramework/CanCompileReferencesWithResourcesWithMcs.cs b/test/Mono.Linker.Tests.Cases/TestFramework/CanCompileReferencesWithResourcesWithMcs.cs index ba244d272..a71b1f258 100644 --- a/test/Mono.Linker.Tests.Cases/TestFramework/CanCompileReferencesWithResourcesWithMcs.cs +++ b/test/Mono.Linker.Tests.Cases/TestFramework/CanCompileReferencesWithResourcesWithMcs.cs @@ -4,9 +4,7 @@ using Mono.Linker.Tests.Cases.TestFramework.Dependencies; namespace Mono.Linker.Tests.Cases.TestFramework { -#if NETCOREAPP - [IgnoreTestCase ("Don't try to compile with mcs on .NET Core")] -#endif + [TestCaseRequirements (TestRunCharacteristics.TestFrameworkSupportsMcs, "A test framework that supports using mcs is required")] [SetupCompileBefore ("library.dll", new[] { "Dependencies/CanCompileReferencesWithResources_Lib1.cs" }, resources: new object[] { "Dependencies/CanCompileReferencesWithResources_Lib1.txt" }, diff --git a/test/Mono.Linker.Tests.Cases/TestFramework/CanCompileTestCaseWithMcs.cs b/test/Mono.Linker.Tests.Cases/TestFramework/CanCompileTestCaseWithMcs.cs index b7986d035..78a468e26 100644 --- a/test/Mono.Linker.Tests.Cases/TestFramework/CanCompileTestCaseWithMcs.cs +++ b/test/Mono.Linker.Tests.Cases/TestFramework/CanCompileTestCaseWithMcs.cs @@ -5,9 +5,7 @@ using Mono.Linker.Tests.Cases.TestFramework.Dependencies; namespace Mono.Linker.Tests.Cases.TestFramework { -#if NETCOREAPP - [IgnoreTestCase ("Don't try to compile with mcs on .NET Core.")] -#endif + [TestCaseRequirements (TestRunCharacteristics.TestFrameworkSupportsMcs, "A test framework that supports using mcs is required")] [SetupCSharpCompilerToUse ("mcs")] // Use all of the compiler setup attributes so that we can verify they all work diff --git a/test/Mono.Linker.Tests.Cases/TestFramework/VerifyExpectModifiedAttributesWork.cs b/test/Mono.Linker.Tests.Cases/TestFramework/VerifyExpectModifiedAttributesWork.cs index 99d3a8832..4b03a4afe 100644 --- a/test/Mono.Linker.Tests.Cases/TestFramework/VerifyExpectModifiedAttributesWork.cs +++ b/test/Mono.Linker.Tests.Cases/TestFramework/VerifyExpectModifiedAttributesWork.cs @@ -9,9 +9,7 @@ namespace Mono.Linker.Tests.Cases.TestFramework /// This test is here to give some coverage to the attribute to ensure it doesn't break. We need to leverage the ETW feature since it is the only /// one that modifies bodies currently /// </summary> -#if NETCOREAPP - [IgnoreTestCase ("--exclude-feature is not supported on .NET Core")] -#endif + [TestCaseRequirements (TestRunCharacteristics.TargetingNetFramework, "--exclude-feature is not supported on .NET Core")] [SetupLinkerArgument ("--exclude-feature", "etw")] // Keep framework code that calls EventSource methods like OnEventCommand [SetupLinkerTrimMode ("skip")] diff --git a/test/Mono.Linker.Tests.Cases/Warnings/Individual/CustomStepWithWarnings.cs b/test/Mono.Linker.Tests.Cases/Warnings/Individual/CustomStepWithWarnings.cs index 32037375b..0bb4f194e 100644 --- a/test/Mono.Linker.Tests.Cases/Warnings/Individual/CustomStepWithWarnings.cs +++ b/test/Mono.Linker.Tests.Cases/Warnings/Individual/CustomStepWithWarnings.cs @@ -12,11 +12,7 @@ using Mono.Linker.Tests.Cases.Expectations.Metadata; namespace Mono.Linker.Tests.Cases.Warnings.Individual { -#if !NETCOREAPP - [IgnoreTestCase ("Can be enabled once MonoBuild produces a dll from which we can grab the types in the Mono.Linker namespace.")] -#else [SetupCompileBefore ("CustomStep.dll", new[] { "../Dependencies/CustomStep.cs" }, new[] { "illink.dll" })] -#endif [SetupLinkerArgument ("--custom-step", "CustomStep.CustomStep,CustomStep.dll")] [SetupLinkerArgument ("--custom-step", "CustomStep.CustomStepWithInvalidWarningCode,CustomStep.dll")] [LogContains ("CustomStep.cs(1,1): warning IL6001: Warning")] diff --git a/test/Mono.Linker.Tests.Cases/Warnings/WarningSuppression/SuppressWarningsUsingTargetViaXml.cs b/test/Mono.Linker.Tests.Cases/Warnings/WarningSuppression/SuppressWarningsUsingTargetViaXmlMono.cs index 1b33f6a4c..30eae7ce1 100644 --- a/test/Mono.Linker.Tests.Cases/Warnings/WarningSuppression/SuppressWarningsUsingTargetViaXml.cs +++ b/test/Mono.Linker.Tests.Cases/Warnings/WarningSuppression/SuppressWarningsUsingTargetViaXmlMono.cs @@ -1,33 +1,27 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; -using System.Text; +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + using Mono.Linker.Tests.Cases.Expectations.Assertions; using Mono.Linker.Tests.Cases.Expectations.Metadata; using Mono.Linker.Tests.Cases.Warnings.Dependencies; namespace Mono.Linker.Tests.Cases.Warnings.WarningSuppression { - // For netcoreapp we don't have to specify the assembly for the attribute, since the attribute comes from corelib - // and will be found always. + [TestCaseRequirements (TestRunCharacteristics.TargetingNetFramework, "This test is specific to .NET Framework")] // For mono though, we have to specify the assembly (Mono.Linker.Tests.Cases.Expectations) because at the time of processing // that assembly is not yet loaded into the closure in the linker, so it won't find the attribute type. -#if NETCOREAPP - [SetupLinkAttributesFile ("SuppressWarningsUsingTargetViaXml.netcore.xml")] - [SetupCompileBefore ("library.dll", new[] { typeof (TriggerWarnings_Lib) }, new[] { "System.Core.dll" })] -#else [SetupLinkAttributesFile ("SuppressWarningsUsingTargetViaXml.mono.xml")] - [SetupCompileBefore ("library.dll", new[] { typeof (TriggerWarnings_Lib) })] -#endif + [SetupCompileBefore ("library.dll", new[] { typeof (TriggerWarnings_Lib) }, new[] { "System.Core.dll" })] [KeptAssembly ("library.dll")] [SetupLinkerAction ("link", "library.dll")] [LogDoesNotContain ("TriggerUnrecognizedPattern()")] - public class SuppressWarningsUsingTargetViaXml + public class SuppressWarningsUsingTargetViaXmlMono { public static void Main () { TriggerWarnings_Lib.Main (); } } -} +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Warnings/WarningSuppression/SuppressWarningsUsingTargetViaXmlNetCore.cs b/test/Mono.Linker.Tests.Cases/Warnings/WarningSuppression/SuppressWarningsUsingTargetViaXmlNetCore.cs new file mode 100644 index 000000000..d908680af --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Warnings/WarningSuppression/SuppressWarningsUsingTargetViaXmlNetCore.cs @@ -0,0 +1,27 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; +using Mono.Linker.Tests.Cases.Warnings.Dependencies; + +namespace Mono.Linker.Tests.Cases.Warnings.WarningSuppression +{ + [TestCaseRequirements (TestRunCharacteristics.TargetingNetCore, "This test is specific to .NET Core")] + // For netcoreapp we don't have to specify the assembly for the attribute, since the attribute comes from corelib + // and will be found always. + [SetupLinkAttributesFile ("SuppressWarningsUsingTargetViaXml.netcore.xml")] + [SetupCompileBefore ("library.dll", new[] { typeof (TriggerWarnings_Lib) })] + + [KeptAssembly ("library.dll")] + [SetupLinkerAction ("link", "library.dll")] + [LogDoesNotContain ("TriggerUnrecognizedPattern()")] + public class SuppressWarningsUsingTargetViaXmlNetCore + { + public static void Main () + { + TriggerWarnings_Lib.Main (); + } + } +} diff --git a/test/Mono.Linker.Tests/TestCasesRunner/BaseMetadataProvider.cs b/test/Mono.Linker.Tests/TestCasesRunner/BaseMetadataProvider.cs new file mode 100644 index 000000000..57d783c69 --- /dev/null +++ b/test/Mono.Linker.Tests/TestCasesRunner/BaseMetadataProvider.cs @@ -0,0 +1,97 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Linq; +using Mono.Cecil; +using Mono.Linker.Tests.Extensions; +using Mono.Linker.Tests.TestCases; + +namespace Mono.Linker.Tests.TestCasesRunner +{ + public abstract class BaseMetadataProvider + { + protected readonly TestCase _testCase; + protected readonly TypeDefinition _testCaseTypeDefinition; + + protected BaseMetadataProvider (TestCase testCase, AssemblyDefinition fullTestCaseAssemblyDefinition) + { + _testCase = testCase; + // The test case types are never nested so we don't need to worry about that + _testCaseTypeDefinition = fullTestCaseAssemblyDefinition.MainModule.GetType (_testCase.ReconstructedFullTypeName); + + if (_testCaseTypeDefinition == null) + throw new InvalidOperationException ($"Could not find the type definition for {_testCase.Name} in {_testCase.SourceFile}"); + } + + protected T GetOptionAttributeValue<T> (string attributeName, T defaultValue) + { + var attribute = _testCaseTypeDefinition.CustomAttributes.FirstOrDefault (attr => attr.AttributeType.Name == attributeName); + if (attribute != null) + return (T) attribute.ConstructorArguments.First ().Value; + + return defaultValue; + } + + protected NPath MakeSourceTreeFilePathAbsolute (string value) + { + return _testCase.SourceFile.Parent.Combine (value); + } + + protected SourceAndDestinationPair GetSourceAndRelativeDestinationValue (CustomAttribute attribute) + { + var fullSource = SourceFileForAttributeArgumentValue (attribute.ConstructorArguments.First ().Value); + var destinationFileName = (string) attribute.ConstructorArguments[1].Value; + return new SourceAndDestinationPair { + Source = fullSource, + DestinationFileName = string.IsNullOrEmpty (destinationFileName) ? fullSource.FileName : destinationFileName + }; + } + + + protected virtual NPath SourceFileForAttributeArgumentValue (object value) + { + if (value is TypeReference valueAsTypeRef) { + // Use the parent type for locating the source file + var parentType = ParentMostType (valueAsTypeRef); + var pathRelativeToAssembly = $"{parentType.FullName.Substring (parentType.Module.Name.Length - 3).Replace ('.', '/')}.cs".ToNPath (); + var pathElements = pathRelativeToAssembly.Elements.ToArray (); + var topMostDirectoryName = pathElements[0]; + var topMostDirectory = _testCase.SourceFile.RecursiveParents.Reverse ().FirstOrDefault (d => !d.IsRoot && d.FileName == topMostDirectoryName); + + if (topMostDirectory == null) { + // Before giving up, try and detect the naming scheme for tests that use a dot in the top level directory name. + // Ex: + // Attributes.Debugger + // + 1 because the file name is one of the elements + if (pathElements.Length >= 3) { + topMostDirectoryName = $"{pathElements[0]}.{pathElements[1]}"; + topMostDirectory = _testCase.SourceFile.RecursiveParents.Reverse ().FirstOrDefault (d => !d.IsRoot && d.FileName == topMostDirectoryName); + pathRelativeToAssembly = topMostDirectoryName.ToNPath ().Combine (pathElements.Skip (2).Aggregate (new NPath (string.Empty), (path, s) => path.Combine (s))); + } + + if (topMostDirectory == null) + throw new ArgumentException ($"Unable to locate the source file for type {valueAsTypeRef}. Could not locate directory {topMostDirectoryName}. Ensure the type name matches the file name. And the namespace match the directory structure on disk"); + } + + var fullPath = topMostDirectory.Parent.Combine (pathRelativeToAssembly); + + if (!fullPath.Exists ()) + throw new ArgumentException ($"Unable to locate the source file for type {valueAsTypeRef}. Expected {fullPath}. Ensure the type name matches the file name. And the namespace match the directory structure on disk"); + + return fullPath; + } + + return MakeSourceTreeFilePathAbsolute (value.ToString ()); + } + + static TypeReference ParentMostType (TypeReference type) + { + if (!type.IsNested) + return type; + + return ParentMostType (type.DeclaringType); + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests/TestCasesRunner/LinkedTestCaseResult.cs b/test/Mono.Linker.Tests/TestCasesRunner/LinkedTestCaseResult.cs index 1a1a1c1f0..3488712e3 100644 --- a/test/Mono.Linker.Tests/TestCasesRunner/LinkedTestCaseResult.cs +++ b/test/Mono.Linker.Tests/TestCasesRunner/LinkedTestCaseResult.cs @@ -10,19 +10,19 @@ namespace Mono.Linker.Tests.TestCasesRunner public readonly NPath OutputAssemblyPath; public readonly NPath ExpectationsAssemblyPath; public readonly TestCaseSandbox Sandbox; - public readonly TestCaseMetadaProvider MetadataProvider; + public readonly TestCaseMetadataProvider MetadataProvider; public readonly ManagedCompilationResult CompilationResult; public readonly LinkerTestLogger Logger; public readonly LinkerCustomizations Customizations; - public LinkedTestCaseResult (TestCase testCase, NPath inputAssemblyPath, NPath outputAssemblyPath, NPath expectationsAssemblyPath, TestCaseSandbox sandbox, TestCaseMetadaProvider metadaProvider, ManagedCompilationResult compilationResult, LinkerTestLogger logger, LinkerCustomizations customizations) + public LinkedTestCaseResult (TestCase testCase, NPath inputAssemblyPath, NPath outputAssemblyPath, NPath expectationsAssemblyPath, TestCaseSandbox sandbox, TestCaseMetadataProvider metadataProvider, ManagedCompilationResult compilationResult, LinkerTestLogger logger, LinkerCustomizations customizations) { TestCase = testCase; InputAssemblyPath = inputAssemblyPath; OutputAssemblyPath = outputAssemblyPath; ExpectationsAssemblyPath = expectationsAssemblyPath; Sandbox = sandbox; - MetadataProvider = metadaProvider; + MetadataProvider = metadataProvider; CompilationResult = compilationResult; Logger = logger; Customizations = customizations; diff --git a/test/Mono.Linker.Tests/TestCasesRunner/LinkerArgumentBuilder.cs b/test/Mono.Linker.Tests/TestCasesRunner/LinkerArgumentBuilder.cs index b95fb0a14..ce28b3161 100644 --- a/test/Mono.Linker.Tests/TestCasesRunner/LinkerArgumentBuilder.cs +++ b/test/Mono.Linker.Tests/TestCasesRunner/LinkerArgumentBuilder.cs @@ -6,11 +6,11 @@ namespace Mono.Linker.Tests.TestCasesRunner public class LinkerArgumentBuilder { private readonly List<string> _arguments = new List<string> (); - private readonly TestCaseMetadaProvider _metadaProvider; + private readonly TestCaseMetadataProvider _metadataProvider; - public LinkerArgumentBuilder (TestCaseMetadaProvider metadaProvider) + public LinkerArgumentBuilder (TestCaseMetadataProvider metadataProvider) { - _metadaProvider = metadaProvider; + _metadataProvider = metadataProvider; } public virtual void AddSearchDirectory (NPath directory) @@ -186,7 +186,7 @@ namespace Mono.Linker.Tests.TestCasesRunner public virtual void ProcessTestInputAssembly (NPath inputAssemblyPath) { - if (_metadaProvider.LinkPublicAndFamily ()) + if (_metadataProvider.LinkPublicAndFamily ()) LinkFromPublicAndFamily (inputAssemblyPath.ToString ()); else LinkFromAssembly (inputAssemblyPath.ToString ()); diff --git a/test/Mono.Linker.Tests/TestCasesRunner/ObjectFactory.cs b/test/Mono.Linker.Tests/TestCasesRunner/ObjectFactory.cs index de964e183..e34407a07 100644 --- a/test/Mono.Linker.Tests/TestCasesRunner/ObjectFactory.cs +++ b/test/Mono.Linker.Tests/TestCasesRunner/ObjectFactory.cs @@ -10,7 +10,7 @@ namespace Mono.Linker.Tests.TestCasesRunner return new TestCaseSandbox (testCase); } - public virtual TestCaseCompiler CreateCompiler (TestCaseSandbox sandbox, TestCaseMetadaProvider metadataProvider) + public virtual TestCaseCompiler CreateCompiler (TestCaseSandbox sandbox, TestCaseCompilationMetadataProvider metadataProvider) { return new TestCaseCompiler (sandbox, metadataProvider); } @@ -20,12 +20,17 @@ namespace Mono.Linker.Tests.TestCasesRunner return new LinkerDriver (); } - public virtual TestCaseMetadaProvider CreateMetadataProvider (TestCase testCase, AssemblyDefinition fullTestCaseAssemblyDefinition) + public virtual TestCaseMetadataProvider CreateMetadataProvider (TestCase testCase, AssemblyDefinition expectationsAssemblyDefinition) { - return new TestCaseMetadaProvider (testCase, fullTestCaseAssemblyDefinition); + return new TestCaseMetadataProvider (testCase, expectationsAssemblyDefinition); } - public virtual LinkerArgumentBuilder CreateLinkerArgumentBuilder (TestCaseMetadaProvider metadataProvider) + public virtual TestCaseCompilationMetadataProvider CreateCompilationMetadataProvider (TestCase testCase, AssemblyDefinition fullTestCaseAssemblyDefinition) + { + return new TestCaseCompilationMetadataProvider (testCase, fullTestCaseAssemblyDefinition); + } + + public virtual LinkerArgumentBuilder CreateLinkerArgumentBuilder (TestCaseMetadataProvider metadataProvider) { return new LinkerArgumentBuilder (metadataProvider); } diff --git a/test/Mono.Linker.Tests/TestCasesRunner/TestCaseCompilationMetadataProvider.cs b/test/Mono.Linker.Tests/TestCasesRunner/TestCaseCompilationMetadataProvider.cs new file mode 100644 index 000000000..5731a2949 --- /dev/null +++ b/test/Mono.Linker.Tests/TestCasesRunner/TestCaseCompilationMetadataProvider.cs @@ -0,0 +1,236 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using Mono.Cecil; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; +using Mono.Linker.Tests.Extensions; +using Mono.Linker.Tests.TestCases; + +namespace Mono.Linker.Tests.TestCasesRunner +{ + public class TestCaseCompilationMetadataProvider : BaseMetadataProvider + { + + public TestCaseCompilationMetadataProvider (TestCase testCase, AssemblyDefinition fullTestCaseAssemblyDefinition) + : base (testCase, fullTestCaseAssemblyDefinition) + { + + } + + public virtual TestRunCharacteristics Characteristics => + TestRunCharacteristics.TargetingNetCore | TestRunCharacteristics.SupportsDefaultInterfaceMethods | TestRunCharacteristics.SupportsStaticInterfaceMethods; + + public virtual bool IsIgnored (out string reason) + { + var ignoreAttribute = _testCaseTypeDefinition.CustomAttributes.FirstOrDefault (attr => attr.AttributeType.Name == nameof (IgnoreTestCaseAttribute)); + if (ignoreAttribute != null) { + if (ignoreAttribute.ConstructorArguments.Count == 1) { + reason = (string) ignoreAttribute.ConstructorArguments.First ().Value; + return true; + } else { + throw new ArgumentException ($"Unhandled {nameof (IgnoreTestCaseAttribute)} constructor with {ignoreAttribute.ConstructorArguments} arguments"); + } + } + + var requirementsAttribute = _testCaseTypeDefinition.CustomAttributes.FirstOrDefault (attr => attr.AttributeType.Name == nameof (TestCaseRequirementsAttribute)); + if (requirementsAttribute != null) { + if (requirementsAttribute.ConstructorArguments.Count == 2) { + var testCaseRequirements = (TestRunCharacteristics) requirementsAttribute.ConstructorArguments[0].Value; + + foreach (var value in Enum.GetValues (typeof (TestRunCharacteristics))) { + if (IsRequirementMissing ((TestRunCharacteristics) value, testCaseRequirements)) { + reason = (string) requirementsAttribute.ConstructorArguments[1].Value; + return true; + } + } + } else { + throw new ArgumentException ($"Unhandled {nameof (TestCaseRequirementsAttribute)} constructor with {requirementsAttribute.ConstructorArguments} arguments"); + } + } + + reason = null; + return false; + } + + bool IsRequirementMissing (TestRunCharacteristics requirement, TestRunCharacteristics testCaseRequirements) + { + return testCaseRequirements.HasFlag (requirement) && !Characteristics.HasFlag (requirement); + } + + public virtual IEnumerable<string> GetDefines () + { + // There are a few tests related to native pdbs where the assertions are different between windows and non-windows + // To enable test cases to define different expected behavior we set this special define + if (Environment.OSVersion.Platform == PlatformID.Win32NT) + yield return "WIN32"; + + if (Characteristics.HasFlag (TestRunCharacteristics.TargetingNetCore)) + yield return "NETCOREAPP"; + + if (Characteristics.HasFlag (TestRunCharacteristics.SupportsDefaultInterfaceMethods)) + yield return "SUPPORTS_DEFAULT_INTERFACE_METHODS"; + + foreach (var attr in _testCaseTypeDefinition.CustomAttributes.Where (attr => attr.AttributeType.Name == nameof (DefineAttribute))) + yield return (string) attr.ConstructorArguments.First ().Value; + } + + public virtual string GetAssemblyName () + { + var asLibraryAttribute = _testCaseTypeDefinition.CustomAttributes + .FirstOrDefault (attr => attr.AttributeType.Name == nameof (SetupCompileAsLibraryAttribute)); + var defaultName = asLibraryAttribute == null ? "test.exe" : "test.dll"; + return GetOptionAttributeValue (nameof (SetupCompileAssemblyNameAttribute), defaultName); + } + + public virtual string GetCSharpCompilerToUse () + { + return GetOptionAttributeValue (nameof (SetupCSharpCompilerToUseAttribute), string.Empty).ToLower (); + } + + public virtual IEnumerable<string> GetSetupCompilerArguments () + { + return _testCaseTypeDefinition.CustomAttributes + .Where (attr => attr.AttributeType.Name == nameof (SetupCompileArgumentAttribute)) + .Select (attr => (string) attr.ConstructorArguments.First ().Value); + } + + public virtual IEnumerable<SourceAndDestinationPair> AdditionalFilesToSandbox () + { + return _testCaseTypeDefinition.CustomAttributes + .Where (attr => attr.AttributeType.Name == nameof (SandboxDependencyAttribute)) + .Select (GetSourceAndRelativeDestinationValue); + } + + + public virtual IEnumerable<string> GetCommonReferencedAssemblies (NPath workingDirectory) + { + yield return workingDirectory.Combine ("Mono.Linker.Tests.Cases.Expectations.dll").ToString (); + if (Characteristics.HasFlag (TestRunCharacteristics.TargetingNetCore)) { + string frameworkDir = Path.GetDirectoryName (typeof (object).Assembly.Location); + + yield return typeof (object).Assembly.Location; + yield return Path.Combine (frameworkDir, "System.Runtime.dll"); + yield return Path.Combine (frameworkDir, "System.Linq.Expressions.dll"); + yield return Path.Combine (frameworkDir, "System.ComponentModel.TypeConverter.dll"); + yield return Path.Combine (frameworkDir, "System.Console.dll"); + yield return Path.Combine (frameworkDir, "mscorlib.dll"); + yield return Path.Combine (frameworkDir, "System.ObjectModel.dll"); + yield return Path.Combine (frameworkDir, "System.Runtime.Extensions.dll"); + } else { + yield return "mscorlib.dll"; + + } + } + + public virtual IEnumerable<string> GetReferencedAssemblies (NPath workingDirectory) + { + foreach (var fileName in GetReferenceValues ()) { + + if (fileName.StartsWith ("System.", StringComparison.Ordinal) || fileName.StartsWith ("Mono.", StringComparison.Ordinal) || fileName.StartsWith ("Microsoft.", StringComparison.Ordinal)) { + if (Characteristics.HasFlag (TestRunCharacteristics.TargetingNetCore)) { + // Try to find the assembly alongside the host's framework dependencies + var frameworkDir = Path.GetFullPath (Path.GetDirectoryName (typeof (object).Assembly.Location)); + var filePath = Path.Combine (frameworkDir, fileName); + + if (File.Exists (filePath)) { + yield return filePath; + } else { + yield return fileName; + } + } else { + yield return fileName; + } + } else { + // Drop any relative path information. Sandboxing will have taken care of copying the reference to the directory + yield return workingDirectory.Combine (Path.GetFileName (fileName)); + } + } + } + + public virtual IEnumerable<string> GetReferenceDependencies () + { + return _testCaseTypeDefinition.CustomAttributes + .Where (attr => attr.AttributeType.Name == nameof (ReferenceDependencyAttribute)) + .Select (attr => (string) attr.ConstructorArguments[0].Value); + } + + public virtual IEnumerable<string> GetReferenceValues () + { + foreach (var referenceAttr in _testCaseTypeDefinition.CustomAttributes.Where (attr => attr.AttributeType.Name == nameof (ReferenceAttribute))) + yield return (string) referenceAttr.ConstructorArguments.First ().Value; + } + + public virtual IEnumerable<SourceAndDestinationPair> GetResources () + { + return _testCaseTypeDefinition.CustomAttributes + .Where (attr => attr.AttributeType.Name == nameof (SetupCompileResourceAttribute)) + .Select (GetSourceAndRelativeDestinationValue); + } + + public virtual IEnumerable<SetupCompileInfo> GetSetupCompileAssembliesBefore () + { + return _testCaseTypeDefinition.CustomAttributes + .Where (attr => attr.AttributeType.Name == nameof (SetupCompileBeforeAttribute)) + .Select (CreateSetupCompileAssemblyInfo); + } + + public virtual IEnumerable<SetupCompileInfo> GetSetupCompileAssembliesAfter () + { + return _testCaseTypeDefinition.CustomAttributes + .Where (attr => attr.AttributeType.Name == nameof (SetupCompileAfterAttribute)) + .Select (CreateSetupCompileAssemblyInfo); + } + + private SetupCompileInfo CreateSetupCompileAssemblyInfo (CustomAttribute attribute) + { + var ctorArguments = attribute.ConstructorArguments; + return new SetupCompileInfo { + OutputName = (string) ctorArguments[0].Value, + SourceFiles = SourceFilesForAttributeArgument (ctorArguments[1]), + References = ((CustomAttributeArgument[]) ctorArguments[2].Value)?.Select (arg => arg.Value.ToString ()).ToArray (), + Defines = ((CustomAttributeArgument[]) ctorArguments[3].Value)?.Select (arg => arg.Value.ToString ()).ToArray (), + Resources = ResourcesForAttributeArgument (ctorArguments[4]), + AdditionalArguments = (string) ctorArguments[5].Value, + CompilerToUse = (string) ctorArguments[6].Value, + AddAsReference = ctorArguments.Count >= 8 ? (bool) ctorArguments[7].Value : true, + RemoveFromLinkerInput = ctorArguments.Count >= 9 ? (bool) ctorArguments[8].Value : false, + OutputSubFolder = ctorArguments.Count >= 10 ? (string) ctorArguments[9].Value : null + }; + } + + protected NPath[] SourceFilesForAttributeArgument (CustomAttributeArgument attributeArgument) + { + return ((CustomAttributeArgument[]) attributeArgument.Value) + .Select (attributeArg => SourceFileForAttributeArgumentValue (attributeArg.Value)) + .Distinct () + .ToArray (); + } + + protected SourceAndDestinationPair[] ResourcesForAttributeArgument (CustomAttributeArgument attributeArgument) + { + return ((CustomAttributeArgument[]) attributeArgument.Value) + ?.Select (arg => { + var referenceArg = (CustomAttributeArgument) arg.Value; + if (referenceArg.Value is string source) { + var fullSource = MakeSourceTreeFilePathAbsolute (source); + return new SourceAndDestinationPair { + Source = fullSource, + DestinationFileName = fullSource.FileName + }; + } + var sourceAndDestination = (CustomAttributeArgument[]) referenceArg.Value; + return new SourceAndDestinationPair { + Source = MakeSourceTreeFilePathAbsolute (sourceAndDestination[0].Value.ToString ()), + DestinationFileName = sourceAndDestination[1].Value.ToString () + }; + }) + ?.ToArray (); + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests/TestCasesRunner/TestCaseCompiler.cs b/test/Mono.Linker.Tests/TestCasesRunner/TestCaseCompiler.cs index 52e6a3f24..5d6c8c35a 100644 --- a/test/Mono.Linker.Tests/TestCasesRunner/TestCaseCompiler.cs +++ b/test/Mono.Linker.Tests/TestCasesRunner/TestCaseCompiler.cs @@ -17,16 +17,16 @@ namespace Mono.Linker.Tests.TestCasesRunner { public class TestCaseCompiler { - protected readonly TestCaseMetadaProvider _metadataProvider; + protected readonly TestCaseCompilationMetadataProvider _metadataProvider; protected readonly TestCaseSandbox _sandbox; protected readonly ILCompiler _ilCompiler; - public TestCaseCompiler (TestCaseSandbox sandbox, TestCaseMetadaProvider metadataProvider) + public TestCaseCompiler (TestCaseSandbox sandbox, TestCaseCompilationMetadataProvider metadataProvider) : this (sandbox, metadataProvider, new ILCompiler ()) { } - public TestCaseCompiler (TestCaseSandbox sandbox, TestCaseMetadaProvider metadataProvider, ILCompiler ilCompiler) + public TestCaseCompiler (TestCaseSandbox sandbox, TestCaseCompilationMetadataProvider metadataProvider, ILCompiler ilCompiler) { _ilCompiler = ilCompiler; _sandbox = sandbox; diff --git a/test/Mono.Linker.Tests/TestCasesRunner/TestCaseMetadaProvider.cs b/test/Mono.Linker.Tests/TestCasesRunner/TestCaseMetadaProvider.cs deleted file mode 100644 index 12735c6e3..000000000 --- a/test/Mono.Linker.Tests/TestCasesRunner/TestCaseMetadaProvider.cs +++ /dev/null @@ -1,459 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using Mono.Cecil; -using Mono.Linker.Tests.Cases.Expectations.Assertions; -using Mono.Linker.Tests.Cases.Expectations.Metadata; -using Mono.Linker.Tests.Extensions; -using Mono.Linker.Tests.TestCases; - -namespace Mono.Linker.Tests.TestCasesRunner -{ - public class TestCaseMetadaProvider - { - protected readonly TestCase _testCase; - protected readonly AssemblyDefinition _fullTestCaseAssemblyDefinition; - protected readonly TypeDefinition _testCaseTypeDefinition; - - public TestCaseMetadaProvider (TestCase testCase, AssemblyDefinition fullTestCaseAssemblyDefinition) - { - _testCase = testCase; - _fullTestCaseAssemblyDefinition = fullTestCaseAssemblyDefinition; - // The test case types are never nested so we don't need to worry about that - _testCaseTypeDefinition = fullTestCaseAssemblyDefinition.MainModule.GetType (_testCase.ReconstructedFullTypeName); - - if (_testCaseTypeDefinition == null) - throw new InvalidOperationException ($"Could not find the type definition for {_testCase.Name} in {_testCase.SourceFile}"); - } - - public virtual TestCaseLinkerOptions GetLinkerOptions (NPath inputPath) - { - var tclo = new TestCaseLinkerOptions { - Il8n = GetOptionAttributeValue (nameof (Il8nAttribute), "none"), - IgnoreDescriptors = GetOptionAttributeValue (nameof (IgnoreDescriptorsAttribute), true), - IgnoreSubstitutions = GetOptionAttributeValue (nameof (IgnoreSubstitutionsAttribute), true), - IgnoreLinkAttributes = GetOptionAttributeValue (nameof (IgnoreLinkAttributesAttribute), true), - KeepTypeForwarderOnlyAssemblies = GetOptionAttributeValue (nameof (KeepTypeForwarderOnlyAssembliesAttribute), string.Empty), - KeepDebugMembers = GetOptionAttributeValue (nameof (SetupLinkerKeepDebugMembersAttribute), string.Empty), - LinkSymbols = GetOptionAttributeValue (nameof (SetupLinkerLinkSymbolsAttribute), string.Empty), - TrimMode = GetOptionAttributeValue<string> (nameof (SetupLinkerTrimModeAttribute), null), - DefaultAssembliesAction = GetOptionAttributeValue<string> (nameof (SetupLinkerDefaultActionAttribute), null), - SkipUnresolved = GetOptionAttributeValue (nameof (SkipUnresolvedAttribute), false), - StripDescriptors = GetOptionAttributeValue (nameof (StripDescriptorsAttribute), true), - StripSubstitutions = GetOptionAttributeValue (nameof (StripSubstitutionsAttribute), true), - StripLinkAttributes = GetOptionAttributeValue (nameof (StripLinkAttributesAttribute), true), - }; - - foreach (var assemblyAction in _testCaseTypeDefinition.CustomAttributes.Where (attr => attr.AttributeType.Name == nameof (SetupLinkerActionAttribute))) { - var ca = assemblyAction.ConstructorArguments; - tclo.AssembliesAction.Add (new KeyValuePair<string, string> ((string) ca[0].Value, (string) ca[1].Value)); - } - - foreach (var descFile in _testCaseTypeDefinition.CustomAttributes.Where (attr => attr.AttributeType.Name == nameof (SetupLinkerDescriptorFile))) { - var ca = descFile.ConstructorArguments; - var file = (string) ca[0].Value; - tclo.Descriptors.Add (Path.Combine (inputPath, file)); - } - - foreach (var subsFile in _testCaseTypeDefinition.CustomAttributes.Where (attr => attr.AttributeType.Name == nameof (SetupLinkerSubstitutionFileAttribute))) { - var ca = subsFile.ConstructorArguments; - var file = (string) ca[0].Value; - tclo.Substitutions.Add (Path.Combine (inputPath, file)); - } - - foreach (var linkAttrFile in _testCaseTypeDefinition.CustomAttributes.Where (attr => attr.AttributeType.Name == nameof (SetupLinkAttributesFile))) { - var ca = linkAttrFile.ConstructorArguments; - var file = (string) ca[0].Value; - tclo.LinkAttributes.Add (Path.Combine (inputPath, file)); - } - - foreach (var additionalArgumentAttr in _testCaseTypeDefinition.CustomAttributes.Where (attr => attr.AttributeType.Name == nameof (SetupLinkerArgumentAttribute))) { - var ca = additionalArgumentAttr.ConstructorArguments; - var values = ((CustomAttributeArgument[]) ca[1].Value)?.Select (arg => arg.Value.ToString ()).ToArray (); - // Since custom attribute arguments need to be constant expressions, we need to add - // the path to the temp directory (where the custom assembly is located) here. - switch ((string) ca[0].Value) { - case "--custom-step": - int pos = values[0].IndexOf (","); - if (pos != -1) { - string custom_assembly_path = values[0].Substring (pos + 1); - if (!Path.IsPathRooted (custom_assembly_path)) - values[0] = values[0].Substring (0, pos + 1) + Path.Combine (inputPath, custom_assembly_path); - } - break; - case "-a": - if (!Path.IsPathRooted (values[0])) - values[0] = Path.Combine (inputPath, values[0]); - - break; - } - - tclo.AdditionalArguments.Add (new KeyValuePair<string, string[]> ((string) ca[0].Value, values)); - } - - return tclo; - } - - public virtual void CustomizeLinker (LinkerDriver linker, LinkerCustomizations customizations) - { - if (_testCaseTypeDefinition.CustomAttributes.Any (attr => - attr.AttributeType.Name == nameof (DependencyRecordedAttribute))) { - customizations.DependencyRecorder = new TestDependencyRecorder (); - customizations.CustomizeContext += context => { - context.Tracer.AddRecorder (customizations.DependencyRecorder); - }; - } - - if (ValidatesReflectionAccessPatterns (_testCaseTypeDefinition)) { - customizations.ReflectionPatternRecorder = new TestReflectionPatternRecorder (); - customizations.CustomizeContext += context => { - customizations.ReflectionPatternRecorder.PreviousRecorder = context.ReflectionPatternRecorder; - context.ReflectionPatternRecorder = customizations.ReflectionPatternRecorder; - context.LogMessages = true; - }; - } - - if (ValidatesLogMessages (_testCaseTypeDefinition)) { - customizations.CustomizeContext += context => { - context.LogMessages = true; - }; - } - } - - bool ValidatesReflectionAccessPatterns (TypeDefinition testCaseTypeDefinition) - { - if (testCaseTypeDefinition.HasNestedTypes) { - var nestedTypes = new Queue<TypeDefinition> (testCaseTypeDefinition.NestedTypes.ToList ()); - while (nestedTypes.Count > 0) { - if (ValidatesReflectionAccessPatterns (nestedTypes.Dequeue ())) - return true; - } - } - - if (testCaseTypeDefinition.CustomAttributes.Any (attr => - attr.AttributeType.Name == nameof (VerifyAllReflectionAccessPatternsAreValidatedAttribute)) - || testCaseTypeDefinition.AllMembers ().Concat (testCaseTypeDefinition.AllDefinedTypes ()).Any (m => m.CustomAttributes.Any (attr => - attr.AttributeType.Name == nameof (RecognizedReflectionAccessPatternAttribute) || - attr.AttributeType.Name == nameof (UnrecognizedReflectionAccessPatternAttribute)))) - return true; - - return false; - } - - bool ValidatesLogMessages (TypeDefinition testCaseTypeDefinition) - { - if (testCaseTypeDefinition.HasNestedTypes) { - var nestedTypes = new Queue<TypeDefinition> (testCaseTypeDefinition.NestedTypes.ToList ()); - while (nestedTypes.Count > 0) { - if (ValidatesLogMessages (nestedTypes.Dequeue ())) - return true; - } - } - - if (testCaseTypeDefinition.AllMembers ().Concat (testCaseTypeDefinition.AllDefinedTypes ()).Append (testCaseTypeDefinition) - .Any (m => m.CustomAttributes.Any (attr => - attr.AttributeType.Name == nameof (LogContainsAttribute) || - attr.AttributeType.Name == nameof (LogDoesNotContainAttribute)))) - return true; - - return false; - } - - public virtual IEnumerable<string> GetCommonReferencedAssemblies (NPath workingDirectory) - { - yield return workingDirectory.Combine ("Mono.Linker.Tests.Cases.Expectations.dll").ToString (); -#if NETCOREAPP - string frameworkDir = Path.GetDirectoryName (typeof (object).Assembly.Location); - - yield return typeof (object).Assembly.Location; - yield return Path.Combine (frameworkDir, "System.Runtime.dll"); - yield return Path.Combine (frameworkDir, "System.Linq.Expressions.dll"); - yield return Path.Combine (frameworkDir, "System.ComponentModel.TypeConverter.dll"); - yield return Path.Combine (frameworkDir, "System.Console.dll"); - yield return Path.Combine (frameworkDir, "mscorlib.dll"); - yield return Path.Combine (frameworkDir, "System.ObjectModel.dll"); - yield return Path.Combine (frameworkDir, "System.Runtime.Extensions.dll"); -#else - yield return "mscorlib.dll"; -#endif - } - - public virtual IEnumerable<string> GetReferencedAssemblies (NPath workingDirectory) - { - foreach (var fileName in GetReferenceValues ()) { - - if (fileName.StartsWith ("System.", StringComparison.Ordinal) || fileName.StartsWith ("Mono.", StringComparison.Ordinal) || fileName.StartsWith ("Microsoft.", StringComparison.Ordinal)) { -#if NETCOREAPP - // Try to find the assembly alongside the host's framework dependencies - var frameworkDir = Path.GetFullPath (Path.GetDirectoryName (typeof (object).Assembly.Location)); - var filePath = Path.Combine (frameworkDir, fileName); - - if (File.Exists (filePath)) { - yield return filePath; - } else { - yield return fileName; - } -#else - yield return fileName; -#endif - } else { - // Drop any relative path information. Sandboxing will have taken care of copying the reference to the directory - yield return workingDirectory.Combine (Path.GetFileName (fileName)); - } - } - } - - public virtual IEnumerable<string> GetReferenceDependencies () - { - return _testCaseTypeDefinition.CustomAttributes - .Where (attr => attr.AttributeType.Name == nameof (ReferenceDependencyAttribute)) - .Select (attr => (string) attr.ConstructorArguments[0].Value); - } - - public virtual IEnumerable<string> GetReferenceValues () - { - foreach (var referenceAttr in _testCaseTypeDefinition.CustomAttributes.Where (attr => attr.AttributeType.Name == nameof (ReferenceAttribute))) - yield return (string) referenceAttr.ConstructorArguments.First ().Value; - } - - public virtual IEnumerable<SourceAndDestinationPair> GetResources () - { - return _testCaseTypeDefinition.CustomAttributes - .Where (attr => attr.AttributeType.Name == nameof (SetupCompileResourceAttribute)) - .Select (GetSourceAndRelativeDestinationValue); - } - - public virtual IEnumerable<SourceAndDestinationPair> GetResponseFiles () - { - return _testCaseTypeDefinition.CustomAttributes - .Where (attr => attr.AttributeType.Name == nameof (SetupLinkerResponseFileAttribute)) - .Select (GetSourceAndRelativeDestinationValue); - } - - public virtual IEnumerable<SourceAndDestinationPair> GetDescriptorFiles () - { - return _testCaseTypeDefinition.CustomAttributes - .Where (attr => attr.AttributeType.Name == nameof (SetupLinkerDescriptorFile)) - .Select (GetSourceAndRelativeDestinationValue); - } - - public virtual IEnumerable<SourceAndDestinationPair> GetSubstitutionFiles () - { - return _testCaseTypeDefinition.CustomAttributes - .Where (attr => attr.AttributeType.Name == nameof (SetupLinkerSubstitutionFileAttribute)) - .Select (GetSourceAndRelativeDestinationValue); - } - - public virtual IEnumerable<SourceAndDestinationPair> GetLinkAttributesFiles () - { - return _testCaseTypeDefinition.CustomAttributes - .Where (attr => attr.AttributeType.Name == nameof (SetupLinkAttributesFile)) - .Select (GetSourceAndRelativeDestinationValue); - } - - public virtual IEnumerable<NPath> GetExtraLinkerReferences () - { - var netcoreappDir = Path.GetDirectoryName (typeof (object).Assembly.Location); - foreach (var assembly in Directory.EnumerateFiles (netcoreappDir)) { - if (Path.GetExtension (assembly) != ".dll") - continue; - var assemblyName = Path.GetFileNameWithoutExtension (assembly); - if (assemblyName.Contains ("Native")) - continue; - if (assemblyName.StartsWith ("Microsoft") || - assemblyName.StartsWith ("System") || - assemblyName == "mscorlib" || assemblyName == "netstandard") - yield return assembly.ToNPath (); - } - } - - public virtual bool IsIgnored (out string reason) - { - var ignoreAttribute = _testCaseTypeDefinition.CustomAttributes.FirstOrDefault (attr => attr.AttributeType.Name == nameof (IgnoreTestCaseAttribute)); - if (ignoreAttribute != null) { - reason = (string) ignoreAttribute.ConstructorArguments.First ().Value; - return true; - } - - reason = null; - return false; - } - - public virtual IEnumerable<SourceAndDestinationPair> AdditionalFilesToSandbox () - { - return _testCaseTypeDefinition.CustomAttributes - .Where (attr => attr.AttributeType.Name == nameof (SandboxDependencyAttribute)) - .Select (GetSourceAndRelativeDestinationValue); - } - - public virtual IEnumerable<SetupCompileInfo> GetSetupCompileAssembliesBefore () - { - return _testCaseTypeDefinition.CustomAttributes - .Where (attr => attr.AttributeType.Name == nameof (SetupCompileBeforeAttribute)) - .Select (CreateSetupCompileAssemblyInfo); - } - - public virtual IEnumerable<SetupCompileInfo> GetSetupCompileAssembliesAfter () - { - return _testCaseTypeDefinition.CustomAttributes - .Where (attr => attr.AttributeType.Name == nameof (SetupCompileAfterAttribute)) - .Select (CreateSetupCompileAssemblyInfo); - } - - public virtual IEnumerable<string> GetDefines () - { - // There are a few tests related to native pdbs where the assertions are different between windows and non-windows - // To enable test cases to define different expected behavior we set this special define - if (Environment.OSVersion.Platform == PlatformID.Win32NT) - yield return "WIN32"; - -#if NETCOREAPP - yield return "NETCOREAPP"; -#endif - - foreach (var attr in _testCaseTypeDefinition.CustomAttributes.Where (attr => attr.AttributeType.Name == nameof (DefineAttribute))) - yield return (string) attr.ConstructorArguments.First ().Value; - } - - public virtual bool LinkPublicAndFamily () - { - return _testCaseTypeDefinition.CustomAttributes - .FirstOrDefault (attr => attr.AttributeType.Name == nameof (SetupLinkerLinkPublicAndFamilyAttribute)) != null; - } - - public virtual string GetAssemblyName () - { - var asLibraryAttribute = _testCaseTypeDefinition.CustomAttributes - .FirstOrDefault (attr => attr.AttributeType.Name == nameof (SetupCompileAsLibraryAttribute)); - var defaultName = asLibraryAttribute == null ? "test.exe" : "test.dll"; - return GetOptionAttributeValue (nameof (SetupCompileAssemblyNameAttribute), defaultName); - } - - public virtual string GetCSharpCompilerToUse () - { - return GetOptionAttributeValue (nameof (SetupCSharpCompilerToUseAttribute), string.Empty).ToLower (); - } - - public virtual IEnumerable<string> GetSetupCompilerArguments () - { - return _testCaseTypeDefinition.CustomAttributes - .Where (attr => attr.AttributeType.Name == nameof (SetupCompileArgumentAttribute)) - .Select (attr => (string) attr.ConstructorArguments.First ().Value); - } - - T GetOptionAttributeValue<T> (string attributeName, T defaultValue) - { - var attribute = _testCaseTypeDefinition.CustomAttributes.FirstOrDefault (attr => attr.AttributeType.Name == attributeName); - if (attribute != null) - return (T) attribute.ConstructorArguments.First ().Value; - - return defaultValue; - } - - SourceAndDestinationPair GetSourceAndRelativeDestinationValue (CustomAttribute attribute) - { - var fullSource = SourceFileForAttributeArgumentValue (attribute.ConstructorArguments.First ().Value); - var destinationFileName = (string) attribute.ConstructorArguments[1].Value; - return new SourceAndDestinationPair { - Source = fullSource, - DestinationFileName = string.IsNullOrEmpty (destinationFileName) ? fullSource.FileName : destinationFileName - }; - } - - private SetupCompileInfo CreateSetupCompileAssemblyInfo (CustomAttribute attribute) - { - var ctorArguments = attribute.ConstructorArguments; - return new SetupCompileInfo { - OutputName = (string) ctorArguments[0].Value, - SourceFiles = SourceFilesForAttributeArgument (ctorArguments[1]), - References = ((CustomAttributeArgument[]) ctorArguments[2].Value)?.Select (arg => arg.Value.ToString ()).ToArray (), - Defines = ((CustomAttributeArgument[]) ctorArguments[3].Value)?.Select (arg => arg.Value.ToString ()).ToArray (), - Resources = ResourcesForAttributeArgument (ctorArguments[4]), - AdditionalArguments = (string) ctorArguments[5].Value, - CompilerToUse = (string) ctorArguments[6].Value, - AddAsReference = ctorArguments.Count >= 8 ? (bool) ctorArguments[7].Value : true, - RemoveFromLinkerInput = ctorArguments.Count >= 9 ? (bool) ctorArguments[8].Value : false, - OutputSubFolder = ctorArguments.Count >= 10 ? (string) ctorArguments[9].Value : null - }; - } - - protected NPath MakeSourceTreeFilePathAbsolute (string value) - { - return _testCase.SourceFile.Parent.Combine (value); - } - - protected NPath[] SourceFilesForAttributeArgument (CustomAttributeArgument attributeArgument) - { - return ((CustomAttributeArgument[]) attributeArgument.Value) - .Select (attributeArg => SourceFileForAttributeArgumentValue (attributeArg.Value)) - .Distinct () - .ToArray (); - } - - protected SourceAndDestinationPair[] ResourcesForAttributeArgument (CustomAttributeArgument attributeArgument) - { - return ((CustomAttributeArgument[]) attributeArgument.Value) - ?.Select (arg => { - var referenceArg = (CustomAttributeArgument) arg.Value; - if (referenceArg.Value is string source) { - var fullSource = MakeSourceTreeFilePathAbsolute (source); - return new SourceAndDestinationPair { - Source = fullSource, - DestinationFileName = fullSource.FileName - }; - } - var sourceAndDestination = (CustomAttributeArgument[]) referenceArg.Value; - return new SourceAndDestinationPair { - Source = MakeSourceTreeFilePathAbsolute (sourceAndDestination[0].Value.ToString ()), - DestinationFileName = sourceAndDestination[1].Value.ToString () - }; - }) - ?.ToArray (); - } - - protected virtual NPath SourceFileForAttributeArgumentValue (object value) - { - if (value is TypeReference valueAsTypeRef) { - // Use the parent type for locating the source file - var parentType = ParentMostType (valueAsTypeRef); - var pathRelativeToAssembly = $"{parentType.FullName.Substring (parentType.Module.Name.Length - 3).Replace ('.', '/')}.cs".ToNPath (); - var pathElements = pathRelativeToAssembly.Elements.ToArray (); - var topMostDirectoryName = pathElements[0]; - var topMostDirectory = _testCase.SourceFile.RecursiveParents.Reverse ().FirstOrDefault (d => !d.IsRoot && d.FileName == topMostDirectoryName); - - if (topMostDirectory == null) { - // Before giving up, try and detect the naming scheme for tests that use a dot in the top level directory name. - // Ex: - // Attributes.Debugger - // + 1 because the file name is one of the elements - if (pathElements.Length >= 3) { - topMostDirectoryName = $"{pathElements[0]}.{pathElements[1]}"; - topMostDirectory = _testCase.SourceFile.RecursiveParents.Reverse ().FirstOrDefault (d => !d.IsRoot && d.FileName == topMostDirectoryName); - pathRelativeToAssembly = topMostDirectoryName.ToNPath ().Combine (pathElements.Skip (2).Aggregate (new NPath (string.Empty), (path, s) => path.Combine (s))); - } - - if (topMostDirectory == null) - throw new ArgumentException ($"Unable to locate the source file for type {valueAsTypeRef}. Could not locate directory {topMostDirectoryName}. Ensure the type name matches the file name. And the namespace match the directory structure on disk"); - } - - var fullPath = topMostDirectory.Parent.Combine (pathRelativeToAssembly); - - if (!fullPath.Exists ()) - throw new ArgumentException ($"Unable to locate the source file for type {valueAsTypeRef}. Expected {fullPath}. Ensure the type name matches the file name. And the namespace match the directory structure on disk"); - - return fullPath; - } - - return MakeSourceTreeFilePathAbsolute (value.ToString ()); - } - - static TypeReference ParentMostType (TypeReference type) - { - if (!type.IsNested) - return type; - - return ParentMostType (type.DeclaringType); - } - } -}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests/TestCasesRunner/TestCaseMetadataProvider.cs b/test/Mono.Linker.Tests/TestCasesRunner/TestCaseMetadataProvider.cs new file mode 100644 index 000000000..404ecbf0f --- /dev/null +++ b/test/Mono.Linker.Tests/TestCasesRunner/TestCaseMetadataProvider.cs @@ -0,0 +1,203 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using Mono.Cecil; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; +using Mono.Linker.Tests.Extensions; +using Mono.Linker.Tests.TestCases; + +namespace Mono.Linker.Tests.TestCasesRunner +{ + public class TestCaseMetadataProvider : BaseMetadataProvider + { + public TestCaseMetadataProvider (TestCase testCase, AssemblyDefinition fullTestCaseAssemblyDefinition) + : base (testCase, fullTestCaseAssemblyDefinition) + { + } + + public virtual TestCaseLinkerOptions GetLinkerOptions (NPath inputPath) + { + var tclo = new TestCaseLinkerOptions { + Il8n = GetOptionAttributeValue (nameof (Il8nAttribute), "none"), + IgnoreDescriptors = GetOptionAttributeValue (nameof (IgnoreDescriptorsAttribute), true), + IgnoreSubstitutions = GetOptionAttributeValue (nameof (IgnoreSubstitutionsAttribute), true), + IgnoreLinkAttributes = GetOptionAttributeValue (nameof (IgnoreLinkAttributesAttribute), true), + KeepTypeForwarderOnlyAssemblies = GetOptionAttributeValue (nameof (KeepTypeForwarderOnlyAssembliesAttribute), string.Empty), + KeepDebugMembers = GetOptionAttributeValue (nameof (SetupLinkerKeepDebugMembersAttribute), string.Empty), + LinkSymbols = GetOptionAttributeValue (nameof (SetupLinkerLinkSymbolsAttribute), string.Empty), + TrimMode = GetOptionAttributeValue<string> (nameof (SetupLinkerTrimModeAttribute), null), + DefaultAssembliesAction = GetOptionAttributeValue<string> (nameof (SetupLinkerDefaultActionAttribute), null), + SkipUnresolved = GetOptionAttributeValue (nameof (SkipUnresolvedAttribute), false), + StripDescriptors = GetOptionAttributeValue (nameof (StripDescriptorsAttribute), true), + StripSubstitutions = GetOptionAttributeValue (nameof (StripSubstitutionsAttribute), true), + StripLinkAttributes = GetOptionAttributeValue (nameof (StripLinkAttributesAttribute), true), + }; + + foreach (var assemblyAction in _testCaseTypeDefinition.CustomAttributes.Where (attr => attr.AttributeType.Name == nameof (SetupLinkerActionAttribute))) { + var ca = assemblyAction.ConstructorArguments; + tclo.AssembliesAction.Add (new KeyValuePair<string, string> ((string) ca[0].Value, (string) ca[1].Value)); + } + + foreach (var descFile in _testCaseTypeDefinition.CustomAttributes.Where (attr => attr.AttributeType.Name == nameof (SetupLinkerDescriptorFile))) { + var ca = descFile.ConstructorArguments; + var file = (string) ca[0].Value; + tclo.Descriptors.Add (Path.Combine (inputPath, file)); + } + + foreach (var subsFile in _testCaseTypeDefinition.CustomAttributes.Where (attr => attr.AttributeType.Name == nameof (SetupLinkerSubstitutionFileAttribute))) { + var ca = subsFile.ConstructorArguments; + var file = (string) ca[0].Value; + tclo.Substitutions.Add (Path.Combine (inputPath, file)); + } + + foreach (var linkAttrFile in _testCaseTypeDefinition.CustomAttributes.Where (attr => attr.AttributeType.Name == nameof (SetupLinkAttributesFile))) { + var ca = linkAttrFile.ConstructorArguments; + var file = (string) ca[0].Value; + tclo.LinkAttributes.Add (Path.Combine (inputPath, file)); + } + + foreach (var additionalArgumentAttr in _testCaseTypeDefinition.CustomAttributes.Where (attr => attr.AttributeType.Name == nameof (SetupLinkerArgumentAttribute))) { + var ca = additionalArgumentAttr.ConstructorArguments; + var values = ((CustomAttributeArgument[]) ca[1].Value)?.Select (arg => arg.Value.ToString ()).ToArray (); + // Since custom attribute arguments need to be constant expressions, we need to add + // the path to the temp directory (where the custom assembly is located) here. + switch ((string) ca[0].Value) { + case "--custom-step": + int pos = values[0].IndexOf (","); + if (pos != -1) { + string custom_assembly_path = values[0].Substring (pos + 1); + if (!Path.IsPathRooted (custom_assembly_path)) + values[0] = values[0].Substring (0, pos + 1) + Path.Combine (inputPath, custom_assembly_path); + } + break; + case "-a": + if (!Path.IsPathRooted (values[0])) + values[0] = Path.Combine (inputPath, values[0]); + + break; + } + + tclo.AdditionalArguments.Add (new KeyValuePair<string, string[]> ((string) ca[0].Value, values)); + } + + return tclo; + } + + public virtual void CustomizeLinker (LinkerDriver linker, LinkerCustomizations customizations) + { + if (_testCaseTypeDefinition.CustomAttributes.Any (attr => + attr.AttributeType.Name == nameof (DependencyRecordedAttribute))) { + customizations.DependencyRecorder = new TestDependencyRecorder (); + customizations.CustomizeContext += context => { + context.Tracer.AddRecorder (customizations.DependencyRecorder); + }; + } + + if (ValidatesReflectionAccessPatterns (_testCaseTypeDefinition)) { + customizations.ReflectionPatternRecorder = new TestReflectionPatternRecorder (); + customizations.CustomizeContext += context => { + customizations.ReflectionPatternRecorder.PreviousRecorder = context.ReflectionPatternRecorder; + context.ReflectionPatternRecorder = customizations.ReflectionPatternRecorder; + context.LogMessages = true; + }; + } + + if (ValidatesLogMessages (_testCaseTypeDefinition)) { + customizations.CustomizeContext += context => { + context.LogMessages = true; + }; + } + } + + bool ValidatesReflectionAccessPatterns (TypeDefinition testCaseTypeDefinition) + { + if (testCaseTypeDefinition.HasNestedTypes) { + var nestedTypes = new Queue<TypeDefinition> (testCaseTypeDefinition.NestedTypes.ToList ()); + while (nestedTypes.Count > 0) { + if (ValidatesReflectionAccessPatterns (nestedTypes.Dequeue ())) + return true; + } + } + + if (testCaseTypeDefinition.CustomAttributes.Any (attr => + attr.AttributeType.Name == nameof (VerifyAllReflectionAccessPatternsAreValidatedAttribute)) + || testCaseTypeDefinition.AllMembers ().Concat (testCaseTypeDefinition.AllDefinedTypes ()).Any (m => m.CustomAttributes.Any (attr => + attr.AttributeType.Name == nameof (RecognizedReflectionAccessPatternAttribute) || + attr.AttributeType.Name == nameof (UnrecognizedReflectionAccessPatternAttribute)))) + return true; + + return false; + } + + bool ValidatesLogMessages (TypeDefinition testCaseTypeDefinition) + { + if (testCaseTypeDefinition.HasNestedTypes) { + var nestedTypes = new Queue<TypeDefinition> (testCaseTypeDefinition.NestedTypes.ToList ()); + while (nestedTypes.Count > 0) { + if (ValidatesLogMessages (nestedTypes.Dequeue ())) + return true; + } + } + + if (testCaseTypeDefinition.AllMembers ().Concat (testCaseTypeDefinition.AllDefinedTypes ()).Append (testCaseTypeDefinition) + .Any (m => m.CustomAttributes.Any (attr => + attr.AttributeType.Name == nameof (LogContainsAttribute) || + attr.AttributeType.Name == nameof (LogDoesNotContainAttribute)))) + return true; + + return false; + } + + public virtual IEnumerable<SourceAndDestinationPair> GetResponseFiles () + { + return _testCaseTypeDefinition.CustomAttributes + .Where (attr => attr.AttributeType.Name == nameof (SetupLinkerResponseFileAttribute)) + .Select (GetSourceAndRelativeDestinationValue); + } + + public virtual IEnumerable<SourceAndDestinationPair> GetDescriptorFiles () + { + return _testCaseTypeDefinition.CustomAttributes + .Where (attr => attr.AttributeType.Name == nameof (SetupLinkerDescriptorFile)) + .Select (GetSourceAndRelativeDestinationValue); + } + + public virtual IEnumerable<SourceAndDestinationPair> GetSubstitutionFiles () + { + return _testCaseTypeDefinition.CustomAttributes + .Where (attr => attr.AttributeType.Name == nameof (SetupLinkerSubstitutionFileAttribute)) + .Select (GetSourceAndRelativeDestinationValue); + } + + public virtual IEnumerable<SourceAndDestinationPair> GetLinkAttributesFiles () + { + return _testCaseTypeDefinition.CustomAttributes + .Where (attr => attr.AttributeType.Name == nameof (SetupLinkAttributesFile)) + .Select (GetSourceAndRelativeDestinationValue); + } + + public virtual IEnumerable<NPath> GetExtraLinkerReferences () + { + var netcoreappDir = Path.GetDirectoryName (typeof (object).Assembly.Location); + foreach (var assembly in Directory.EnumerateFiles (netcoreappDir)) { + if (Path.GetExtension (assembly) != ".dll") + continue; + var assemblyName = Path.GetFileNameWithoutExtension (assembly); + if (assemblyName.Contains ("Native")) + continue; + if (assemblyName.StartsWith ("Microsoft") || + assemblyName.StartsWith ("System") || + assemblyName == "mscorlib" || assemblyName == "netstandard") + yield return assembly.ToNPath (); + } + } + + public virtual bool LinkPublicAndFamily () + { + return _testCaseTypeDefinition.CustomAttributes + .FirstOrDefault (attr => attr.AttributeType.Name == nameof (SetupLinkerLinkPublicAndFamilyAttribute)) != null; + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests/TestCasesRunner/TestCaseSandbox.cs b/test/Mono.Linker.Tests/TestCasesRunner/TestCaseSandbox.cs index 79e754cb7..33e3601f9 100644 --- a/test/Mono.Linker.Tests/TestCasesRunner/TestCaseSandbox.cs +++ b/test/Mono.Linker.Tests/TestCasesRunner/TestCaseSandbox.cs @@ -74,7 +74,7 @@ namespace Mono.Linker.Tests.TestCasesRunner public IEnumerable<NPath> ResourceFiles => ResourcesDirectory.Files (); - public virtual void Populate (TestCaseMetadaProvider metadataProvider) + public virtual void Populate (TestCaseCompilationMetadataProvider metadataProvider) { _testCase.SourceFile.Copy (_directory); @@ -107,22 +107,6 @@ namespace Mono.Linker.Tests.TestCasesRunner res.Source.FileMustExist ().Copy (ResourcesDirectory.Combine (res.DestinationFileName)); } - foreach (var res in metadataProvider.GetResponseFiles ()) { - res.Source.FileMustExist ().Copy (InputDirectory.Combine (res.DestinationFileName)); - } - - foreach (var res in metadataProvider.GetDescriptorFiles ()) { - res.Source.FileMustExist ().Copy (InputDirectory.Combine (res.DestinationFileName)); - } - - foreach (var res in metadataProvider.GetSubstitutionFiles ()) { - res.Source.FileMustExist ().Copy (InputDirectory.Combine (res.DestinationFileName)); - } - - foreach (var res in metadataProvider.GetLinkAttributesFiles ()) { - res.Source.FileMustExist ().Copy (InputDirectory.Combine (res.DestinationFileName)); - } - foreach (var compileRefInfo in metadataProvider.GetSetupCompileAssembliesBefore ()) { var destination = BeforeReferenceSourceDirectoryFor (compileRefInfo.OutputName).EnsureDirectoryExists (); compileRefInfo.SourceFiles.Copy (destination); @@ -150,6 +134,30 @@ namespace Mono.Linker.Tests.TestCasesRunner } } + /// <summary> + /// Any files that are needed for linking should come from the expectations assembly so that these values + /// can be controlled using #ifs regardless of the framework the NUnit test project is compiled against + /// </summary> + /// <param name="metadataProvider"></param> + public virtual void PopulateFromExpectations (TestCaseMetadataProvider metadataProvider) + { + foreach (var res in metadataProvider.GetResponseFiles ()) { + res.Source.FileMustExist ().Copy (InputDirectory.Combine (res.DestinationFileName)); + } + + foreach (var res in metadataProvider.GetDescriptorFiles ()) { + res.Source.FileMustExist ().Copy (InputDirectory.Combine (res.DestinationFileName)); + } + + foreach (var res in metadataProvider.GetSubstitutionFiles ()) { + res.Source.FileMustExist ().Copy (InputDirectory.Combine (res.DestinationFileName)); + } + + foreach (var res in metadataProvider.GetLinkAttributesFiles ()) { + res.Source.FileMustExist ().Copy (InputDirectory.Combine (res.DestinationFileName)); + } + } + private static NPath GetExpectationsAssemblyPath () { return new Uri (typeof (KeptAttribute).Assembly.Location).LocalPath.ToNPath (); diff --git a/test/Mono.Linker.Tests/TestCasesRunner/TestRunner.cs b/test/Mono.Linker.Tests/TestCasesRunner/TestRunner.cs index 44325138c..f6ce178d0 100644 --- a/test/Mono.Linker.Tests/TestCasesRunner/TestRunner.cs +++ b/test/Mono.Linker.Tests/TestCasesRunner/TestRunner.cs @@ -20,15 +20,21 @@ namespace Mono.Linker.Tests.TestCasesRunner public virtual LinkedTestCaseResult Run (TestCase testCase) { using (var fullTestCaseAssemblyDefinition = AssemblyDefinition.ReadAssembly (testCase.OriginalTestCaseAssemblyPath.ToString ())) { - var metadataProvider = _factory.CreateMetadataProvider (testCase, fullTestCaseAssemblyDefinition); + var compilationMetadataProvider = _factory.CreateCompilationMetadataProvider (testCase, fullTestCaseAssemblyDefinition); - if (metadataProvider.IsIgnored (out string ignoreReason)) + if (compilationMetadataProvider.IsIgnored (out string ignoreReason)) Assert.Ignore (ignoreReason); - var sandbox = Sandbox (testCase, metadataProvider); - var compilationResult = Compile (sandbox, metadataProvider); - PrepForLink (sandbox, compilationResult); - return Link (testCase, sandbox, compilationResult, metadataProvider); + var sandbox = Sandbox (testCase, compilationMetadataProvider); + var compilationResult = Compile (sandbox, compilationMetadataProvider); + using (var expectationsAssemblyDefinition = AssemblyDefinition.ReadAssembly (compilationResult.ExpectationsAssemblyPath.ToString ())) { + var metadataProvider = _factory.CreateMetadataProvider (testCase, expectationsAssemblyDefinition); + + sandbox.PopulateFromExpectations (metadataProvider); + + PrepForLink (sandbox, compilationResult); + return Link (testCase, sandbox, compilationResult, metadataProvider); + } } } @@ -38,14 +44,14 @@ namespace Mono.Linker.Tests.TestCasesRunner return Link (result.TestCase, result.Sandbox, result.CompilationResult, result.MetadataProvider); } - private TestCaseSandbox Sandbox (TestCase testCase, TestCaseMetadaProvider metadataProvider) + private TestCaseSandbox Sandbox (TestCase testCase, TestCaseCompilationMetadataProvider metadataProvider) { var sandbox = _factory.CreateSandbox (testCase); sandbox.Populate (metadataProvider); return sandbox; } - private ManagedCompilationResult Compile (TestCaseSandbox sandbox, TestCaseMetadaProvider metadataProvider) + private ManagedCompilationResult Compile (TestCaseSandbox sandbox, TestCaseCompilationMetadataProvider metadataProvider) { var inputCompiler = _factory.CreateCompiler (sandbox, metadataProvider); var expectationsCompiler = _factory.CreateCompiler (sandbox, metadataProvider); @@ -90,7 +96,7 @@ namespace Mono.Linker.Tests.TestCasesRunner { } - private LinkedTestCaseResult Link (TestCase testCase, TestCaseSandbox sandbox, ManagedCompilationResult compilationResult, TestCaseMetadaProvider metadataProvider) + private LinkedTestCaseResult Link (TestCase testCase, TestCaseSandbox sandbox, ManagedCompilationResult compilationResult, TestCaseMetadataProvider metadataProvider) { var linker = _factory.CreateLinker (); var linkerCustomizations = CustomizeLinker (linker, metadataProvider); @@ -105,7 +111,7 @@ namespace Mono.Linker.Tests.TestCasesRunner return new LinkedTestCaseResult (testCase, compilationResult.InputAssemblyPath, sandbox.OutputDirectory.Combine (compilationResult.InputAssemblyPath.FileName), compilationResult.ExpectationsAssemblyPath, sandbox, metadataProvider, compilationResult, logger, linkerCustomizations); } - protected virtual void AddLinkOptions (TestCaseSandbox sandbox, ManagedCompilationResult compilationResult, LinkerArgumentBuilder builder, TestCaseMetadaProvider metadataProvider) + protected virtual void AddLinkOptions (TestCaseSandbox sandbox, ManagedCompilationResult compilationResult, LinkerArgumentBuilder builder, TestCaseMetadataProvider metadataProvider) { var caseDefinedOptions = metadataProvider.GetLinkerOptions (sandbox.InputDirectory); @@ -130,7 +136,7 @@ namespace Mono.Linker.Tests.TestCasesRunner builder.ProcessTestInputAssembly (compilationResult.InputAssemblyPath); } - protected virtual LinkerCustomizations CustomizeLinker (LinkerDriver linker, TestCaseMetadaProvider metadataProvider) + protected virtual LinkerCustomizations CustomizeLinker (LinkerDriver linker, TestCaseMetadataProvider metadataProvider) { LinkerCustomizations customizations = new LinkerCustomizations (); |