From 981c990d747ae97f56a6c7474e5d2ef04bf237c5 Mon Sep 17 00:00:00 2001 From: Steve Lee Date: Thu, 13 Jun 2019 13:05:37 -0700 Subject: [PATCH] Make `UseAbbreviationExpansion` and `TempDrive` official features (#9872) --- .../CommandCompletion/CompletionCompleters.cs | 8 +--- .../ExperimentalFeature.cs | 6 --- .../engine/GetCommandCommand.cs | 1 - .../namespaces/FileSystemProvider.cs | 21 ++++----- .../TabCompletion/TabCompletion.Tests.ps1 | 37 ++++----------- .../Get-PSDrive.Tests.ps1 | 22 ++------- .../Get-Command.Tests.ps1 | 47 +++++++++---------- 7 files changed, 47 insertions(+), 95 deletions(-) diff --git a/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs b/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs index 0bf1786475..a89994152f 100644 --- a/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs +++ b/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs @@ -173,12 +173,8 @@ namespace System.Management.Automation powershell .AddCommandWithPreferenceSetting("Get-Command", typeof(GetCommandCommand)) .AddParameter("All") - .AddParameter("Name", commandName); - - if (ExperimentalFeature.IsEnabled("PSUseAbbreviationExpansion")) - { - powershell.AddParameter("UseAbbreviationExpansion"); - } + .AddParameter("Name", commandName) + .AddParameter("UseAbbreviationExpansion"); if (moduleName != null) { diff --git a/src/System.Management.Automation/engine/ExperimentalFeature/ExperimentalFeature.cs b/src/System.Management.Automation/engine/ExperimentalFeature/ExperimentalFeature.cs index 5c47fe73f3..57dae18d01 100644 --- a/src/System.Management.Automation/engine/ExperimentalFeature/ExperimentalFeature.cs +++ b/src/System.Management.Automation/engine/ExperimentalFeature/ExperimentalFeature.cs @@ -105,12 +105,6 @@ namespace System.Management.Automation new ExperimentalFeature( name: "PSImplicitRemotingBatching", description: "Batch implicit remoting proxy commands to improve performance"), - new ExperimentalFeature( - name: "PSUseAbbreviationExpansion", - description: "Allow tab completion of cmdlets and functions by abbreviation"), - new ExperimentalFeature( - name: "PSTempDrive", - description: "Create TEMP: PS Drive mapped to user's temporary directory path"), new ExperimentalFeature( name: "PSCommandNotFoundSuggestion", description: "Recommend potential commands based on fuzzy search on a CommandNotFoundException"), diff --git a/src/System.Management.Automation/engine/GetCommandCommand.cs b/src/System.Management.Automation/engine/GetCommandCommand.cs index 5269d5c2de..8414986a25 100644 --- a/src/System.Management.Automation/engine/GetCommandCommand.cs +++ b/src/System.Management.Automation/engine/GetCommandCommand.cs @@ -364,7 +364,6 @@ namespace Microsoft.PowerShell.Commands /// This means it matches cmdlets where the uppercase characters for the noun match /// the given characters. i.e., g-sgc would match Get-SomeGreatCmdlet. /// - [Experimental("PSUseAbbreviationExpansion", ExperimentAction.Show)] [Parameter(ValueFromPipelineByPropertyName = true, ParameterSetName = "AllCommandSet")] public SwitchParameter UseAbbreviationExpansion { get; set; } diff --git a/src/System.Management.Automation/namespaces/FileSystemProvider.cs b/src/System.Management.Automation/namespaces/FileSystemProvider.cs index 7cf78ade9a..3fcc23b040 100644 --- a/src/System.Management.Automation/namespaces/FileSystemProvider.cs +++ b/src/System.Management.Automation/namespaces/FileSystemProvider.cs @@ -1088,18 +1088,15 @@ namespace Microsoft.PowerShell.Commands } } - if (ExperimentalFeature.IsEnabled("PSTempDrive")) - { - PSDriveInfo newPSDriveInfo = - new PSDriveInfo( - DriveNames.TempDrive, - ProviderInfo, - Path.GetTempPath(), - SessionStateStrings.TempDriveDescription, - credential: null, - displayRoot: null); - results.Add(newPSDriveInfo); - } + results.Add( + new PSDriveInfo( + DriveNames.TempDrive, + ProviderInfo, + Path.GetTempPath(), + SessionStateStrings.TempDriveDescription, + credential: null, + displayRoot: null) + ); return results; } diff --git a/test/powershell/Host/TabCompletion/TabCompletion.Tests.ps1 b/test/powershell/Host/TabCompletion/TabCompletion.Tests.ps1 index 8a30a9b00c..2d85943352 100644 --- a/test/powershell/Host/TabCompletion/TabCompletion.Tests.ps1 +++ b/test/powershell/Host/TabCompletion/TabCompletion.Tests.ps1 @@ -10,33 +10,16 @@ Describe "TabCompletion" -Tags CI { $res.CompletionMatches[0].CompletionText | Should -BeExactly 'Get-Command' } - Context "ExperimentalFeatures" { - - BeforeAll { - $configFilePath = Join-Path $testdrive "useabbreviationexpansion.json" - - @" - { - "ExperimentalFeatures": [ - "PSUseAbbreviationExpansion" - ] - } -"@ > $configFilePath - - } - - It 'Should complete abbreviated cmdlet' { - $res = pwsh -noprofile -settingsfile $configFilePath -c "(TabExpansion2 -inputScript 'i-psdf' -cursorColumn 'pschr'.Length).CompletionMatches.CompletionText" - $res | Should -HaveCount 1 - $res | Should -BeExactly 'Import-PowerShellDataFile' - } - - It 'Should complete abbreviated function' { - $res = pwsh -noprofile -settingsfile $configFilePath -c "(TabExpansion2 -inputScript 'pschrl' -cursorColumn 'pschr'.Length).CompletionMatches.CompletionText" - $res.Count | Should -BeGreaterOrEqual 1 - $res | Should -BeExactly 'PSConsoleHostReadLine' - } + It 'Should complete abbreviated cmdlet' { + $res = (TabExpansion2 -inputScript 'i-psdf' -cursorColumn 'pschr'.Length).CompletionMatches.CompletionText + $res | Should -HaveCount 1 + $res | Should -BeExactly 'Import-PowerShellDataFile' + } + It 'Should complete abbreviated function' { + $res = (TabExpansion2 -inputScript 'pschrl' -cursorColumn 'pschr'.Length).CompletionMatches.CompletionText + $res.Count | Should -BeGreaterOrEqual 1 + $res | Should -BeExactly 'PSConsoleHostReadLine' } It 'Should complete native exe' -Skip:(!$IsWindows) { @@ -483,7 +466,7 @@ Describe "TabCompletion" -Tags CI { @{ inputStr = '$host.UI.WriteD'; expected = 'WriteDebugLine('; setup = $null } @{ inputStr = '$MaximumHistoryCount.'; expected = 'CompareTo('; setup = $null } @{ inputStr = '$A=[datetime]::now;$A.'; expected = 'Date'; setup = $null } - @{ inputStr = 'try { 1/0 } catch {};$error[0].'; expected = 'CategoryInfo'; setup = $null } + @{ inputStr = '$e=$null;try { 1/0 } catch {$e=$_};$e.'; expected = 'CategoryInfo'; setup = $null } @{ inputStr = '$x= gps pwsh;$x.*pm'; expected = 'NPM'; setup = $null } @{ inputStr = 'function Get-ScrumData {}; Get-Scrum'; expected = 'Get-ScrumData'; setup = $null } @{ inputStr = 'function write-output {param($abcd) $abcd};Write-Output -a'; expected = '-abcd'; setup = $null } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Management/Get-PSDrive.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Management/Get-PSDrive.Tests.ps1 index 2d6a109bd0..37784cf421 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Management/Get-PSDrive.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Management/Get-PSDrive.Tests.ps1 @@ -58,26 +58,10 @@ Describe "Get-PSDrive" -Tags "CI" { } } -Describe "Experimental Feature Temp: drive" -Tag Feature { - BeforeAll { - $configFilePath = Join-Path $testdrive "experimentalfeature.json" - - @" - { - "ExperimentalFeatures": [ - "PSTempDrive" - ] - } -"@ > $configFilePath - } - - It "TEMP: drive exists if experimental feature is enabled" { - $res = pwsh -outputformat xml -settingsfile $configFilePath -command "Get-PSDrive Temp" +Describe "Temp: drive" -Tag Feature { + It "TEMP: drive exists" { + $res = Get-PSDrive Temp $res.Name | Should -BeExactly "Temp" $res.Root | Should -BeExactly ([System.IO.Path]::GetTempPath()) } - - It "TEMP: drive does not exist if experimental feature is not enabled" { - { Get-PSDrive Temp -ErrorAction Stop } | Should -Throw -ErrorId "GetLocationNoMatchingDrive,Microsoft.PowerShell.Commands.GetPSDriveCommand" - } } 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 fe46bc3b53..9847d40b8a 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Command.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Command.Tests.ps1 @@ -32,21 +32,10 @@ Describe "Get-Command Feature tests" -Tag Feature { Set-Content -Path (Join-Path $testModulesPath "test1/test1.psm1") -Value "function Import-FooZedZed {}" Set-Content -Path (Join-Path $testModulesPath "test2/test2.psm1") -Value "function Invoke-FooZedZed {}" - - $configFilePath = Join-Path $testdrive "useabbreviationexpansion.json" - - @" - { - "ExperimentalFeatures": [ - "PSUseAbbreviationExpansion" - ] - } -"@ > $configFilePath - } It "Can return multiple results relying on auto module loading" { - $results = pwsh -outputformat xml -settingsfile $configFilePath -command "`$env:PSModulePath += '$testPSModulePath'; Get-Command i-fzz -UseAbbreviationExpansion" + $results = pwsh -outputformat xml -command "`$env:PSModulePath += '$testPSModulePath'; Get-Command i-fzz -UseAbbreviationExpansion" $results | Should -HaveCount 2 $results.Name | Should -Contain "Invoke-FooZedZed" $results.Name | Should -Contain "Import-FooZedZed" @@ -60,20 +49,23 @@ Describe "Get-Command Feature tests" -Tag Feature { ) { param($name, $expected, $module) - $command = "Get-Command $name -UseAbbreviationExpansion" - - if ($module) { - $command += " -Module $module" + $params = @{ + UseAbbreviationExpansion = $true; + Name = $name; } - $results = pwsh -outputformat xml -settingsfile $configFilePath -command "$command" + if ($module) { + $params += @{ Module = $module } + } + + $results = Get-Command @params $results | Should -HaveCount 1 $results.Name | Should -BeExactly $expected } It "Can return multiple results for cmdlets matching abbreviation" { # use mixed casing to validate case insensitivity - $results = pwsh -outputformat xml -settingsfile $configFilePath -command "Get-Command i-C -UseAbbreviationExpansion" + $results = Get-Command i-C -UseAbbreviationExpansion $results.Name | Should -Contain "Invoke-Command" $results.Name | Should -Contain "Import-Clixml" $results.Name | Should -Contain "Import-Csv" @@ -89,18 +81,25 @@ Describe "Get-Command Feature tests" -Tag Feature { function Get-FB { "fb" } "@ > $modulePath - $results = pwsh -outputformat xml -settingsfile $configFilePath -command "Import-Module $manifestPath; Get-Command g-fb -UseAbbreviationExpansion" - $results | Should -HaveCount 2 - $results[0].Name | Should -BeExactly "Get-FB" - $results[1].Name | Should -BeExactly "Get-FooBar" + try { + Import-Module $manifestPath + $results = Get-Command g-fb -UseAbbreviationExpansion + $results | Should -HaveCount 2 + $results[0].Name | Should -BeIn "Get-FB","Get-FooBar" + $results[1].Name | Should -BeIn "Get-FB","Get-FooBar" + $results[0].Name | Should -Not -Be $results[1].Name + } + finally { + Remove-Module test + } } It "Non-existing cmdlets returns non-terminating error" { - pwsh -settingsfile $configFilePath -command 'try { get-command g-adf -ea stop } catch { $_.fullyqualifiederrorid }' | Should -BeExactly "CommandNotFoundException,Microsoft.PowerShell.Commands.GetCommandCommand" + { get-command g-adf -ErrorAction Stop } | Should -Throw -ErrorId "CommandNotFoundException,Microsoft.PowerShell.Commands.GetCommandCommand" } It "No results if wildcard is used" { - pwsh -settingsfile $configFilePath -command Get-Command i-psd* -UseAbbreviationExpansion | Should -BeNullOrEmpty + Get-Command i-psd* -UseAbbreviationExpansion | Should -BeNullOrEmpty } } }