diff --git a/test/powershell/Host/TabCompletion/TabCompletion.Tests.ps1 b/test/powershell/Host/TabCompletion/TabCompletion.Tests.ps1 index 2c22e93f2f..f48a66acf9 100644 --- a/test/powershell/Host/TabCompletion/TabCompletion.Tests.ps1 +++ b/test/powershell/Host/TabCompletion/TabCompletion.Tests.ps1 @@ -26,13 +26,13 @@ Describe "TabCompletion" -Tags CI { } It 'Should complete abbreviated cmdlet' { - $res = pwsh -settingsfile $configFilePath -c "(TabExpansion2 -inputScript 'i-psdf' -cursorColumn 'pschr'.Length).CompletionMatches.CompletionText" + $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 -settingsfile $configFilePath -c "(TabExpansion2 -inputScript 'pschrl' -cursorColumn 'pschr'.Length).CompletionMatches.CompletionText" + $res = pwsh -noprofile -settingsfile $configFilePath -c "(TabExpansion2 -inputScript 'pschrl' -cursorColumn 'pschr'.Length).CompletionMatches.CompletionText" $res.Count | Should -BeGreaterOrEqual 1 $res | Should -BeExactly 'PSConsoleHostReadLine' } @@ -245,6 +245,51 @@ Describe "TabCompletion" -Tags CI { $completionText -join ' '| Should -BeExactly 'blg csv tsv' } + Context "Script name completion" { + BeforeAll { + setup -f 'install-powershell.ps1' -content "" + setup -f 'remove-powershell.ps1' -content "" + + $scriptWithWildcardCases = @( + @{ + command = '.\install-*.ps1' + expectedCommand = Join-Path -Path '.' -ChildPath 'install-powershell.ps1' + name = "'$(Join-Path -Path '.' -ChildPath 'install-powershell.ps1')'" + } + @{ + command = (Join-Path ${TestDrive} -ChildPath 'install-*.ps1') + expectedCommand = (Join-Path ${TestDrive} -ChildPath 'install-powershell.ps1') + name = "'$(Join-Path -Path '.' -ChildPath 'install-powershell.ps1')' by fully qualified path" + } + @{ + command = '.\?emove-powershell.ps1' + expectedCommand = Join-Path -Path '.' -ChildPath 'remove-powershell.ps1' + name = "'$(Join-Path -Path '.' -ChildPath '?emove-powershell.ps1')'" + } + @{ + # [] cause the parser to create a new token. + # So, the command must be quoted to tab complete. + command = "'.\[ra]emove-powershell.ps1'" + expectedCommand = "'$(Join-Path -Path '.' -ChildPath 'remove-powershell.ps1')'" + name = "'$(Join-Path -Path '.' -ChildPath '[ra]emove-powershell.ps1')'" + } + ) + + Push-Location ${TestDrive}\ + } + + AfterAll { + Pop-Location + } + + it "Input should successfully complete" -TestCases $scriptWithWildcardCases { + param($command, $expectedCommand) + $res = TabExpansion2 -inputScript $command -cursorColumn $command.Length + $res.CompletionMatches.Count | Should -BeGreaterThan 0 + $res.CompletionMatches[0].CompletionText | Should -BeExactly $expectedCommand + } + } + Context "File name completion" { BeforeAll { $tempDir = Join-Path -Path $TestDrive -ChildPath "baseDir" diff --git a/test/powershell/engine/Basic/CommandDiscovery.Tests.ps1 b/test/powershell/engine/Basic/CommandDiscovery.Tests.ps1 index 408e6d81e9..4b9be7a736 100644 --- a/test/powershell/engine/Basic/CommandDiscovery.Tests.ps1 +++ b/test/powershell/engine/Basic/CommandDiscovery.Tests.ps1 @@ -84,4 +84,33 @@ Describe "Command Discovery tests" -Tags "CI" { It "Get- is prepended to commands" { (& 'location').Path | Should -Be (get-location).Path } + + Context "Get-Command should use globbing for scripts" { + BeforeAll { + $firstResult = '[first script]' + $secondResult = 'alt script' + setup -f '[test1].ps1' -content "'$firstResult'" + setup -f '1.ps1' -content "'$secondResult'" + + $gcmWithWildcardCases = @( + @{command = '.\?[tb]est1?.ps1'; expectedCommand = '[test1].ps1'; expectedCommandCount =1; name = '''.\?[tb]est1?.ps1'''} + @{command = (Join-Path ${TestDrive} -ChildPath '?[tb]est1?.ps1'); expectedCommand = '[test1].ps1'; expectedCommandCount =1 ; name = '''.\?[tb]est1?.ps1'' by fully qualified path'} + @{command = '.\[test1].ps1'; expectedCommand = '1.ps1'; expectedCommandCount =1; name = '''.\[test1].ps1'''} + @{command = (Join-Path ${TestDrive} -ChildPath '[test1].ps1'); expectedCommand = '1.ps1'; expectedCommandCount =1 ; name = '''.\[test1].ps1'' by fully qualified path'} + ) + + Push-Location ${TestDrive}\ + } + + AfterAll { + Pop-Location + } + + It "Get-Command should return command named ''" -TestCases $gcmWithWildcardCases { + param($command, $expectedCommand, $expectedCommandCount) + $commands = Get-Command -Name $command + $commands.Count | Should -Be $expectedCommandCount + $commands.Name | Should -BeExactly $expectedCommand + } + } }