Skip to content

Commit

Permalink
Make UseAbbreviationExpansion and TempDrive official features (Po…
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveL-MSFT authored and daxian-dbw committed Jun 13, 2019
1 parent e1793b9 commit 981c990
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 93 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,8 @@ List<CompletionResult> ExecuteGetCommandCommand(bool useModulePrefix)
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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,6 @@ static ExperimentalFeature()
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"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,6 @@ public PSTypeName[] ParameterType
/// This means it matches cmdlets where the uppercase characters for the noun match
/// the given characters. i.e., g-sgc would match Get-SomeGreatCmdlet.
/// </summary>
[Experimental("PSUseAbbreviationExpansion", ExperimentAction.Show)]
[Parameter(ValueFromPipelineByPropertyName = true, ParameterSetName = "AllCommandSet")]
public SwitchParameter UseAbbreviationExpansion { get; set; }

Expand Down
21 changes: 9 additions & 12 deletions src/System.Management.Automation/namespaces/FileSystemProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1088,18 +1088,15 @@ protected override Collection<PSDriveInfo> InitializeDefaultDrives()
}
}

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;
}
Expand Down
37 changes: 10 additions & 27 deletions test/powershell/Host/TabCompletion/TabCompletion.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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 }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -60,20 +49,23 @@ Describe "Get-Command Feature tests" -Tag Feature {
) {
param($name, $expected, $module)

$command = "Get-Command $name -UseAbbreviationExpansion"
$params = @{
UseAbbreviationExpansion = $true;
Name = $name;
}

if ($module) {
$command += " -Module $module"
$params += @{ Module = $module }
}

$results = pwsh -outputformat xml -settingsfile $configFilePath -command "$command"
$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"
Expand All @@ -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
}
}
}

0 comments on commit 981c990

Please sign in to comment.