From a694480e9a59d5b8a3dcae85b886be4fd90c537f Mon Sep 17 00:00:00 2001 From: "Christoph Bergmeister [MVP]" Date: Fri, 17 Apr 2020 19:33:30 +0100 Subject: [PATCH] Make CompatibilityCollector able to parse a single version String (#1446) Co-authored-by: Christoph Bergmeister --- .../Common/PowerShellVersion.cs | 3 ++- PSCompatibilityCollector/Tests/UtilityApi.Tests.ps1 | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/PSCompatibilityCollector/Microsoft.PowerShell.CrossCompatibility/Common/PowerShellVersion.cs b/PSCompatibilityCollector/Microsoft.PowerShell.CrossCompatibility/Common/PowerShellVersion.cs index a875a89e6..fb91e1915 100644 --- a/PSCompatibilityCollector/Microsoft.PowerShell.CrossCompatibility/Common/PowerShellVersion.cs +++ b/PSCompatibilityCollector/Microsoft.PowerShell.CrossCompatibility/Common/PowerShellVersion.cs @@ -88,7 +88,8 @@ public static PowerShellVersion Parse(string versionStr) if (dotCount == 0) { - throw new ArgumentException($"Version string '{versionStr}' must contain at least one dot separator"); + var majorVersion = int.Parse(versionStr); + return new PowerShellVersion(majorVersion, -1, -1, label: null); } versionParts[dotCount] = int.Parse(versionStr.Substring(sectionStartOffset, i - sectionStartOffset)); diff --git a/PSCompatibilityCollector/Tests/UtilityApi.Tests.ps1 b/PSCompatibilityCollector/Tests/UtilityApi.Tests.ps1 index 4183a8b35..3d0108b50 100644 --- a/PSCompatibilityCollector/Tests/UtilityApi.Tests.ps1 +++ b/PSCompatibilityCollector/Tests/UtilityApi.Tests.ps1 @@ -101,6 +101,8 @@ Describe "PowerShell version object" { Context "Version parsing" { BeforeAll { $genericVerCases = @( + @{ VerStr = '42'; Major = 42; Minor = -1; Patch = -1 } + @{ VerStr = '7'; Major = 7; Minor = -1; Patch = -1 } @{ VerStr = '6.1'; Major = 6; Minor = 1; Patch = -1 } @{ VerStr = '5.2.7'; Major = 5; Minor = 2; Patch = 7 } @{ VerStr = '512.2124.71'; Major = 512; Minor = 2124; Patch = 71 }