-
Notifications
You must be signed in to change notification settings - Fork 46
Add argument completer for Build.ps1 -Tasks to enable tab-expansion of task names
#569
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
Open
raandree
wants to merge
6
commits into
gaelcolas:main
Choose a base branch
from
raandree:feature/#568
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b6604c7
Update next-version in GitVersion.yml to 0.90.0
raandree de8c21b
Merge branch 'gaelcolas:main' into main
raandree 5b73099
Add tab-completion for -Tasks parameter in Build.ps1 and correspondin…
raandree 7469d2b
Refactor task extraction in Build.ps1 to use Select-String for improv…
raandree 93cea6a
fixed and changes according to PR comments
raandree 7799153
fix: avoid false positives when scanning task declarations
raandree File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,122 @@ | ||
| Describe 'Sampler Build.ps1 template' { | ||
| BeforeAll { | ||
| $templatePath = Join-Path -Path $PSScriptRoot -ChildPath '../../../Sampler/Templates/Build/build.ps1' | ||
| $templatePath = (Resolve-Path -Path $templatePath).Path | ||
|
|
||
| $tokens = $null | ||
| $parseErrors = $null | ||
| $script:ast = [System.Management.Automation.Language.Parser]::ParseFile( | ||
| $templatePath, [ref] $tokens, [ref] $parseErrors | ||
| ) | ||
| $script:parseErrors = $parseErrors | ||
|
|
||
| $script:tasksParam = $script:ast.FindAll({ | ||
| param ($node) | ||
| $node -is [System.Management.Automation.Language.ParameterAst] -and | ||
| $node.Name.VariablePath.UserPath -eq 'Tasks' | ||
| }, $true) | Select-Object -First 1 | ||
|
|
||
| $script:completerAttr = $null | ||
| if ($script:tasksParam) | ||
| { | ||
| $script:completerAttr = $script:tasksParam.Attributes | | ||
| Where-Object { $_.TypeName.FullName -eq 'ArgumentCompleter' } | | ||
| Select-Object -First 1 | ||
| } | ||
| } | ||
|
|
||
| It 'Parses without errors' { | ||
| $script:parseErrors.Count | Should -Be 0 | ||
| } | ||
|
|
||
| It 'Defines a $Tasks parameter' { | ||
| $script:tasksParam | Should -Not -BeNullOrEmpty | ||
| } | ||
|
|
||
| It 'Has an ArgumentCompleter attribute on $Tasks' { | ||
| $script:completerAttr | Should -Not -BeNullOrEmpty | ||
| } | ||
|
|
||
| Context 'When invoking the ArgumentCompleter against a fake workspace' { | ||
| BeforeAll { | ||
| $script:fakeRoot = Join-Path -Path $TestDrive -ChildPath 'FakeProject' | ||
| $null = New-Item -ItemType Directory -Path $script:fakeRoot | ||
| $null = New-Item -ItemType Directory -Path (Join-Path -Path $script:fakeRoot -ChildPath '.build') | ||
|
|
||
| Set-Content -Path (Join-Path -Path $script:fakeRoot -ChildPath '.build/Foo.ps1') -Value 'task Foo {}' | ||
|
|
||
| $yamlLines = @( | ||
|
raandree marked this conversation as resolved.
|
||
| 'BuildWorkflow:' | ||
| ' CompWorkflow:' | ||
| ' - build' | ||
| ' - test' | ||
| ' OtherWf:' | ||
| ' - noop' | ||
| 'NextKey: value' | ||
| ) | ||
| Set-Content -Path (Join-Path -Path $script:fakeRoot -ChildPath 'build.yaml') -Value ($yamlLines -join [System.Environment]::NewLine) | ||
|
|
||
| $fakeScriptPath = Join-Path -Path $script:fakeRoot -ChildPath 'Build.ps1' | ||
| Set-Content -Path $fakeScriptPath -Value '# stub' | ||
|
|
||
| $script:completerSource = $script:completerAttr.PositionalArguments[0].ScriptBlock.GetScriptBlock().ToString() | ||
|
|
||
| # Run the completer in a fresh runspace with the fake workspace as | ||
| # the current location. Because no script is being invoked, | ||
| # $PSCommandPath is empty inside the runspace and the completer | ||
| # falls back to $PWD.Path for its script root. | ||
| function Invoke-Completer | ||
| { | ||
| param ([string] $WordToComplete) | ||
|
raandree marked this conversation as resolved.
Outdated
|
||
|
|
||
| $ps = [powershell]::Create() | ||
| try | ||
| { | ||
| $null = $ps.AddScript("Set-Location -LiteralPath '$($script:fakeRoot.Replace("'", "''"))'") | ||
| $null = $ps.Invoke() | ||
| $ps.Commands.Clear() | ||
|
|
||
| $null = $ps.AddScript("`$completer = [scriptblock]::Create(@'`n$($script:completerSource)`n'@); & `$completer 'x' 'Tasks' '$WordToComplete' `$null `$null") | ||
| return $ps.Invoke() | ||
| } | ||
| finally | ||
| { | ||
| $ps.Dispose() | ||
| } | ||
| } | ||
| } | ||
|
|
||
| It 'Returns a non-empty, sorted, deduplicated completion list' { | ||
| $results = Invoke-Completer -WordToComplete '' | ||
| $values = @($results | ForEach-Object { $_.CompletionText }) | ||
|
|
||
| $values | Should -Not -BeNullOrEmpty | ||
| $values | Should -Contain '?' | ||
| $values | Should -Contain 'Foo' | ||
| $values | Should -Contain 'CompWorkflow' | ||
| $values | Should -Contain 'OtherWf' | ||
|
|
||
| # Sorted alphabetically. | ||
|
raandree marked this conversation as resolved.
Outdated
|
||
| ($values -join '|') | Should -Be (($values | Sort-Object) -join '|') | ||
|
|
||
| # Deduplicated (case-insensitive). | ||
| ($values | Group-Object | Where-Object Count -gt 1) | Should -BeNullOrEmpty | ||
| } | ||
|
|
||
| It 'Filters results based on $wordToComplete' { | ||
| $results = Invoke-Completer -WordToComplete 'Comp' | ||
| $values = @($results | ForEach-Object { $_.CompletionText }) | ||
|
|
||
| $values | Should -Contain 'CompWorkflow' | ||
| $values | Should -Not -Contain 'Foo' | ||
| $values | Should -Not -Contain 'OtherWf' | ||
| } | ||
|
|
||
| It 'Emits CompletionResult objects with ParameterValue result type' { | ||
| $results = @(Invoke-Completer -WordToComplete '') | ||
| $results[0] | Should -BeOfType ([System.Management.Automation.CompletionResult]) | ||
| $results[0].ResultType | Should -Be ([System.Management.Automation.CompletionResultType]::ParameterValue) | ||
| } | ||
| } | ||
| } | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.