diff options
Diffstat (limited to 'test')
27 files changed, 352 insertions, 0 deletions
diff --git a/test/ILLink.Tasks.Tests/ILLink.Tasks.Tests.cs b/test/ILLink.Tasks.Tests/ILLink.Tasks.Tests.cs index 44266efb7..bbae3a027 100644 --- a/test/ILLink.Tasks.Tests/ILLink.Tasks.Tests.cs +++ b/test/ILLink.Tasks.Tests/ILLink.Tasks.Tests.cs @@ -304,6 +304,52 @@ namespace ILLink.Tasks.Tests } } + public static IEnumerable<object []> FeatureSettingsCases => new List<object []> { + new object [] { + new ITaskItem [] { + new TaskItem ("FeatureName", new Dictionary<string, string> { { "Value", "true" } }) + }, + }, + new object [] { + new ITaskItem [] { + new TaskItem ("FeatureName", new Dictionary<string, string> { { "Value", "true" } }), + new TaskItem ("FeatureName", new Dictionary<string, string> { { "Value", "false" } }) + }, + }, + new object [] { + new ITaskItem [] { + new TaskItem ("FeatureName1", new Dictionary<string, string> { { "value", "true" } }), + new TaskItem ("FeatureName2", new Dictionary<string, string> { { "value", "false" } }), + }, + }, + }; + + [Theory] + [MemberData (nameof (FeatureSettingsCases))] + public void TestFeatureSettings (ITaskItem [] featureSettings) + { + var task = new MockTask () { + FeatureSettings = featureSettings + }; + using (var driver = task.CreateDriver ()) { + var expectedSettings = featureSettings.Select (f => new { Feature = f.ItemSpec, Value = f.GetMetadata ("Value") }) + .GroupBy (f => f.Feature) + .Select (f => f.Last()) + .ToDictionary (f => f.Feature, f => bool.Parse(f.Value)); + var actualSettings = driver.Context.FeatureSettings; + Assert.Equal (expectedSettings, actualSettings); + } + } + + [Fact] + public void TestInvalidFeatureSettings () + { + var task = new MockTask () { + FeatureSettings = new ITaskItem [] { new TaskItem ("FeatureName") } + }; + Assert.Throws <ArgumentException> (() => task.CreateDriver ()); + } + [Fact] public void TestExtraArgs () { diff --git a/test/Mono.Linker.Tests.Cases/Attributes/OnlyKeepUsed/ComAttributesAreRemovedWhenFeatureExcluded.cs b/test/Mono.Linker.Tests.Cases/Attributes/OnlyKeepUsed/ComAttributesAreRemovedWhenFeatureExcluded.cs index ca83503d4..0fd0317f7 100644 --- a/test/Mono.Linker.Tests.Cases/Attributes/OnlyKeepUsed/ComAttributesAreRemovedWhenFeatureExcluded.cs +++ b/test/Mono.Linker.Tests.Cases/Attributes/OnlyKeepUsed/ComAttributesAreRemovedWhenFeatureExcluded.cs @@ -3,6 +3,9 @@ using Mono.Linker.Tests.Cases.Expectations.Assertions; 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 [SetupLinkerArgument ("--used-attrs-only", "true")] [SetupLinkerArgument ("--exclude-feature", "com")] public class ComAttributesAreRemovedWhenFeatureExcluded { diff --git a/test/Mono.Linker.Tests.Cases/BCLFeatures/ETW/BaseRemovedEventSource.cs b/test/Mono.Linker.Tests.Cases/BCLFeatures/ETW/BaseRemovedEventSource.cs index 38cf2da9d..868ac6d35 100644 --- a/test/Mono.Linker.Tests.Cases/BCLFeatures/ETW/BaseRemovedEventSource.cs +++ b/test/Mono.Linker.Tests.Cases/BCLFeatures/ETW/BaseRemovedEventSource.cs @@ -4,6 +4,9 @@ using Mono.Linker.Tests.Cases.Expectations.Assertions; 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 [SetupLinkerArgument ("--exclude-feature", "etw")] // Keep framework code that calls EventSource methods like OnEventCommand [SetupLinkerCoreAction ("skip")] diff --git a/test/Mono.Linker.Tests.Cases/BCLFeatures/ETW/BaseRemovedEventSourceEmptyBody.cs b/test/Mono.Linker.Tests.Cases/BCLFeatures/ETW/BaseRemovedEventSourceEmptyBody.cs index c36fa18ab..05fc018c6 100644 --- a/test/Mono.Linker.Tests.Cases/BCLFeatures/ETW/BaseRemovedEventSourceEmptyBody.cs +++ b/test/Mono.Linker.Tests.Cases/BCLFeatures/ETW/BaseRemovedEventSourceEmptyBody.cs @@ -3,6 +3,9 @@ using Mono.Linker.Tests.Cases.Expectations.Assertions; 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 [SetupLinkerArgument ("--exclude-feature", "etw")] // Keep framework code that calls EventSource methods like OnEventCommand [SetupLinkerCoreAction ("skip")] diff --git a/test/Mono.Linker.Tests.Cases/BCLFeatures/ETW/Excluded.cs b/test/Mono.Linker.Tests.Cases/BCLFeatures/ETW/Excluded.cs index 0568f7a3d..59be7a22d 100644 --- a/test/Mono.Linker.Tests.Cases/BCLFeatures/ETW/Excluded.cs +++ b/test/Mono.Linker.Tests.Cases/BCLFeatures/ETW/Excluded.cs @@ -4,6 +4,9 @@ using Mono.Linker.Tests.Cases.Expectations.Assertions; 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 [SetupLinkerArgument ("--exclude-feature", "etw")] // Keep framework code that calls EventSource methods like OnEventCommand [SetupLinkerCoreAction ("skip")] diff --git a/test/Mono.Linker.Tests.Cases/BCLFeatures/ETW/LocalsOfModifiedMethodAreRemoved.cs b/test/Mono.Linker.Tests.Cases/BCLFeatures/ETW/LocalsOfModifiedMethodAreRemoved.cs index 97af4deaf..06ba2b79f 100644 --- a/test/Mono.Linker.Tests.Cases/BCLFeatures/ETW/LocalsOfModifiedMethodAreRemoved.cs +++ b/test/Mono.Linker.Tests.Cases/BCLFeatures/ETW/LocalsOfModifiedMethodAreRemoved.cs @@ -3,6 +3,9 @@ using Mono.Linker.Tests.Cases.Expectations.Assertions; 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 [SetupLinkerArgument ("--exclude-feature", "etw")] // Keep framework code that calls EventSource methods like OnEventCommand [SetupLinkerCoreAction ("skip")] diff --git a/test/Mono.Linker.Tests.Cases/BCLFeatures/ETW/NonEventWithLog.cs b/test/Mono.Linker.Tests.Cases/BCLFeatures/ETW/NonEventWithLog.cs index 5b0b82f18..e6f76bf95 100644 --- a/test/Mono.Linker.Tests.Cases/BCLFeatures/ETW/NonEventWithLog.cs +++ b/test/Mono.Linker.Tests.Cases/BCLFeatures/ETW/NonEventWithLog.cs @@ -4,6 +4,9 @@ using Mono.Linker.Tests.Cases.Expectations.Assertions; 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 [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 7d6cb22c8..68ca8f37c 100644 --- a/test/Mono.Linker.Tests.Cases/BCLFeatures/ETW/StubbedMethodWithExceptionHandlers.cs +++ b/test/Mono.Linker.Tests.Cases/BCLFeatures/ETW/StubbedMethodWithExceptionHandlers.cs @@ -4,6 +4,9 @@ using Mono.Linker.Tests.Cases.Expectations.Assertions; 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 [SetupLinkerArgument ("--exclude-feature", "etw")] // Keep framework code that calls EventSource methods like OnEventCommand [SetupLinkerCoreAction ("skip")] 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 de8908678..597da0c7b 100644 --- a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/UnusedComInterfaceIsRemovedWhenComFeatureExcluded.cs +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/UnusedComInterfaceIsRemovedWhenComFeatureExcluded.cs @@ -3,6 +3,9 @@ using Mono.Linker.Tests.Cases.Expectations.Assertions; 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 [SetupLinkerArgument ("--exclude-feature", "com")] public class UnusedComInterfaceIsRemovedWhenComFeatureExcluded { public static void Main () diff --git a/test/Mono.Linker.Tests.Cases/LinkXml/CanPreserveExcludedFeatureCom.cs b/test/Mono.Linker.Tests.Cases/LinkXml/CanPreserveExcludedFeatureCom.cs index 0016d7272..df2aeb29f 100644 --- a/test/Mono.Linker.Tests.Cases/LinkXml/CanPreserveExcludedFeatureCom.cs +++ b/test/Mono.Linker.Tests.Cases/LinkXml/CanPreserveExcludedFeatureCom.cs @@ -4,6 +4,9 @@ using Mono.Linker.Tests.Cases.Expectations.Assertions; 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 [SetupLinkerArgument ("--exclude-feature", "com")] public class CanPreserveExcludedFeatureCom { public static void Main() diff --git a/test/Mono.Linker.Tests.Cases/LinkXml/FeatureExclude/OnAssembly.cs b/test/Mono.Linker.Tests.Cases/LinkXml/FeatureExclude/OnAssembly.cs index cbdfb5509..59d546a15 100644 --- a/test/Mono.Linker.Tests.Cases/LinkXml/FeatureExclude/OnAssembly.cs +++ b/test/Mono.Linker.Tests.Cases/LinkXml/FeatureExclude/OnAssembly.cs @@ -3,6 +3,9 @@ using Mono.Linker.Tests.Cases.Expectations.Metadata; 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 [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 e733ab2d1..2cf664c5e 100644 --- a/test/Mono.Linker.Tests.Cases/LinkXml/FeatureExclude/OnEvent.cs +++ b/test/Mono.Linker.Tests.Cases/LinkXml/FeatureExclude/OnEvent.cs @@ -3,6 +3,9 @@ using Mono.Linker.Tests.Cases.Expectations.Assertions; 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 [SetupLinkerArgument ("--exclude-feature", "one")] public class OnEvent { public static void Main () diff --git a/test/Mono.Linker.Tests.Cases/LinkXml/FeatureExclude/OnField.cs b/test/Mono.Linker.Tests.Cases/LinkXml/FeatureExclude/OnField.cs index 93a61f0ab..466be6199 100644 --- a/test/Mono.Linker.Tests.Cases/LinkXml/FeatureExclude/OnField.cs +++ b/test/Mono.Linker.Tests.Cases/LinkXml/FeatureExclude/OnField.cs @@ -2,6 +2,9 @@ using Mono.Linker.Tests.Cases.Expectations.Assertions; 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 [SetupLinkerArgument ("--exclude-feature", "one")] public class OnField { public static void Main () diff --git a/test/Mono.Linker.Tests.Cases/LinkXml/FeatureExclude/OnMethod.cs b/test/Mono.Linker.Tests.Cases/LinkXml/FeatureExclude/OnMethod.cs index 11feb7a6a..30741f2a2 100644 --- a/test/Mono.Linker.Tests.Cases/LinkXml/FeatureExclude/OnMethod.cs +++ b/test/Mono.Linker.Tests.Cases/LinkXml/FeatureExclude/OnMethod.cs @@ -2,6 +2,9 @@ using Mono.Linker.Tests.Cases.Expectations.Assertions; 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 [SetupLinkerArgument ("--exclude-feature", "one")] public class OnMethod { public static void Main () diff --git a/test/Mono.Linker.Tests.Cases/LinkXml/FeatureExclude/OnProperty.cs b/test/Mono.Linker.Tests.Cases/LinkXml/FeatureExclude/OnProperty.cs index eb043fb01..c550c605c 100644 --- a/test/Mono.Linker.Tests.Cases/LinkXml/FeatureExclude/OnProperty.cs +++ b/test/Mono.Linker.Tests.Cases/LinkXml/FeatureExclude/OnProperty.cs @@ -2,6 +2,9 @@ using Mono.Linker.Tests.Cases.Expectations.Assertions; 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 [SetupLinkerArgument ("--exclude-feature", "one")] public class OnProperty { public static void Main () diff --git a/test/Mono.Linker.Tests.Cases/LinkXml/FeatureExclude/OnType.cs b/test/Mono.Linker.Tests.Cases/LinkXml/FeatureExclude/OnType.cs index 368812fcc..731f54080 100644 --- a/test/Mono.Linker.Tests.Cases/LinkXml/FeatureExclude/OnType.cs +++ b/test/Mono.Linker.Tests.Cases/LinkXml/FeatureExclude/OnType.cs @@ -2,6 +2,9 @@ using Mono.Linker.Tests.Cases.Expectations.Assertions; 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 [SetupLinkerArgument ("--exclude-feature", "one")] public class OnType { public static void Main () diff --git a/test/Mono.Linker.Tests.Cases/Substitutions/EmbeddedSubstitutions.cs b/test/Mono.Linker.Tests.Cases/Substitutions/EmbeddedSubstitutions.cs new file mode 100644 index 000000000..479be2d6f --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Substitutions/EmbeddedSubstitutions.cs @@ -0,0 +1,25 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.Substitutions +{ + [SetupCompileResource ("EmbeddedSubstitutions.xml", "ILLink.Substitutions.xml")] + [IncludeBlacklistStep (true)] + public class EmbeddedSubstitutions + { + public static void Main () + { + ConvertToThrowMethod (); + } + + [Kept] + [ExpectedInstructionSequence (new [] { + "ldstr", + "newobj", + "throw" + })] + public static void ConvertToThrowMethod () + { + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/Substitutions/EmbeddedSubstitutions.xml b/test/Mono.Linker.Tests.Cases/Substitutions/EmbeddedSubstitutions.xml new file mode 100644 index 000000000..3bd0175a6 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Substitutions/EmbeddedSubstitutions.xml @@ -0,0 +1,7 @@ +<linker> + <assembly fullname="test, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"> + <type fullname="Mono.Linker.Tests.Cases.Substitutions.EmbeddedSubstitutions"> + <method signature="System.Void ConvertToThrowMethod()" body="remove" /> + </type> + </assembly> +</linker>
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Substitutions/FeatureSubstitutions.cs b/test/Mono.Linker.Tests.Cases/Substitutions/FeatureSubstitutions.cs new file mode 100644 index 000000000..980451da4 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Substitutions/FeatureSubstitutions.cs @@ -0,0 +1,51 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.Substitutions +{ + [SetupLinkerSubstitutionFile ("FeatureSubstitutions.xml")] + [SetupLinkerArgument ("--feature", "OptionalFeature", "false")] + public class FeatureSubstitutions + { + [Kept] + static bool IsOptionalFeatureEnabled { + [Kept] + [ExpectedInstructionSequence (new [] { + "ldc.i4.0", + "ret", + })] + get; + } + + public static void Main () + { + TestOptionalFeature (); + } + + [Kept] + [ExpectBodyModified] + [ExpectedInstructionSequence (new [] { + "call", + "brfalse", + "call", + "ret", + })] + static void TestOptionalFeature () + { + if (IsOptionalFeatureEnabled) { + UseOptionalFeature (); + } else { + UseFallback (); + } + } + + static void UseOptionalFeature () + { + } + + [Kept] + static void UseFallback () + { + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/Substitutions/FeatureSubstitutions.xml b/test/Mono.Linker.Tests.Cases/Substitutions/FeatureSubstitutions.xml new file mode 100644 index 000000000..44d332d75 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Substitutions/FeatureSubstitutions.xml @@ -0,0 +1,8 @@ +<linker feature="OptionalFeature" featurevalue="false"> + <assembly fullname="test, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"> + <type fullname="Mono.Linker.Tests.Cases.Substitutions.FeatureSubstitutions"> + <method signature="System.Boolean get_IsOptionalFeatureEnabled()" body="stub" value="false"> + </method> + </type> + </assembly> +</linker>
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Substitutions/FeatureSubstitutionsGlobalFalse.xml b/test/Mono.Linker.Tests.Cases/Substitutions/FeatureSubstitutionsGlobalFalse.xml new file mode 100644 index 000000000..a9452db38 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Substitutions/FeatureSubstitutionsGlobalFalse.xml @@ -0,0 +1,9 @@ +<!-- Check that the feature attribute can be used on the linker element. --> +<linker feature="GlobalCondition" featurevalue="false"> + <assembly fullname="test, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"> + <type fullname="Mono.Linker.Tests.Cases.Substitutions.FeatureInAssembly"> + <method signature="System.Boolean GlobalConditionMethod()" body="stub" value="false"> + </method> + </type> + </assembly> +</linker>
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Substitutions/FeatureSubstitutionsGlobalTrue.xml b/test/Mono.Linker.Tests.Cases/Substitutions/FeatureSubstitutionsGlobalTrue.xml new file mode 100644 index 000000000..3b8d006f9 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Substitutions/FeatureSubstitutionsGlobalTrue.xml @@ -0,0 +1,9 @@ +<!-- Check that the feature attribute can be used on the linker element. --> +<linker feature="GlobalCondition" featurevalue="true"> + <assembly fullname="test, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"> + <type fullname="Mono.Linker.Tests.Cases.Substitutions.FeatureSubstitutionsNested"> + <method signature="System.Boolean GlobalConditionMethod()" body="stub" value="true"> + </method> + </type> + </assembly> +</linker>
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Substitutions/FeatureSubstitutionsInvalid.cs b/test/Mono.Linker.Tests.Cases/Substitutions/FeatureSubstitutionsInvalid.cs new file mode 100644 index 000000000..73ba6acbc --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Substitutions/FeatureSubstitutionsInvalid.cs @@ -0,0 +1,33 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.Substitutions +{ + [SetupLinkerSubstitutionFile ("FeatureSubstitutionsInvalid.xml")] + [SetupLinkerArgument ("--feature", "NoValueFeature", "true")] + [LogContains ("Feature NoValueFeature does not specify a \"featurevalue\" attribute")] + public class FeatureSubstitutionsInvalid + { + public static void Main () + { + NoValueFeatureMethod (); + NonBooleanFeatureMethod (); + BooleanFeatureMethod (); + } + + [Kept] + static void NoValueFeatureMethod () + { + } + + [Kept] + static void NonBooleanFeatureMethod () + { + } + + [Kept] + static void BooleanFeatureMethod () + { + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/Substitutions/FeatureSubstitutionsInvalid.xml b/test/Mono.Linker.Tests.Cases/Substitutions/FeatureSubstitutionsInvalid.xml new file mode 100644 index 000000000..9a0ed8a39 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Substitutions/FeatureSubstitutionsInvalid.xml @@ -0,0 +1,9 @@ +<linker> + <assembly fullname="test, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"> + <type fullname="Mono.Linker.Tests.Cases.Substitutions.FeatureSubstitutionsInvalid"> + <method signature="System.Boolean NoValueFeatureMethod()" body="stub" value="true" feature="NoValueFeature" /> + <method signature="System.Boolean NonBooleanFeatureMethod()" body="stub" value="false" feature="NonBooleanFeature" featurevalue="nonboolean" /> + <method signature="System.Boolean BooleanFeatureMethod()" body="stub" value="false" feature="BooleanFeature" featurevalue="true" /> + </type> + </assembly> +</linker>
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Substitutions/FeatureSubstitutionsNested.cs b/test/Mono.Linker.Tests.Cases/Substitutions/FeatureSubstitutionsNested.cs new file mode 100644 index 000000000..5e124ee48 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Substitutions/FeatureSubstitutionsNested.cs @@ -0,0 +1,75 @@ +using System; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.Substitutions +{ + [SetupLinkerSubstitutionFile ("FeatureSubstitutionsGlobalTrue.xml")] + [SetupLinkerSubstitutionFile ("FeatureSubstitutionsGlobalFalse.xml")] + [SetupLinkerSubstitutionFile ("FeatureSubstitutionsNested.xml")] + [SetupLinkerArgument ("--feature", "GlobalCondition", "true")] + [SetupLinkerArgument ("--feature", "AssemblyCondition", "false")] + [SetupLinkerArgument ("--feature", "TypeCondition", "true")] + [SetupLinkerArgument ("--feature", "MethodCondition", "false")] + [SetupLinkerArgument ("--feature", "FieldCondition", "true")] + public class FeatureSubstitutionsNested + { + public static void Main () { + GlobalConditionMethod (); + AssemblyConditionMethod (); + TypeConditionMethod (); + MethodConditionMethod (); + _ = FieldConditionField; + } + + [Kept] + [ExpectedInstructionSequence (new [] { + "ldc.i4.1", + "ret", + })] + static bool GlobalConditionMethod () { + throw new NotImplementedException (); + } + + [Kept] + [ExpectedInstructionSequence (new [] { + "ldc.i4.0", + "ret", + })] + static bool AssemblyConditionMethod () { + throw new NotImplementedException (); + } + + [Kept] + [ExpectedInstructionSequence (new [] { + "ldc.i4.1", + "ret", + })] + static bool TypeConditionMethod () { + throw new NotImplementedException (); + } + + [Kept] + [ExpectedInstructionSequence (new [] { + "ldc.i4.0", + "ret", + })] + static bool MethodConditionMethod () { + throw new NotImplementedException (); + } + + [Kept] + static readonly bool FieldConditionField; + + [Kept] + [ExpectedInstructionSequence (new [] { + "nop", + "ldc.i4.1", + "stsfld", + "ret" + })] + static FeatureSubstitutionsNested () + { + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Substitutions/FeatureSubstitutionsNested.xml b/test/Mono.Linker.Tests.Cases/Substitutions/FeatureSubstitutionsNested.xml new file mode 100644 index 000000000..122bea08d --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Substitutions/FeatureSubstitutionsNested.xml @@ -0,0 +1,32 @@ +<linker> + <!-- Check that the feature attribute can be used on the assembly element. --> + <assembly fullname="test, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null" feature="AssemblyCondition" featurevalue="false"> + <type fullname="Mono.Linker.Tests.Cases.Substitutions.FeatureSubstitutionsNested"> + <method signature="System.Boolean AssemblyConditionMethod()" body="stub" value="false" /> + </type> + <!-- Or on the type element. --> + <type fullname="Mono.Linker.Tests.Cases.Substitutions.FeatureSubstitutionsNested" feature="TypeCondition" featurevalue="true"> + <method signature="System.Boolean TypeConditionMethod()" body="stub" value="true"> + </method> + <!-- Or on the method element. --> + <method signature="System.Boolean MethodConditionMethod()" body="stub" value="false" feature="MethodCondition" featurevalue="false" /> + <!-- Else case --> + <method signature="System.Boolean MethodConditionMethod()" body="stub" value="true" feature="MethodCondition" featurevalue="true" /> + <!-- Or on the field element. --> + <field name="FieldConditionField" value="true" initialize="true" feature="FieldCondition" featurevalue="true" /> + <!-- Else case --> + <field name="FieldConditionField" value="false" initialize="true" feature="FieldCondition" featurevalue="false" /> + </type> + <!-- Else case for the type feature attribute --> + <type fullname="Mono.Linker.Tests.Cases.Substitutions.FeatureSubstitutionsNested" feature="TypeCondition" featurevalue="false"> + <method signature="System.Boolean TypeConditionMethod()" body="stub" value="false"> + </method> + </type> + </assembly> + <!-- Else case for the assembly feature attribute --> + <assembly fullname="test, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null" feature="AssemblyCondition" featurevalue="true"> + <type fullname="Mono.Linker.Tests.Cases.Substitutions.FeatureSubstitutionsNested"> + <method signature="System.Boolean AssemblyConditionMethod()" body="stub" value="true" /> + </type> + </assembly> +</linker>
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/TestFramework/VerifyExpectModifiedAttributesWork.cs b/test/Mono.Linker.Tests.Cases/TestFramework/VerifyExpectModifiedAttributesWork.cs index 3b3a7f015..787c5179e 100644 --- a/test/Mono.Linker.Tests.Cases/TestFramework/VerifyExpectModifiedAttributesWork.cs +++ b/test/Mono.Linker.Tests.Cases/TestFramework/VerifyExpectModifiedAttributesWork.cs @@ -8,6 +8,9 @@ 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 [SetupLinkerArgument ("--exclude-feature", "etw")] // Keep framework code that calls EventSource methods like OnEventCommand [SetupLinkerCoreAction ("skip")] |