From 9051ca1fbc4754cc66d0cbb3be4037b0f58f13e6 Mon Sep 17 00:00:00 2001 From: Chunqing Chen Date: Mon, 1 May 2017 21:04:49 -0700 Subject: [PATCH] PSVersionTable should have entry for OS and Platform (#3654) --- .../engine/PSVersionInfo.cs | 5 ++- test/powershell/Host/PSVersionTable.Tests.ps1 | 44 ++++++++++++++----- 2 files changed, 36 insertions(+), 13 deletions(-) diff --git a/src/System.Management.Automation/engine/PSVersionInfo.cs b/src/System.Management.Automation/engine/PSVersionInfo.cs index 3eca5b296..daf8e8649 100644 --- a/src/System.Management.Automation/engine/PSVersionInfo.cs +++ b/src/System.Management.Automation/engine/PSVersionInfo.cs @@ -64,10 +64,13 @@ namespace System.Management.Automation s_psVersionTable[PSVersionInfo.SerializationVersionName] = new Version(InternalSerializer.DefaultVersion); s_psVersionTable[PSVersionInfo.PSRemotingProtocolVersionName] = RemotingConstants.ProtocolVersion; s_psVersionTable[PSVersionInfo.WSManStackVersionName] = GetWSManStackVersion(); + s_psVersionTable["Platform"] = Environment.OSVersion.Platform.ToString(); #if CORECLR + s_psVersionTable["OS"] = Runtime.InteropServices.RuntimeInformation.OSDescription.ToString(); s_psVersionTable["CLRVersion"] = null; #else s_psVersionTable["CLRVersion"] = Environment.Version; + s_psVersionTable["OS"] = Environment.OSVersion.ToString(); #endif } @@ -800,4 +803,4 @@ namespace System.Management.Automation } } } -} +} \ No newline at end of file diff --git a/test/powershell/Host/PSVersionTable.Tests.ps1 b/test/powershell/Host/PSVersionTable.Tests.ps1 index 7d2d5b5bb..78e3eb005 100644 --- a/test/powershell/Host/PSVersionTable.Tests.ps1 +++ b/test/powershell/Host/PSVersionTable.Tests.ps1 @@ -1,25 +1,45 @@ Describe "PSVersionTable" -Tags "CI" { It "Should have version table entries" { - $PSVersionTable.Count | Should Be 9 + $PSVersionTable.Count | Should Be 11 } It "Should have the right version table entries" { - $PSVersionTable.ContainsKey("PSVersion") | Should Be True - $PSVersionTable.ContainsKey("PSEdition") | Should Be True - $PSVersionTable.ContainsKey("WSManStackVersion") | Should Be True - $PSVersionTable.ContainsKey("SerializationVersion") | Should Be True - $PSVersionTable.ContainsKey("CLRVersion") | Should Be True - $PSVersionTable.ContainsKey("BuildVersion") | Should Be True - $PSVersionTable.ContainsKey("PSCompatibleVersions") | Should Be True - $PSVersionTable.ContainsKey("PSRemotingProtocolVersion") | Should Be True - $PSVersionTable.ContainsKey("GitCommitId") | Should Be True + $PSVersionTable.ContainsKey("PSVersion") | Should Be True + $PSVersionTable.ContainsKey("PSEdition") | Should Be True + $PSVersionTable.ContainsKey("WSManStackVersion") | Should Be True + $PSVersionTable.ContainsKey("SerializationVersion") | Should Be True + $PSVersionTable.ContainsKey("CLRVersion") | Should Be True + $PSVersionTable.ContainsKey("BuildVersion") | Should Be True + $PSVersionTable.ContainsKey("PSCompatibleVersions") | Should Be True + $PSVersionTable.ContainsKey("PSRemotingProtocolVersion") | Should Be True + $PSVersionTable.ContainsKey("GitCommitId") | Should Be True + $PSVersionTable.ContainsKey("Platform") | Should Be True + $PSVersionTable.ContainsKey("OS") | Should Be True } It "GitCommitId property should not contain an error" { - $PSVersionTable.GitCommitId | Should not match "powershell.version" + $PSVersionTable.GitCommitId | Should not match "powershell.version" } It "Should have the correct edition" -Skip:(!$IsCoreCLR) { - $PSVersionTable["PSEdition"] | Should Be "Core" + $PSVersionTable["PSEdition"] | Should Be "Core" + } + + It "Should have the correct platform info" { + $platform = [String][System.Environment]::OSVersion.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 + } + else + { + $OSDescription = [String][System.Environment]::OSVersion + [String]$PSVersionTable["OS"] | Should Be $OSDescription + } } }