diff options
author | Jackson Schuster <36744439+jtschuster@users.noreply.github.com> | 2022-05-13 19:20:43 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-13 19:20:43 +0300 |
commit | 107cfcdb1a9f2c45942bc374654b1b42e742d7aa (patch) | |
tree | 91372e5fe6cdf7c1a3e31fdf9f42195ef6250145 /test/Mono.Linker.Tests.Cases.Expectations/Assertions | |
parent | bb974a60d6b42edb17077e6b54b4f1f66fb41819 (diff) |
Add sanity check for overrides (#2793)
Make sure that MethodImpls point to an interface that the type
implements or a base type that is inherited from.
Diffstat (limited to 'test/Mono.Linker.Tests.Cases.Expectations/Assertions')
-rw-r--r-- | test/Mono.Linker.Tests.Cases.Expectations/Assertions/KeptOverrideAttribute.cs | 27 | ||||
-rw-r--r-- | test/Mono.Linker.Tests.Cases.Expectations/Assertions/RemovedOverrideAttribute.cs | 25 |
2 files changed, 52 insertions, 0 deletions
diff --git a/test/Mono.Linker.Tests.Cases.Expectations/Assertions/KeptOverrideAttribute.cs b/test/Mono.Linker.Tests.Cases.Expectations/Assertions/KeptOverrideAttribute.cs new file mode 100644 index 000000000..62bfd0c15 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases.Expectations/Assertions/KeptOverrideAttribute.cs @@ -0,0 +1,27 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System; + +namespace Mono.Linker.Tests.Cases.Expectations.Assertions +{ + /// <summary> + /// Used to ensure that a method should keep an 'override' annotation for a method in the supplied base type. + /// The absence of this attribute does not enforce that the override is removed -- this is different from other Kept attributes + /// To enforce the removal of an override, use <see cref="RemovedOverrideAttribute"/>. + /// Fails in tests if the method doesn't have the override method in the original or linked assembly. + /// </summary> + /// <seealso cref="RemovedOverrideAttribute" /> + [AttributeUsage (AttributeTargets.Method, AllowMultiple = true, Inherited = false)] + public class KeptOverrideAttribute : KeptAttribute + { + public Type TypeWithOverriddenMethodDeclaration; + + public KeptOverrideAttribute (Type typeWithOverriddenMethod) + { + if (typeWithOverriddenMethod == null) + throw new ArgumentNullException (nameof (typeWithOverriddenMethod)); + TypeWithOverriddenMethodDeclaration = typeWithOverriddenMethod; + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases.Expectations/Assertions/RemovedOverrideAttribute.cs b/test/Mono.Linker.Tests.Cases.Expectations/Assertions/RemovedOverrideAttribute.cs new file mode 100644 index 000000000..c15cf9a9e --- /dev/null +++ b/test/Mono.Linker.Tests.Cases.Expectations/Assertions/RemovedOverrideAttribute.cs @@ -0,0 +1,25 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System; + +namespace Mono.Linker.Tests.Cases.Expectations.Assertions +{ + /// <Summary> + /// Used to ensure that a method should remove an 'override' annotation for a method in the supplied base type. + /// Fails in tests if the method has the override method in the linked assembly, + /// or if the override is not found in the original assembly + /// </Summary> + /// <seealso cref="KeptOverrideAttribute" /> + [AttributeUsage (AttributeTargets.Method, AllowMultiple = true, Inherited = false)] + public class RemovedOverrideAttribute : BaseInAssemblyAttribute + { + public Type TypeWithOverriddenMethodDeclaration; + public RemovedOverrideAttribute (Type typeWithOverriddenMethod) + { + if (typeWithOverriddenMethod == null) + throw new ArgumentException ("Value cannot be null or empty.", nameof (typeWithOverriddenMethod)); + TypeWithOverriddenMethodDeclaration = typeWithOverriddenMethod; + } + } +}
\ No newline at end of file |