GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Fix `#requires -version` for pwsh 7 to include 6.1 and 6.2 in `PSComp… · PowerShell/PowerShell@ccc791c

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • src/System.Management.Automation/engine
    • PSVersionInfo.cs
  • test/powershell
    • Host
      • PSVersionTable.Tests.ps1
    • Language/Scripting
      • Requires.Tests.ps1
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/System.Management.Automation/engine/PSVersionInfo.cs‎

Copy file name to clipboardExpand all lines: src/System.Management.Automation/engine/PSVersionInfo.cs
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ public class PSVersionInfo
5959
private static readonly Version s_psV5Version = new Version(5, 0);
6060
private static readonly Version s_psV51Version = new Version(5, 1, NTVerpVars.PRODUCTBUILD, NTVerpVars.PRODUCTBUILD_QFE);
6161
private static readonly SemanticVersion s_psV6Version = new SemanticVersion(6, 0, 0, preReleaseLabel: null, buildLabel: null);
62+
private static readonly SemanticVersion s_psV61Version = new SemanticVersion(6, 1, 0, preReleaseLabel: null, buildLabel: null);
63+
private static readonly SemanticVersion s_psV62Version = new SemanticVersion(6, 2, 0, preReleaseLabel: null, buildLabel: null);
6264
private static readonly SemanticVersion s_psSemVersion;
6365
private static readonly Version s_psVersion;
6466

@@ -105,7 +107,7 @@ static PSVersionInfo()
105107
s_psVersionTable[PSVersionInfo.PSVersionName] = s_psSemVersion;
106108
s_psVersionTable[PSVersionInfo.PSEditionName] = PSEditionValue;
107109
s_psVersionTable[PSGitCommitIdName] = rawGitCommitId;
108-
s_psVersionTable[PSCompatibleVersionsName] = new Version[] { s_psV1Version, s_psV2Version, s_psV3Version, s_psV4Version, s_psV5Version, s_psV51Version, s_psV6Version, s_psVersion };
110+
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 };
109111
s_psVersionTable[PSVersionInfo.SerializationVersionName] = new Version(InternalSerializer.DefaultVersion);
110112
s_psVersionTable[PSVersionInfo.PSRemotingProtocolVersionName] = RemotingConstants.ProtocolVersion;
111113
s_psVersionTable[PSVersionInfo.WSManStackVersionName] = GetWSManStackVersion();
Collapse file

‎test/powershell/Host/PSVersionTable.Tests.ps1‎

Copy file name to clipboardExpand all lines: test/powershell/Host/PSVersionTable.Tests.ps1
+16Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ Describe "PSVersionTable" -Tags "CI" {
2222
$expectedGitCommitIdPattern = "^$mainVersionPattern$"
2323
$unexpectectGitCommitIdPattern = $fullVersionPattern
2424
}
25+
26+
$powerShellVersions = "1.0", "2.0", "3.0", "4.0", "5.0", "5.1", "6.0", "6.1", "6.2", "7.0"
27+
$powerShellCompatibleVersions = $PSVersionTable.PSCompatibleVersions |
28+
ForEach-Object {$_.ToString(2).SubString(0,3)}
2529
}
2630

2731
It "Should have version table entries" {
@@ -158,4 +162,16 @@ Describe "PSVersionTable" -Tags "CI" {
158162
$PSVersionTable.Add("PSEdition", $EditionValue)
159163
}
160164
}
165+
166+
It "Verify PSCompatibleVersions has an entry for all known versions of PowerShell" {
167+
foreach ($version in $powerShellVersions) {
168+
$version | Should -BeIn $powerShellCompatibleVersions
169+
}
170+
}
171+
172+
It "Verify PSCompatibleVersions has no unknown PowerShell entries" {
173+
foreach ($version in $powerShellCompatibleVersions) {
174+
$version | Should -BeIn $powerShellVersions
175+
}
176+
}
161177
}
Collapse file

‎test/powershell/Language/Scripting/Requires.Tests.ps1‎

Copy file name to clipboardExpand all lines: test/powershell/Language/Scripting/Requires.Tests.ps1
+54Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,60 @@ Describe "Requires tests" -Tags "CI" {
3636
{ $ps.AddScript("#requires").Invoke(@(), $settings) } | Should -Not -Throw
3737
}
3838
}
39+
40+
Context "Version checks" {
41+
BeforeAll {
42+
$currentVersion = $PSVersionTable.PSVersion
43+
44+
$powerShellVersions = "1.0", "2.0", "3.0", "4.0", "5.0", "5.1", "6.0", "6.1", "6.2", "7.0"
45+
$latestVersion = [version]($powerShellVersions | Sort-Object -Descending -Top 1)
46+
$nonExistingMinor = "$($latestVersion.Major).$($latestVersion.Minor + 1)"
47+
$nonExistingMajor = "$($latestVersion.Major + 1).0"
48+
49+
foreach ($version in ($powerShellVersions + $nonExistingMinor + $nonExistingMajor)) {
50+
$filePath = Join-Path -Path $TestDrive -ChildPath "$version.ps1"
51+
$null = New-Item -Path $filePath -Value "#requires -version $version"
52+
}
53+
54+
$filesSuccessTestCase = foreach ($version in $powerShellVersions) {
55+
@{
56+
Name = "Check for version $version"
57+
File = Join-Path -Path $TestDrive -ChildPath "$version.ps1"
58+
Version = $version
59+
}
60+
}
61+
62+
$filesFailTestCase = foreach ($version in @($nonExistingMinor) + @($nonExistingMajor)) {
63+
@{
64+
Name = "Check for version $version"
65+
File = Join-Path -Path $TestDrive -ChildPath "$version.ps1"
66+
}
67+
}
68+
}
69+
70+
It "<Name>" -TestCase $filesSuccessTestCase {
71+
param(
72+
$Name,
73+
$File,
74+
$Version
75+
)
76+
77+
if ($currentVersion -notmatch '^7' -and $Version -match '^7') {
78+
Set-ItResult -Skipped -Because "Test not valid for current version - $currentVersion and test version = $Version"
79+
}
80+
81+
{ . $File } | Should -Not -Throw
82+
}
83+
84+
It "<Name>" -TestCase $filesFailTestCase {
85+
param(
86+
$Name,
87+
$File
88+
)
89+
90+
{ . $File } | Should -Throw -ExceptionType ([System.Management.Automation.ScriptRequiresException])
91+
}
92+
}
3993
}
4094

4195
Describe "#requires -Modules" -Tags "CI" {

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.