fix: Types that became internal were not being detected as removed

Previously, removed types were only flagged if removed completely, and mistakenly ignored if only their visibility had changed.
This commit is contained in:
David Oliver 2020-05-21 18:31:16 -04:00
Родитель 4aa3b7a2af
Коммит 05c12ef702
4 изменённых файлов: 52 добавлений и 10 удалений

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

@ -98,5 +98,21 @@ namespace Uno.PackageDiff.Tests
Assert.AreEqual("TestMethod", r.InvalidMethods.ElementAt(0).Name);
Assert.AreEqual("System.Threading.Tasks.Task Uno.PackageDiff.Tests.Sources.When_Target_Method_ChangedReturnType::TestMethod()", r.InvalidMethods.ElementAt(0).ToString());
}
[TestMethod]
public void When_Target_Type_Internal()
{
var context = _builder.BuildAssemblies();
var r = AssemblyComparer.CompareTypes(context.BaseAssembly, context.TargetAssembly);
Assert.AreEqual(1, r.InvalidTypes.Length);
// Changed members of removed (no longer visible) types shouldn't be flagged
Assert.AreEqual(0, r.InvalidEvents.Length);
Assert.AreEqual(0, r.InvalidFields.Length);
Assert.AreEqual(0, r.InvalidMethods.Length);
Assert.AreEqual(0, r.InvalidProperties.Length);
}
}
}

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

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Uno.PackageDiff.Tests.Sources
{
public class When_Target_Type_Internal
{
public int MyProperty { get; set; }
public void MyMethod() { }
}
}

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

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Uno.PackageDiff.Tests.Sources
{
internal class When_Target_Type_Internal
{
public double MyProperty { get; set; }
public void MyMethod(int newParam) { }
}
}

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

@ -36,20 +36,20 @@ namespace Uno.PackageDiff
var baseTypes = baseAssembly.MainModule.GetTypes();
var targetTypes = targetAssembly.MainModule.GetTypes();
// Types only in target
var q = from targetType in baseTypes
where !targetTypes.Any(t => t.FullName == targetType.FullName)
where targetType.IsPublic
select targetType;
// Types only in base
var q = from baseType in baseTypes
where baseType.IsPublic
where !targetTypes.Any(t => t.FullName == baseType.FullName && t.IsPublic)
select baseType;
var invalidTypes = q.ToArray();
var existingTypes = (
from targetType in baseTypes
let sourceType = targetTypes.FirstOrDefault(t => t.FullName == targetType.FullName)
where sourceType != null
where targetType.IsPublic
select (sourceType, targetType)
from baseType in baseTypes
where baseType.IsPublic
let sourceType = targetTypes.FirstOrDefault(t => t.FullName == baseType.FullName)
where sourceType != null && sourceType.IsPublic
select (sourceType, baseType)
).ToArray();
var invalidProperties = FindMissingProperties(existingTypes);