Add pathSeparator back into regex, remove testhost- from regex, update baselines for regex, add generic placeholders, remove diff assert that's not in main branch

This commit is contained in:
Ella Hathaway 2023-09-05 23:41:24 +00:00
parent f891d66573
commit e7de907edb
3 changed files with 249 additions and 249 deletions

View file

@ -16,10 +16,10 @@ namespace Microsoft.DotNet.SourceBuild.SmokeTests
{ {
internal class BaselineHelper internal class BaselineHelper
{ {
private const string VersionPlaceholder = "x.y.z"; private const string SemanticVersionPlaceholder = "x.y.z";
private const string VersionPlaceholderMatchingPattern = "*.*.*"; // wildcard pattern used to match on the version represented by the placeholder private const string SemanticVersionPlaceholderMatchingPattern = "*.*.*"; // wildcard pattern used to match on the version represented by the placeholder
private const string NetTfmPlaceholder = "netx.y"; private const string NonSemanticVersionPlaceholder = "x.y";
private const string NetTfmPlaceholderMatchingPattern = "net*.*"; // wildcard pattern used to match on the version represented by the placeholder private const string NonSemanticVersionPlaceholderMatchingPattern = "*.*"; // wildcard pattern used to match on the version represented by the placeholder
public static void CompareEntries(string baselineFileName, IOrderedEnumerable<string> actualEntries) public static void CompareEntries(string baselineFileName, IOrderedEnumerable<string> actualEntries)
{ {
@ -81,7 +81,6 @@ namespace Microsoft.DotNet.SourceBuild.SmokeTests
{ {
(Process Process, string StdOut, string StdErr) diffResult = (Process Process, string StdOut, string StdErr) diffResult =
ExecuteHelper.ExecuteProcess("git", $"diff --no-index {file1Path} {file2Path}", outputHelper); ExecuteHelper.ExecuteProcess("git", $"diff --no-index {file1Path} {file2Path}", outputHelper);
Assert.Equal(1, diffResult.Process.ExitCode);
return diffResult.StdOut; return diffResult.StdOut;
} }
@ -95,13 +94,14 @@ namespace Microsoft.DotNet.SourceBuild.SmokeTests
public static string RemoveVersions(string source) public static string RemoveVersions(string source)
{ {
// Remove version numbers for examples like "roslyn4.1", "testhost-1.0", "net8.0", and "netstandard2.1". // Remove version numbers for examples like "roslyn4.1", "net8.0", and "netstandard2.1".
string result = Regex.Replace(source, $@"(roslyn|testhost-|netstandard|net)\d+\.\d+", match => string pathSeparator = Regex.Escape(Path.DirectorySeparatorChar.ToString());
string result = Regex.Replace(source, $@"{pathSeparator}(net|netstandard|roslyn)[1-9]+\.[0-9]+{pathSeparator}", match =>
{ {
string wordPart = match.Groups[1].Value; string wordPart = match.Groups[1].Value;
return $"{wordPart}x.y"; return $"{Path.DirectorySeparatorChar}{wordPart}{NonSemanticVersionPlaceholder}{Path.DirectorySeparatorChar}";
}); });
// Remove semantic versions // Remove semantic versions
// Regex source: https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string // Regex source: https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string
// The regex from https://semver.org has been modified to account for the following: // The regex from https://semver.org has been modified to account for the following:
@ -110,11 +110,11 @@ namespace Microsoft.DotNet.SourceBuild.SmokeTests
// - The version may have one or more release identifiers that begin with '.' or '-' // - The version may have one or more release identifiers that begin with '.' or '-'
// - The version should end before a path separator, '.', '-', or '/' // - The version should end before a path separator, '.', '-', or '/'
Regex semanticVersionRegex = new( Regex semanticVersionRegex = new(
@"(?<=[./-])(0|[1-9]\d*)\.(0|[1-9]\d*)(\.(0|[1-9]\d*))+" + @"(?<=[./-])(0|[1-9]\d*)\.(0|[1-9]\d*)(\.(0|[1-9]\d*))+"
@"(((?:[-.]((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)))+" + + @"(((?:[-.]((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)))+"
@"(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?" + + @"(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?"
@"(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?(?=[/.-])"); + @"(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?(?=[/.-])");
return semanticVersionRegex.Replace(result, VersionPlaceholder); return semanticVersionRegex.Replace(result, SemanticVersionPlaceholder);
} }
/// <summary> /// <summary>
@ -124,8 +124,8 @@ namespace Microsoft.DotNet.SourceBuild.SmokeTests
public static Matcher GetFileMatcherFromPath(string path) public static Matcher GetFileMatcherFromPath(string path)
{ {
path = path path = path
.Replace(VersionPlaceholder, VersionPlaceholderMatchingPattern) .Replace(SemanticVersionPlaceholder, SemanticVersionPlaceholderMatchingPattern)
.Replace(NetTfmPlaceholder, NetTfmPlaceholderMatchingPattern); .Replace(NonSemanticVersionPlaceholder, NonSemanticVersionPlaceholderMatchingPattern);
Matcher matcher = new(); Matcher matcher = new();
matcher.AddInclude(path); matcher.AddInclude(path);
return matcher; return matcher;

View file

@ -45,7 +45,7 @@ index ------------
./packs/Microsoft.NETCore.App.Ref/x.y.z/ ./packs/Microsoft.NETCore.App.Ref/x.y.z/
./packs/Microsoft.NETCore.App.Ref/x.y.z/analyzers/ ./packs/Microsoft.NETCore.App.Ref/x.y.z/analyzers/
@@ ------------ @@ @@ ------------ @@
./packs/NETStandard.Library.Ref/x.y.z/ref/netstandard2.1/System.Xml.XPath.XDocument.dll ./packs/NETStandard.Library.Ref/x.y.z/ref/netstandardx.y/System.Xml.XPath.XDocument.dll
./sdk-manifests/ ./sdk-manifests/
./sdk-manifests/x.y.z/ ./sdk-manifests/x.y.z/
-./sdk-manifests/x.y.z/ -./sdk-manifests/x.y.z/