-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Get '$PSVersionTable.PSVersion' from ProductVersion attribute #4863
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
7e0e6ad
c3bc0b8
16fe5da
04ef450
8c29037
38b9827
b8a83fa
0a15f55
ce1ed51
5ec4f94
b57f457
b85ca57
fbc35bd
9f93ebe
9f740fa
ad92e3c
f469c0e
2dbf568
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,27 @@ | ||
| Describe "PSVersionTable" -Tags "CI" { | ||
|
|
||
| BeforeAll { | ||
| $sma = Get-Item (Join-Path $PSHome "System.Management.Automation.dll") | ||
| $formattedVersion = $sma.VersionInfo.ProductVersion | ||
|
|
||
| $mainVersionPattern = "(\d+\.\d+\.\d+)(-.+)?" | ||
| $fullVersionPattern = "^v(\d+\.\d+\.\d+)-(.+)-(\d+)-g(.+)$" | ||
|
|
||
| $expectedPSVersion = ($formattedVersion -split " ")[0] | ||
| $expectedVersionPattern = "^$mainVersionPattern$" | ||
|
|
||
| if ($formattedVersion.Contains(" Commits: ")) | ||
| { | ||
| $rawGitCommitId = "v" + $formattedVersion.Replace(" Commits: ", "-").Replace(" SHA: ", "-g") | ||
| $expectedGitCommitIdPattern = $fullVersionPattern | ||
| $unexpectectGitCommitIdPattern = "qwerty" | ||
| } else { | ||
| $rawGitCommitId = "v" + ($formattedVersion -split " SHA: ")[0] | ||
| $expectedGitCommitIdPattern = "^v$mainVersionPattern$" | ||
| $unexpectectGitCommitIdPattern = $fullVersionPattern | ||
| } | ||
| } | ||
|
|
||
| It "Should have version table entries" { | ||
| $PSVersionTable.Count | Should Be 9 | ||
| } | ||
|
|
@@ -15,20 +38,31 @@ Describe "PSVersionTable" -Tags "CI" { | |
| $PSVersionTable.ContainsKey("OS") | Should Be True | ||
|
|
||
| } | ||
| It "GitCommitId property should not contain an error" { | ||
| $PSVersionTable.GitCommitId | Should not match "powershell.version" | ||
|
|
||
| It "PSVersion property" { | ||
| $PSVersionTable.PSVersion | Should BeOfType "System.Management.Automation.SemanticVersion" | ||
| $PSVersionTable.PSVersion | Should BeExactly $expectedPSVersion | ||
| $PSVersionTable.PSVersion | Should Match $expectedVersionPattern | ||
| $PSVersionTable.PSVersion.Major | Should Be 6 | ||
| } | ||
|
|
||
| It "GitCommitId property" { | ||
| $PSVersionTable.GitCommitId | Should BeOfType "System.String" | ||
| $PSVersionTable.GitCommitId | Should Match $expectedGitCommitIdPattern | ||
| $PSVersionTable.GitCommitId | Should Not Match $unexpectectGitCommitIdPattern | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We do two checks - 1. for string values (line below). 2. for regex patterns (this line).
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see the point. It's to guarantee that the reconstructed |
||
| $PSVersionTable.GitCommitId | Should BeExactly $rawGitCommitId | ||
| } | ||
|
|
||
| It "Should have the correct platform info" { | ||
| $platform = [String][System.Environment]::OSVersion.Platform | ||
| [String]$PSVersionTable["Platform"] | Should Be $platform | ||
| [String]$PSVersionTable["Platform"] | Should Be $platform | ||
| } | ||
|
|
||
| It "Should have the correct OS info" { | ||
| if ($IsCoreCLR) | ||
| { | ||
| $OSDescription = [String][System.Runtime.InteropServices.RuntimeInformation]::OSDescription | ||
| [String]$PSVersionTable["OS"] | Should Be $OSDescription | ||
| [String]$PSVersionTable["OS"] | Should Be $OSDescription | ||
| } | ||
| else | ||
| { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to remove
powershell.versionfrom.gitignoreas well.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.