From 3ceb1c17ef31b80ba296f7d8fa0b9eeff1cea33d Mon Sep 17 00:00:00 2001 From: Steve Lee Date: Sat, 20 Oct 2018 03:45:03 +0800 Subject: [PATCH] Fix logic to not rely on build number to determine whether to output formatdata (#8063) --- .../FormatAndOutput/common/GetFormatDataCommand.cs | 2 +- .../Get-FormatData.Tests.ps1 | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/FormatAndOutput/common/GetFormatDataCommand.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/FormatAndOutput/common/GetFormatDataCommand.cs index 3dcea5d691..d46c9e20d2 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/FormatAndOutput/common/GetFormatDataCommand.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/FormatAndOutput/common/GetFormatDataCommand.cs @@ -97,7 +97,7 @@ namespace Microsoft.PowerShell.Commands { bool writeOldWay = PowerShellVersion == null || PowerShellVersion.Major < 5 || - PowerShellVersion.Build < 11086; + (PowerShellVersion.Major == 5 && PowerShellVersion.Minor < 1); TypeInfoDataBase db = this.Context.FormatDBManager.Database; diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-FormatData.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-FormatData.Tests.ps1 index 9db38ee99e..45562a6c7c 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-FormatData.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-FormatData.Tests.ps1 @@ -9,4 +9,16 @@ Describe "Get-FormatData" -Tags "CI" { ,$result | Should -BeOfType "System.Object[]" } } + + It "Can get format data requiring '-PowerShellVersion 5.1'" { + $format = Get-FormatData System.IO.FileInfo -PowerShellVersion 5.1 + $format.TypeNames | Should -HaveCount 2 + $format.TypeNames[0] | Should -BeExactly "System.IO.DirectoryInfo" + $format.TypeNames[1] | Should -BeExactly "System.IO.FileInfo" + $format.FormatViewDefinition | Should -HaveCount 3 + } + + It "Should return nothing for format data requiring '-PowerShellVersion 5.1' and not provided" { + Get-FormatData System.IO.FileInfo | Should -BeNullOrEmpty + } }