diff --git a/azure-pipelines/end-to-end-tests-dir/autocomplete-posh-vcpkg.Test.ps1 b/azure-pipelines/end-to-end-tests-dir/autocomplete-posh-vcpkg.Test.ps1 new file mode 100644 index 0000000000..e915e705c0 --- /dev/null +++ b/azure-pipelines/end-to-end-tests-dir/autocomplete-posh-vcpkg.Test.ps1 @@ -0,0 +1,180 @@ +BeforeAll { + Import-Module $PSScriptRoot/../../scripts/posh-vcpkg.psd1 +} + +Describe 'Module posh-vcpkg tests' { + + BeforeAll { + + function Complete-InputCaret { + [OutputType([string[]])] + param ( + [Parameter(Mandatory, Position = 0, ValueFromPipeline)] + [string]$caretCursorCommand + ) + $positionMatches = [regex]::Matches($caretCursorCommand, '\^') + if ($positionMatches.Count -ne 1) { + throw 'Invalid caret cursor command, please indicate by only one ^ character' + } + $command = [string]$caretCursorCommand.Replace('^', '') + $cursorPosition = [int]$positionMatches[0].Index + $result = [System.Management.Automation.CommandCompletion]::CompleteInput($command, $cursorPosition, $null) + # Write-Host ( $result.CompletionMatches | Select-Object -ExpandProperty CompletionText) + return $result.CompletionMatches | Select-Object -ExpandProperty CompletionText + } + + } + + Context 'Internal function tests' { + + It 'Complete-InputCaret 1 caret string should success' { + 'aaaa^' | Complete-InputCaret | Should -BeNullOrEmpty + } + + It 'Complete-InputCaret 0 caret string should throw' { + { 'aaaa' | Complete-InputCaret } | Should -Throw + } + + It 'Complete-InputCaret 2 caret string should throw' { + { 'aaaa^^' | Complete-InputCaret } | Should -Throw + } + + It 'Complete-InputCaret self should success' { + 'Complete-InputCaret^' | Complete-InputCaret | Should -Contain 'Complete-InputCaret' + } + + } + + Context 'Complete command name tests' { + + It 'Should complete command list with blank space [vcpkg ^] - ' -ForEach ( + @( + , 'help' + , 'install' + , 'list' + , 'remove' + , 'version' + ) | ForEach-Object { @{Expected = $_ } } + ) { + 'vcpkg ^' | Complete-InputCaret | Should -Contain $expected + } + + } + + + + # Context 'Complete command name tests' { + + # It -Skip 'Should complete command list with blank space []' -TestCases ( + # @{ caretCmd = 'vcpkg ^' ; expectedContain = 'version'; comment = 'without word' }, + # @{ caretCmd = 'vcpkg ver^' ; expectedContain = 'version'; comment = 'with word' }, + # @{ caretCmd = 'vcpkg.exe ver^' ; expectedContain = 'version'; comment = 'with native exe' }, + # @{ caretCmd = './vcpkg ver^' ; expectedContain = 'version'; comment = 'with dot slash' }, + # @{ caretCmd = '.\vcpkg ver^' ; expectedContain = 'version'; comment = 'with dot backslash' } + # ) { + # param($caretCmd, $expectedContain, $comment) + # $caretCmd | Complete-InputCaret | Should -Contain $expectedContain + # } + + # It -Skip 'Should complete command word [] with [] with ' -TestCases ( + # @{ caretCmd = 'vcpkg ^' ; expectedContain = 'version'; comment = 'without word' }, + # @{ caretCmd = 'vcpkg ver^' ; expectedContain = 'version'; comment = 'with word' }, + # @{ caretCmd = 'vcpkg.exe ver^' ; expectedContain = 'version'; comment = 'with native exe' }, + # @{ caretCmd = './vcpkg ver^' ; expectedContain = 'version'; comment = 'with dot slash' }, + # @{ caretCmd = '.\vcpkg ver^' ; expectedContain = 'version'; comment = 'with dot backslash' } + # ) { + # param($caretCmd, $expectedContain, $comment) + # $caretCmd | Complete-InputCaret | Should -Contain $expectedContain + # } + + # } + + # Context -Skip 'Complete command spaces tests' { + + # It 'Should complete command []' -TestCases ( + # @{ comment = 'spaces without argument'; caretCmd = 'vcpkg ^'; expectedContain = 'version' }, + # @{ comment = 'before remaining'; caretCmd = 'vcpkg ver^'; expectedContain = 'version' }, + # # @{ comment = 'with trailing spaces'; caretCmd = 'vcpkg ver ^'; expectedContain = 'version' }, + # @{ comment = 'with leading spaces'; caretCmd = ' vcpkg ver^'; expectedContain = 'version' } + # ) { + # param($caretCmd, $expectedContain, $comment) + # $caretCmd | Complete-InputCaret | Should -Contain $expectedContain + # } + + # It 'Should complete command with trailing spaces [vcpkg ver ^]' -Skip { + # 'vcpkg ver ^' | Complete-InputCaret | Should -Contain 'version' + # } + + # } + + # Context -Skip 'Complete command quotation tests' { + + # It "Should complete command with quoted word [vcpkg 'ver'^]" { + # "vcpkg 'ver'^" | Complete-InputCaret | Should -Contain 'version' + # } + + # It "Should complete command with quoted space [vcpkg ' '^]" { + # "vcpkg 'ver'^" | Complete-InputCaret | Should -Contain 'version' + # } + + # It "Should complete command with quoted word [vcpkg 'version'^]" { + # "vcpkg 'ver'^" | Complete-InputCaret | Should -Contain 'version' + # } + + # } + + # Context -Skip 'Complete command intermediate tests' { + + # It 'Should complete command []' -TestCases ( + # @{ comment = 'end of word'; caretCmd = 'vcpkg version^'; expectedContain = 'version' }, + # @{ comment = 'middle of word'; caretCmd = 'vcpkg ver^sion'; expectedContain = 'version' }, + # @{ comment = 'front of word'; caretCmd = 'vcpkg ^version'; expectedContain = 'version' } + # ) { + # param($caretCmd, $expectedContain, $comment) + # $caretCmd | Complete-InputCaret | Should -Contain $expectedContain + # } + + # } + + # Context -Skip 'Complete subcommand tests' { + + # It 'Should complete subcommand [] from []' -TestCases ( + # @{ caretCmd = 'vcpkg depend^'; expected = 'depend-info' }, + # @{ caretCmd = 'vcpkg inst^'; expected = 'install' }, + # @{ caretCmd = 'vcpkg int^'; expected = 'integrate' }, + # @{ caretCmd = 'vcpkg rem^'; expected = 'remove' } + # ) { + # param($caretCmd, $expected) + # @($caretCmd | Complete-InputCaret)[0] | Should -BeExactly $expected + # } + + # It 'Should complete subcommand two-level [powershell] from [vcpkg integrate power^]' -Skip { + # 'vcpkg integrate power^' | Complete-InputCaret | Should -Contain 'powershell' + # } + + # } + + # Context -Skip 'Complete subcommand argument and options tests' { + + # It 'Should complete argument [] from []' -TestCases ( + # @{ caretCmd = 'vcpkg install vcpkg-cmake^'; expectedContain = 'vcpkg-cmake-get-vars' }, + # @{ caretCmd = 'vcpkg install vcpkg-cmake --^'; expectedContain = '--dry-run' } + # ) { + # param($caretCmd, $expected) + # $caretCmd | Complete-InputCaret | Should -Contain $expectedContain + # } + + # } + + # Context -Skip 'Complete complex tests' { + + # It 'Should complete complex line [] from []' -TestCases ( + # @{ caretCmd = 'echo powershell | % { vcpkg ver^ $_ }; echo $?'; expectedContain = 'version' } + # ) { + # param($caretCmd, $expected) + # $caretCmd | Complete-InputCaret | Should -Contain $expectedContain + # } + + # } + +} diff --git a/azure-pipelines/end-to-end-tests-dir/autocomplete-posh-z.Spec.ps1 b/azure-pipelines/end-to-end-tests-dir/autocomplete-posh-z.Spec.ps1 new file mode 100644 index 0000000000..7700a43a67 --- /dev/null +++ b/azure-pipelines/end-to-end-tests-dir/autocomplete-posh-z.Spec.ps1 @@ -0,0 +1,6 @@ + +Write-Host "It's spec." + +if ($IsLinux -or $IsWindows) { + throw 'It is an error for end-to-end-tests.ps1 on Linux or Windows.' +}