Skip to content

Commit acb00b9

Browse files
authored
Merge pull request #4048 from cormacpayne/sign-fix
Fix breaking change tool failures during sign job
2 parents cfee58f + 4d2987f commit acb00b9

File tree

2 files changed

+73
-2
lines changed

2 files changed

+73
-2
lines changed

tools/StaticAnalysis/BreakingChangeAnalyzer/CmdletMetadataHelper.cs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
using System.Collections.Generic;
1717
using System.Linq;
1818
using System.Text;
19+
using System.Text.RegularExpressions;
1920
using System.Threading.Tasks;
2021

2122
namespace StaticAnalysis.BreakingChangeAnalyzer
@@ -215,7 +216,7 @@ private void CheckForChangedOutputType(
215216
ReportLogger<BreakingChangeIssue> issueLogger)
216217
{
217218
// This dictionary will map an output type name to the corresponding type metadata
218-
Dictionary<string, TypeMetadata> outputDictionary = new Dictionary<string, TypeMetadata>();
219+
Dictionary<string, TypeMetadata> outputDictionary = new Dictionary<string, TypeMetadata>(new TypeNameComparer());
219220

220221
// Add each output in the new metadata to the dictionary
221222
foreach (var newOutput in newCmdlet.OutputTypes)
@@ -312,5 +313,25 @@ private void CheckDefaultParameterName(
312313
}
313314
}
314315
}
316+
317+
/// <summary>
318+
/// Comparer for assebly qualified names. Parses of the PublicKeyToken, so that types from signed and unsigned assemblies match
319+
/// </summary>
320+
class TypeNameComparer : IEqualityComparer<string>
321+
{
322+
Regex keyToken = new Regex(@", PublicKeyToken=\w+");
323+
public bool Equals(string x, string y)
324+
{
325+
var newX = keyToken.Replace(x, "");
326+
var newY = keyToken.Replace(y, "");
327+
return StringComparer.OrdinalIgnoreCase.Equals(newX, newY);
328+
}
329+
330+
public int GetHashCode(string obj)
331+
{
332+
var newObj = keyToken.Replace(obj, "");
333+
return StringComparer.OrdinalIgnoreCase.GetHashCode(newObj);
334+
}
335+
}
315336
}
316337
}

tools/StaticAnalysis/StaticAnalysis.Test/BreakingChangeAnalyzerTests.cs

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
using StaticAnalysis.ProblemIds;
1+
using StaticAnalysis.BreakingChangeAnalyzer;
2+
using StaticAnalysis.ProblemIds;
23
using System;
4+
using System.Collections;
35
using System.Collections.Generic;
46
using System.IO;
57
using System.Linq;
@@ -856,5 +858,53 @@ public void ChangeValidateRangeMaximum()
856858
.Where<int>((problemId) => problemId.Equals(BreakingChangeProblemId.ChangedValidateRangeMaximum))
857859
.SingleOrDefault<int>().Equals(BreakingChangeProblemId.ChangedValidateRangeMaximum));
858860
}
861+
862+
[Fact]
863+
[Trait(Category.AcceptanceType, Category.CheckIn)]
864+
public void CheckDifferentPublicKeyToken()
865+
{
866+
TypeMetadata unsignedType = new TypeMetadata()
867+
{
868+
AssemblyQualifiedName = "StaticAnalysis.Test.BreakingChangeAnalyzerTests, StaticAnalysis.Test, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
869+
};
870+
TypeMetadata signedType = new TypeMetadata()
871+
{
872+
AssemblyQualifiedName = "StaticAnalysis.Test.BreakingChangeAnalyzerTests, StaticAnalysis.Test, Version=1.0.0.0, Culture=neutral, PublicKeyToken=h1ccnwzjxvldu787"
873+
};
874+
875+
OutputMetadata unsignedOutputType = new OutputMetadata()
876+
{
877+
Type = unsignedType
878+
};
879+
OutputMetadata signedOutputType = new OutputMetadata()
880+
{
881+
Type = signedType
882+
};
883+
884+
CmdletBreakingChangeMetadata unsignedCmdlet = new CmdletBreakingChangeMetadata()
885+
{
886+
VerbName = "Check",
887+
NounName = "DifferentPublicKeyToken",
888+
DefaultParameterSetName = "DefaultParameterSetName"
889+
};
890+
CmdletBreakingChangeMetadata signedCmdlet = new CmdletBreakingChangeMetadata()
891+
{
892+
VerbName = "Check",
893+
NounName = "DifferentPublicKeyToken",
894+
DefaultParameterSetName = "DefaultParameterSetName"
895+
};
896+
897+
unsignedCmdlet.OutputTypes.Add(unsignedOutputType);
898+
signedCmdlet.OutputTypes.Add(signedOutputType);
899+
900+
var issueLogger = analysisLogger.CreateLogger<BreakingChangeIssue>("BreakingChangeIssues.csv");
901+
902+
CmdletMetadataHelper helper = new CmdletMetadataHelper();
903+
helper.CompareCmdletMetadata(new List<CmdletBreakingChangeMetadata> { unsignedCmdlet },
904+
new List<CmdletBreakingChangeMetadata> { signedCmdlet },
905+
issueLogger);
906+
907+
Assert.Equal(0, issueLogger.Records.Count);
908+
}
859909
}
860910
}

0 commit comments

Comments
 (0)