[tests] Adjust the NoAvailabilityOnError cecil test to look in and work with .NET assemblies as well. (#16891)

Also remove some unnecessary null-checking code.
This commit is contained in:
Rolf Bjarne Kvinge 2022-11-28 18:03:47 +01:00 коммит произвёл GitHub
Родитель 52e3e2f4ee
Коммит e7653c5cde
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
1 изменённых файлов: 12 добавлений и 5 удалений

Просмотреть файл

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
@ -18,10 +19,6 @@ namespace Cecil.Tests {
public void NoAvailabilityOnError (string assemblyPath)
{
var assembly = Helper.GetAssembly (assemblyPath);
if (assembly == null) {
Assert.Ignore ("{assemblyPath} could not be found (might be disabled in build)");
return; // just to help nullability
}
HashSet<string> found = new HashSet<string> ();
foreach (var type in assembly.MainModule.Types)
NoAvailabilityOnError (type, found);
@ -61,6 +58,14 @@ namespace Cecil.Tests {
foreach (var f in type.Fields) {
if (!f.HasCustomAttributes)
continue;
// If there are any ObsoletedOSPlatform attributes, then we must add other availability attributes for supported platforms,
// because otherwise they're implicitly not supported. This means that we can't assert that there aren't any other
// availability attributes if there's any ObsoletedOSPlatform attributes.
var hasAnyObsoletedOSPlatformAttributes = f.CustomAttributes.Any (v => v.AttributeType.Name == "ObsoletedOSPlatformAttribute");
if (hasAnyObsoletedOSPlatformAttributes)
continue;
foreach (var ca in f.CustomAttributes) {
switch (ca.AttributeType.Name) {
case "ObsoleteAttribute":
@ -76,7 +81,9 @@ namespace Cecil.Tests {
case "NoMacAttribute":
case "NoTVAttribute":
case "NoWatchAttribute":
found.Add ($"{type.FullName}.{f.Name}");
case "SupportedOSPlatformAttribute":
case "UnsupportedOSPlatformAttribute":
found.Add ($"{type.FullName}.{f.Name}: {ca.AttributeType.Name}");
break;
default:
break;