diff options
author | Michael Voorhees <michaelv@unity3d.com> | 2019-02-21 17:13:07 +0300 |
---|---|---|
committer | Marek Safar <marek.safar@gmail.com> | 2019-02-22 16:03:43 +0300 |
commit | ecfb524ca4075c09c3cc881c47e7b7f3723761a6 (patch) | |
tree | 437e8ab8d8f4fa9ef21a04283ca5971fa99c2be8 /test/Mono.Linker.Tests | |
parent | d8ed41032df454320e42e117da0735e1e54636ff (diff) |
Support [KeptInterface] with generics
Diffstat (limited to 'test/Mono.Linker.Tests')
-rw-r--r-- | test/Mono.Linker.Tests/TestCasesRunner/AssemblyChecker.cs | 44 |
1 files changed, 27 insertions, 17 deletions
diff --git a/test/Mono.Linker.Tests/TestCasesRunner/AssemblyChecker.cs b/test/Mono.Linker.Tests/TestCasesRunner/AssemblyChecker.cs index 9893a82a1..fc8968fa5 100644 --- a/test/Mono.Linker.Tests/TestCasesRunner/AssemblyChecker.cs +++ b/test/Mono.Linker.Tests/TestCasesRunner/AssemblyChecker.cs @@ -155,22 +155,7 @@ namespace Mono.Linker.Tests.TestCasesRunner { string expectedBaseName; var expectedBaseGenericAttr = src.CustomAttributes.FirstOrDefault (w => w.AttributeType.Name == nameof (KeptBaseTypeAttribute) && w.ConstructorArguments.Count > 1); if (expectedBaseGenericAttr != null) { - StringBuilder builder = new StringBuilder (); - builder.Append (expectedBaseGenericAttr.ConstructorArguments [0].Value); - builder.Append ("<"); - bool separator = false; - foreach (var caa in (CustomAttributeArgument[])expectedBaseGenericAttr.ConstructorArguments [1].Value) { - if (separator) - builder.Append (","); - else - separator = true; - - var arg = (CustomAttributeArgument)caa.Value; - builder.Append (arg.Value); - } - - builder.Append (">"); - expectedBaseName = builder.ToString (); + expectedBaseName = FormatBaseOrInterfaceAttributeValue (expectedBaseGenericAttr); } else { var defaultBaseType = src.IsEnum ? "System.Enum" : src.IsValueType ? "System.ValueType" : "System.Object"; expectedBaseName = GetCustomAttributeCtorValues<object> (src, nameof (KeptBaseTypeAttribute)).FirstOrDefault ()?.ToString () ?? defaultBaseType; @@ -180,7 +165,9 @@ namespace Mono.Linker.Tests.TestCasesRunner { void VerifyInterfaces (TypeDefinition src, TypeDefinition linked) { - var expectedInterfaces = new HashSet<string> (GetCustomAttributeCtorValues<object> (src, nameof (KeptInterfaceAttribute)).Select (val => val.ToString ())); + var expectedInterfaces = new HashSet<string> (src.CustomAttributes + .Where (w => w.AttributeType.Name == nameof (KeptInterfaceAttribute)) + .Select (FormatBaseOrInterfaceAttributeValue)); if (expectedInterfaces.Count == 0) { Assert.IsFalse (linked.HasInterfaces, $"Type `{src}' has unexpected interfaces"); } else { @@ -192,6 +179,29 @@ namespace Mono.Linker.Tests.TestCasesRunner { } } + static string FormatBaseOrInterfaceAttributeValue (CustomAttribute attr) + { + if (attr.ConstructorArguments.Count == 1) + return attr.ConstructorArguments [0].Value.ToString (); + + StringBuilder builder = new StringBuilder (); + builder.Append (attr.ConstructorArguments [0].Value); + builder.Append ("<"); + bool separator = false; + foreach (var caa in (CustomAttributeArgument [])attr.ConstructorArguments [1].Value) { + if (separator) + builder.Append (","); + else + separator = true; + + var arg = (CustomAttributeArgument)caa.Value; + builder.Append (arg.Value); + } + + builder.Append (">"); + return builder.ToString (); + } + void VerifyField (FieldDefinition src, FieldDefinition linked) { bool expectedKept = ShouldBeKept (src); |