-
Notifications
You must be signed in to change notification settings - Fork 8.4k
Add error handling for interactive #requires #6469
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
Changes from all commits
565bb13
b7a773f
163f93d
cca907d
9aa8981
b3c4324
214e854
c8617dc
f615591
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -915,4 +915,39 @@ foo``u{2195}abc | |
| # Issue #2780 | ||
| { ExecuteCommand "`$herestr=@`"`n'`"'`n`"@" } | Should Not Throw | ||
| } | ||
|
|
||
| Context "#requires nested scan tokenizer tests" { | ||
| BeforeAll { | ||
| $settings = [System.Management.Automation.PSInvocationSettings]::new() | ||
| $settings.AddToHistory = $true | ||
|
|
||
| $ps = [powershell]::Create() | ||
| } | ||
|
|
||
| AfterAll { | ||
| $ps.Dispose() | ||
| } | ||
|
|
||
| AfterEach { | ||
| $ps.Commands.Clear() | ||
| } | ||
|
|
||
| $testCases = @( | ||
| @{ script = "#requires"; firstToken = $null; lastToken = $null }, | ||
| @{ script = "#requires -Version 5.0`n10"; firstToken = "10"; lastToken = "10" }, | ||
| @{ script = "Write-Host 'Hello'`n#requires -Version 5.0`n7"; firstToken = "Write-Host"; lastToken = "7" }, | ||
| @{ script = "Write-Host 'Hello'`n#requires -Version 5.0"; firstToken = "Write-Host"; lastToken = "Hello"} | ||
| ) | ||
|
|
||
| It "Correctly resets the first and last tokens in the tokenizer after nested scan in script" -TestCases $testCases { | ||
| param($script, $firstToken, $lastToken) | ||
|
|
||
| $ps.AddScript($script) | ||
| $ps.AddScript("(`$^,`$`$)") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm a little surprised this works, 2 calls to AddScript is I think like piping the first call to the second. That said, it neatly drops any results from the first call. To be slightly more like the interactive scenario, I think you would call
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I tried that and it didn't seem to do what I wanted. To be honest, I wasn't entirely certain how I should be using the embedded PowerShell session to recreate the input. But I spent some time playing with it, tried the "script, invoke, tokens, invoke" way and seemed to get |
||
| $tokens = $ps.Invoke(@(), $settings) | ||
|
|
||
| $tokens[0] | Should -BeExactly $firstToken | ||
| $tokens[1] | Should -BeExactly $lastToken | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please have a
AfterAllblock to dispose$ps.