Fix #requires -version for pwsh 7 to include 6.1 and 6.2 in PSCompatibleVersions (#9943)

This commit is contained in:
Ben Gelens
2019-08-12 15:25:28 -07:00
committed by Aditya Patwardhan
parent 11d8cd3230
commit ccc791c0a3
3 changed files with 73 additions and 1 deletions
@@ -59,6 +59,8 @@ namespace System.Management.Automation
private static readonly Version s_psV5Version = new Version(5, 0);
private static readonly Version s_psV51Version = new Version(5, 1, NTVerpVars.PRODUCTBUILD, NTVerpVars.PRODUCTBUILD_QFE);
private static readonly SemanticVersion s_psV6Version = new SemanticVersion(6, 0, 0, preReleaseLabel: null, buildLabel: null);
private static readonly SemanticVersion s_psV61Version = new SemanticVersion(6, 1, 0, preReleaseLabel: null, buildLabel: null);
private static readonly SemanticVersion s_psV62Version = new SemanticVersion(6, 2, 0, preReleaseLabel: null, buildLabel: null);
private static readonly SemanticVersion s_psSemVersion;
private static readonly Version s_psVersion;
@@ -105,7 +107,7 @@ namespace System.Management.Automation
s_psVersionTable[PSVersionInfo.PSVersionName] = s_psSemVersion;
s_psVersionTable[PSVersionInfo.PSEditionName] = PSEditionValue;
s_psVersionTable[PSGitCommitIdName] = rawGitCommitId;
s_psVersionTable[PSCompatibleVersionsName] = new Version[] { s_psV1Version, s_psV2Version, s_psV3Version, s_psV4Version, s_psV5Version, s_psV51Version, s_psV6Version, s_psVersion };
s_psVersionTable[PSCompatibleVersionsName] = new Version[] { s_psV1Version, s_psV2Version, s_psV3Version, s_psV4Version, s_psV5Version, s_psV51Version, s_psV6Version, s_psV61Version, s_psV62Version, s_psVersion };
s_psVersionTable[PSVersionInfo.SerializationVersionName] = new Version(InternalSerializer.DefaultVersion);
s_psVersionTable[PSVersionInfo.PSRemotingProtocolVersionName] = RemotingConstants.ProtocolVersion;
s_psVersionTable[PSVersionInfo.WSManStackVersionName] = GetWSManStackVersion();
@@ -22,6 +22,10 @@ Describe "PSVersionTable" -Tags "CI" {
$expectedGitCommitIdPattern = "^$mainVersionPattern$"
$unexpectectGitCommitIdPattern = $fullVersionPattern
}
$powerShellVersions = "1.0", "2.0", "3.0", "4.0", "5.0", "5.1", "6.0", "6.1", "6.2", "7.0"
$powerShellCompatibleVersions = $PSVersionTable.PSCompatibleVersions |
ForEach-Object {$_.ToString(2).SubString(0,3)}
}
It "Should have version table entries" {
@@ -158,4 +162,16 @@ Describe "PSVersionTable" -Tags "CI" {
$PSVersionTable.Add("PSEdition", $EditionValue)
}
}
It "Verify PSCompatibleVersions has an entry for all known versions of PowerShell" {
foreach ($version in $powerShellVersions) {
$version | Should -BeIn $powerShellCompatibleVersions
}
}
It "Verify PSCompatibleVersions has no unknown PowerShell entries" {
foreach ($version in $powerShellCompatibleVersions) {
$version | Should -BeIn $powerShellVersions
}
}
}
@@ -36,6 +36,60 @@ Describe "Requires tests" -Tags "CI" {
{ $ps.AddScript("#requires").Invoke(@(), $settings) } | Should -Not -Throw
}
}
Context "Version checks" {
BeforeAll {
$currentVersion = $PSVersionTable.PSVersion
$powerShellVersions = "1.0", "2.0", "3.0", "4.0", "5.0", "5.1", "6.0", "6.1", "6.2", "7.0"
$latestVersion = [version]($powerShellVersions | Sort-Object -Descending -Top 1)
$nonExistingMinor = "$($latestVersion.Major).$($latestVersion.Minor + 1)"
$nonExistingMajor = "$($latestVersion.Major + 1).0"
foreach ($version in ($powerShellVersions + $nonExistingMinor + $nonExistingMajor)) {
$filePath = Join-Path -Path $TestDrive -ChildPath "$version.ps1"
$null = New-Item -Path $filePath -Value "#requires -version $version"
}
$filesSuccessTestCase = foreach ($version in $powerShellVersions) {
@{
Name = "Check for version $version"
File = Join-Path -Path $TestDrive -ChildPath "$version.ps1"
Version = $version
}
}
$filesFailTestCase = foreach ($version in @($nonExistingMinor) + @($nonExistingMajor)) {
@{
Name = "Check for version $version"
File = Join-Path -Path $TestDrive -ChildPath "$version.ps1"
}
}
}
It "<Name>" -TestCase $filesSuccessTestCase {
param(
$Name,
$File,
$Version
)
if ($currentVersion -notmatch '^7' -and $Version -match '^7') {
Set-ItResult -Skipped -Because "Test not valid for current version - $currentVersion and test version = $Version"
}
{ . $File } | Should -Not -Throw
}
It "<Name>" -TestCase $filesFailTestCase {
param(
$Name,
$File
)
{ . $File } | Should -Throw -ExceptionType ([System.Management.Automation.ScriptRequiresException])
}
}
}
Describe "#requires -Modules" -Tags "CI" {