From c3cb6df809ce66d3b1c1255f77b0a365fb05df87 Mon Sep 17 00:00:00 2001 From: Steve Lee Date: Mon, 14 Jan 2019 14:28:15 -0800 Subject: [PATCH] Update 'CommandNotFound' fuzzy suggestion to only return unique results (#8640) --- .../engine/hostifaces/HostUtilities.cs | 2 +- .../Get-Command.Tests.ps1 | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/System.Management.Automation/engine/hostifaces/HostUtilities.cs b/src/System.Management.Automation/engine/hostifaces/HostUtilities.cs index 40cf76739..cd660537b 100644 --- a/src/System.Management.Automation/engine/hostifaces/HostUtilities.cs +++ b/src/System.Management.Automation/engine/hostifaces/HostUtilities.cs @@ -68,7 +68,7 @@ namespace System.Management.Automation [System.Diagnostics.DebuggerHidden()] param([string] $formatString) - $formatString -f [string]::Join(', ', (Get-Command $lastError.TargetObject -UseFuzzyMatch | Select-Object -First 10 -ExpandProperty Name)) + $formatString -f [string]::Join(', ', (Get-Command $lastError.TargetObject -UseFuzzyMatch | Select-Object -First 10 -Unique -ExpandProperty Name)) "; private static ArrayList s_suggestions = new ArrayList( diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Command.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Command.Tests.ps1 index 3f52bb241..d98f71081 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Command.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Command.Tests.ps1 @@ -1,7 +1,7 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. -Describe "Get-Command CI tests" -Tag Feature { +Describe "Get-Command Feature tests" -Tag Feature { Context "-UseFuzzyMatch tests" { It "Should match cmdlets" { $cmds = Get-Command get-hlp -UseFuzzyMatch @@ -10,14 +10,15 @@ Describe "Get-Command CI tests" -Tag Feature { } It "Should match native commands" { - $ping = "ping" + $input = "pwsg" + $expectedcmd = "pwsh" if ($IsWindows) { - $ping = "PING.EXE" + $expectedcmd = "pwsh.EXE" } - $cmds = Get-Command pinh -UseFuzzyMatch + $cmds = Get-Command $input -UseFuzzyMatch $cmds.Count | Should -BeGreaterThan 0 - $cmds.Name | Should -Contain $ping + $cmds.Name | Should -Contain $expectedcmd } }