feat: Ignore changes to an ignored type

If a type is in the Types of an ignore file, but is not actually removed, ignore all removed members on that type instead.

In general ignoring individual members explicitly is preferable, but this option is useful in certain special cases, eg breaking changes involving large numbers of properties coming from generated code.
This commit is contained in:
David Oliver 2020-04-07 22:08:41 -04:00
Родитель 80d22b3228
Коммит abf946d749
5 изменённых файлов: 60 добавлений и 5 удалений

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

@ -35,5 +35,16 @@ namespace Uno.PackageDiff.Tests
Assert.IsNotNull(context.IgnoreSet);
Assert.IsTrue(ReportAnalyzer.IsDiffFailed(res, context.IgnoreSet));
}
[TestMethod]
public void When_Ignore_All_Changes_To_Type()
{
var context = _builder.BuildAssemblies();
var comparison = AssemblyComparer.CompareTypes(context.BaseAssembly, context.TargetAssembly);
Assert.IsNotNull(context.IgnoreSet);
Assert.IsFalse(ReportAnalyzer.IsDiffFailed(comparison, context.IgnoreSet));
}
}
}

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

@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Uno.PackageDiff.Tests.Sources
{
public class When_Ignore_All_Changes_To_Type
{
public int OldProperty1 { get; }
public string OldProperty2 { get; protected set; }
public void OldMethod1(float f) { }
public double OldMethod2() => 42d;
public event Action OldEvent;
}
}

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

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8" ?>
<DiffIgnore>
<IgnoreSets>
<IgnoreSet baseVersion="1.0.0">
<Types>
<Member fullName="Uno.PackageDiff.Tests.Sources.When_Ignore_All_Changes_To_Type"/>
</Types>
</IgnoreSet>
</IgnoreSets>
</DiffIgnore>

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

@ -0,0 +1,10 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Uno.PackageDiff.Tests.Sources
{
public class When_Ignore_All_Changes_To_Type
{
}
}

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

@ -9,11 +9,16 @@ namespace Uno.PackageDiff
{
public static bool IsDiffFailed(ComparisonResult results, IgnoreSet ignoreSet)
{
var failedTypes = results.InvalidTypes.Any(t => !ignoreSet.Types.Select(t2 => t2.FullName).Contains(t.ToSignature()));
var failedEvents = results.InvalidEvents.Any(e => !ignoreSet.Events.Select(t => t.FullName).Contains(e.ToSignature()));
var failedFields = results.InvalidFields.Any(f => !ignoreSet.Fields.Select(t => t.FullName).Contains(f.ToSignature()));
var failedMethods = results.InvalidMethods.Any(m => !ignoreSet.Methods.Select(t => t.FullName).Contains(m.ToSignature()));
var failedProperties = results.InvalidProperties.Any(p => !ignoreSet.Properties.Select(t => t.FullName).Contains(p.ToSignature()));
var ignoredTypes = ignoreSet.Types.Select(t2 => t2.FullName);
var failedTypes = results.InvalidTypes.Any(t => !ignoredTypes.Contains(t.ToSignature()));
var failedEvents = results.InvalidEvents.Any(e => !ignoreSet.Events.Select(t => t.FullName).Contains(e.ToSignature())
&& !ignoredTypes.Contains(e.DeclaringType.ToSignature()));
var failedFields = results.InvalidFields.Any(f => !ignoreSet.Fields.Select(t => t.FullName).Contains(f.ToSignature())
&& !ignoredTypes.Contains(f.DeclaringType.ToSignature()));
var failedMethods = results.InvalidMethods.Any(m => !ignoreSet.Methods.Select(t => t.FullName).Contains(m.ToSignature())
&& !ignoredTypes.Contains(m.DeclaringType.ToSignature()));
var failedProperties = results.InvalidProperties.Any(p => !ignoreSet.Properties.Select(t => t.FullName).Contains(p.ToSignature())
&& !ignoredTypes.Contains(p.DeclaringType.ToSignature()));
return failedTypes
|| failedEvents