Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions src/System.Management.Automation/engine/PSVersionInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,8 @@ private const int Version_Major
private static readonly Version s_psV4Version = new(4, 0);
private static readonly Version s_psV5Version = new(5, 0);
private static readonly Version s_psV51Version = new(5, 1);
private static readonly Version s_psV6Version = new(6, 0, 0);
private static readonly Version s_psV61Version = new(6, 1, 0);
private static readonly Version s_psV62Version = new(6, 2, 0);
private static readonly Version s_psV7Version = new(7, 0, 0);
private static readonly Version s_psV71Version = new(7, 1, 0);
private static readonly Version s_psV72Version = new(7, 2, 0);
private static readonly Version s_psV73Version = new(7, 3, 0);
private static readonly Version s_psV6Version = new(6, 0);
private static readonly Version s_psV7Version = new(7, 0);
private static readonly Version s_psVersion;
private static readonly SemanticVersion s_psSemVersion;

Expand All @@ -98,7 +93,7 @@ static PSVersionInfo()
s_psVersionTable[PSVersionName] = s_psSemVersion;
s_psVersionTable[PSEditionName] = PSEditionValue;
s_psVersionTable[PSGitCommitIdName] = GitCommitId;
s_psVersionTable[PSCompatibleVersionsName] = new Version[] { s_psV1Version, s_psV2Version, s_psV3Version, s_psV4Version, s_psV5Version, s_psV51Version, s_psV6Version, s_psV61Version, s_psV62Version, s_psV7Version, s_psV71Version, s_psV72Version, s_psV73Version, s_psVersion };
s_psVersionTable[PSCompatibleVersionsName] = new Version[] { s_psV1Version, s_psV2Version, s_psV3Version, s_psV4Version, s_psV5Version, s_psV51Version, s_psV6Version, s_psV7Version };
s_psVersionTable[SerializationVersionName] = new Version(InternalSerializer.DefaultVersion);
s_psVersionTable[PSRemotingProtocolVersionName] = RemotingConstants.ProtocolVersion;
s_psVersionTable[WSManStackVersionName] = GetWSManStackVersion();
Expand Down
35 changes: 24 additions & 11 deletions test/powershell/Host/PSVersionTable.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Describe "PSVersionTable" -Tags "CI" {

BeforeAll {
Set-StrictMode -Version 3
$sma = Get-Item (Join-Path $PSHOME "System.Management.Automation.dll")
$formattedVersion = $sma.VersionInfo.ProductVersion

Expand All @@ -22,10 +23,6 @@ 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", "7.1", "7.2", "7.3", "7.4"
$powerShellCompatibleVersions = $PSVersionTable.PSCompatibleVersions |
ForEach-Object {$_.ToString(2).SubString(0,3)}
}

It "Should have version table entries" {
Expand Down Expand Up @@ -163,15 +160,31 @@ Describe "PSVersionTable" -Tags "CI" {
}
}

It "Verify PSCompatibleVersions has an entry for all known versions of PowerShell" {
foreach ($version in $powerShellVersions) {
$version | Should -BeIn $powerShellCompatibleVersions
Context "PSCompatibleVersions property" {
It "Is of type System.Version[]" {
Should -ActualValue $PSVersionTable.PSCompatibleVersions -BeOfType System.Version[]
}

It "Is sorted in ascending order" {
$array = $PSVersionTable.PSCompatibleVersions
[array]::Sort($array)

$PSVersionTable.PSCompatibleVersions | Should -Be $array
}
}

It "Verify PSCompatibleVersions has no unknown PowerShell entries" {
foreach ($version in $powerShellCompatibleVersions) {
$version | Should -BeIn $powerShellVersions
It "Has no unexpected items present" {
$expectedItems = @(
[version]::new(1, 0)
[version]::new(2, 0)
[version]::new(3, 0)
[version]::new(4, 0)
[version]::new(5, 0)
[version]::new(5, 1)
[version]::new(6, 0)
[version]::new(7, 0)
)

Compare-Object $expectedItems $PSVersionTable.PSCompatibleVersions | Should -Be $null
}
}
}