Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tab completion test for PowerShell #1629

Merged
merged 2 commits into from
Feb 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ install:
} else {
Write-Host "MSYS2 not required" -ForegroundColor Green
}
- pwsh: |
Install-Module Pester -Force

# Install rust, x86_64-pc-windows-msvc host
- appveyor-retry appveyor DownloadFile https://win.rustup.rs/ -FileName rustup-init.exe
Expand Down Expand Up @@ -81,6 +83,9 @@ test_script:
- if defined BUILD_MSI pushd src\rustup-win-installer && cargo build --release --target %TARGET% & popd
- if defined BUILD_MSI pushd src\rustup-win-installer\msi && powershell .\build.ps1 -Target %TARGET% & popd
- cargo fmt --all -- --check
- pwsh: |
$pesterOutputFile = 'src\rustup-win-installer\msi\PesterTestsResults.xml'
Invoke-Pester -OutputFormat NUnitXml -OutputFile $pesterOutputFile

notifications:
- provider: Webhook
Expand Down
21 changes: 21 additions & 0 deletions src/rustup-win-installer/msi/Completion.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
if (Get-Command -Name rustup -ErrorAction Stop) {
# Enable rustup tab completion
rustup completions powershell | Out-String | Invoke-Expression
}

function Get-Result([string]$Text, [int]$CursorPosition = $Text.Length, [hashtable]$Options) {
[System.Management.Automation.CommandCompletion]::CompleteInput($Text, $CursorPosition, $Options).CompletionMatches
}

Describe 'rustup flags and subcommands' {
$result = Get-Result 'rustup '

# Keep it simple because over-specify testing might be risky
$result.Count | Should -BeGreaterThan 10
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a "More than 10" type test.

$result.CompletionText | Should -Contain 'completions'
$result.CompletionText | Should -Contain 'install'
$result.CompletionText | Should -Contain 'uninstall'
$result.CompletionText | Should -Contain 'update'
$result.CompletionText | Should -Contain '--help'
$result.CompletionText | Should -Contain '--verbose'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should -Contain can verify elements of an array ignoring order.

}