GeezerVison is showing github.com — Fix `#requires -version` for pwsh 7 to include 6.1 and 6.2 in `PSComp… · PowerShell/PowerShell@ccc791c
File treeExpand file treeCollapse file tree Open diff view settings src/System.Management.Automation/engine
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: src/System.Management.Automation/engine/PSVersionInfo.cs +3-1Lines changed: 3 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -59,6 +59,8 @@ public class PSVersionInfo | 59 | 59 | private static readonly Version s_psV5Version = new Version(5, 0); | 60 | 60 | private static readonly Version s_psV51Version = new Version(5, 1, NTVerpVars.PRODUCTBUILD, NTVerpVars.PRODUCTBUILD_QFE); | 61 | 61 | 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); | 62 | 64 | private static readonly SemanticVersion s_psSemVersion; | 63 | 65 | private static readonly Version s_psVersion; | 64 | 66 |
| @@ -105,7 +107,7 @@ static PSVersionInfo() | 105 | 107 | s_psVersionTable[PSVersionInfo.PSVersionName] = s_psSemVersion; | 106 | 108 | s_psVersionTable[PSVersionInfo.PSEditionName] = PSEditionValue; | 107 | 109 | 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 }; | 109 | 111 | s_psVersionTable[PSVersionInfo.SerializationVersionName] = new Version(InternalSerializer.DefaultVersion); | 110 | 112 | s_psVersionTable[PSVersionInfo.PSRemotingProtocolVersionName] = RemotingConstants.ProtocolVersion; | 111 | 113 | s_psVersionTable[PSVersionInfo.WSManStackVersionName] = GetWSManStackVersion(); | |
Collapse file Copy file name to clipboardExpand all lines: test/powershell/Host/PSVersionTable.Tests.ps1 +16Lines changed: 16 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -22,6 +22,10 @@ Describe "PSVersionTable" -Tags "CI" { | 22 | 22 | $expectedGitCommitIdPattern = "^$mainVersionPattern$" | 23 | 23 | $unexpectectGitCommitIdPattern = $fullVersionPattern | 24 | 24 | } | | 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)} | 25 | 29 | } | 26 | 30 |
| 27 | 31 | It "Should have version table entries" { | @@ -158,4 +162,16 @@ Describe "PSVersionTable" -Tags "CI" { | 158 | 162 | $PSVersionTable.Add("PSEdition", $EditionValue) | 159 | 163 | } | 160 | 164 | } | | 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 | + } | 161 | 177 | } |
Collapse file Copy file name to clipboardExpand all lines: test/powershell/Language/Scripting/Requires.Tests.ps1 +54Lines changed: 54 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -36,6 +36,60 @@ Describe "Requires tests" -Tags "CI" { | 36 | 36 | { $ps.AddScript("#requires").Invoke(@(), $settings) } | Should -Not -Throw | 37 | 37 | } | 38 | 38 | } | | 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 | + } | 39 | 93 | } | 40 | 94 |
| 41 | 95 | Describe "#requires -Modules" -Tags "CI" { | |
|