From b3dce144f635f53ecd957577301402bb4e81fa5e Mon Sep 17 00:00:00 2001 From: Ben Gelens Date: Thu, 18 Jul 2019 16:50:40 +0200 Subject: [PATCH 1/3] added psv6.1 and 6.2 to compatible versions --- src/System.Management.Automation/engine/PSVersionInfo.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/System.Management.Automation/engine/PSVersionInfo.cs b/src/System.Management.Automation/engine/PSVersionInfo.cs index 4f49ac8646c..ef58dafb56a 100644 --- a/src/System.Management.Automation/engine/PSVersionInfo.cs +++ b/src/System.Management.Automation/engine/PSVersionInfo.cs @@ -59,6 +59,8 @@ public class PSVersionInfo 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 @@ static PSVersionInfo() 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(); From 16026f968c293f3081bf0bf0154bbbbb0134ea43 Mon Sep 17 00:00:00 2001 From: Aditya Patwardhan Date: Fri, 9 Aug 2019 10:38:23 -0700 Subject: [PATCH 2/3] Add test for Requires -version --- .../Language/Scripting/Requires.Tests.ps1 | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/test/powershell/Language/Scripting/Requires.Tests.ps1 b/test/powershell/Language/Scripting/Requires.Tests.ps1 index d86e683e26c..4d068af2be5 100644 --- a/test/powershell/Language/Scripting/Requires.Tests.ps1 +++ b/test/powershell/Language/Scripting/Requires.Tests.ps1 @@ -36,6 +36,29 @@ Describe "Requires tests" -Tags "CI" { { $ps.AddScript("#requires").Invoke(@(), $settings) } | Should -Not -Throw } } + + Context "Version checks" { + BeforeAll { + $currentVersion = $PSVersionTable.PSVersion + + $files = "6.1", "6.2" | ForEach-Object { New-Item -Path (Join-Path $TestDrive "vers$_.ps1") -Value "#requires -version $_" } + + $filesTestCase = @( + @{ Name = "Check for version 6.1" ; File = $files[0] } + @{ Name = "Check for version 6.2" ; File = $files[1] } + ) + } + + It "" -TestCase $filesTestCase { + param( $Name, $File) + + if ($currentVersion -notmatch '^7') { + Set-ItResult -Skipped -Because "Test not valid for current version - $currentVersion" + } + + { . $file } | Should -Not -Throw + } + } } Describe "#requires -Modules" -Tags "CI" { From 497bd6c9ce96f7d1d7432af2fa19b7ee2bcc7c33 Mon Sep 17 00:00:00 2001 From: Ben Gelens Date: Sat, 10 Aug 2019 20:08:06 +0200 Subject: [PATCH 3/3] added PSVersionTable tests for PSCompatibleVersions and updated requires test for version --- test/powershell/Host/PSVersionTable.Tests.ps1 | 16 ++++++ .../Language/Scripting/Requires.Tests.ps1 | 51 +++++++++++++++---- 2 files changed, 57 insertions(+), 10 deletions(-) diff --git a/test/powershell/Host/PSVersionTable.Tests.ps1 b/test/powershell/Host/PSVersionTable.Tests.ps1 index 573a0a8216e..8806d8ebf29 100644 --- a/test/powershell/Host/PSVersionTable.Tests.ps1 +++ b/test/powershell/Host/PSVersionTable.Tests.ps1 @@ -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 + } + } } diff --git a/test/powershell/Language/Scripting/Requires.Tests.ps1 b/test/powershell/Language/Scripting/Requires.Tests.ps1 index 4d068af2be5..03d44accb94 100644 --- a/test/powershell/Language/Scripting/Requires.Tests.ps1 +++ b/test/powershell/Language/Scripting/Requires.Tests.ps1 @@ -41,22 +41,53 @@ Describe "Requires tests" -Tags "CI" { BeforeAll { $currentVersion = $PSVersionTable.PSVersion - $files = "6.1", "6.2" | ForEach-Object { New-Item -Path (Join-Path $TestDrive "vers$_.ps1") -Value "#requires -version $_" } + $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" + } - $filesTestCase = @( - @{ Name = "Check for version 6.1" ; File = $files[0] } - @{ Name = "Check for version 6.2" ; File = $files[1] } - ) + $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 "" -TestCase $filesTestCase { - param( $Name, $File) + It "" -TestCase $filesSuccessTestCase { + param( + $Name, + $File, + $Version + ) - if ($currentVersion -notmatch '^7') { - Set-ItResult -Skipped -Because "Test not valid for current version - $currentVersion" + 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 + { . $File } | Should -Not -Throw + } + + It "" -TestCase $filesFailTestCase { + param( + $Name, + $File + ) + + { . $File } | Should -Throw -ExceptionType ([System.Management.Automation.ScriptRequiresException]) } } }