-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Fix for #4520 '-ArgumentList should accept @() or $null' #6597
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
d85c2a5
94983c5
b0c3bed
436cc81
01603a5
45f0ccf
324d772
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 |
|---|---|---|
|
|
@@ -6,6 +6,10 @@ Describe "Start-Process" -Tags @("Feature") { | |
| $isNanoServer = [System.Management.Automation.Platform]::IsNanoServer | ||
| $isIot = [System.Management.Automation.Platform]::IsIoT | ||
| $isFullWin = $IsWindows -and !$isNanoServer -and !$isIot | ||
| $extraArgs = @{} | ||
| if ($isFullWin) { | ||
| $extraArgs.WindowStyle = "Hidden" | ||
| } | ||
|
|
||
| $pingCommand = (Get-Command -CommandType Application ping)[0].Definition | ||
| $pingDirectory = Split-Path $pingCommand -Parent | ||
|
|
@@ -23,65 +27,65 @@ Describe "Start-Process" -Tags @("Feature") { | |
| # This has been fixed on Linux, but not on macOS | ||
|
|
||
| It "Should process arguments without error" { | ||
| $process = Start-Process ping -ArgumentList $pingParam -PassThru -RedirectStandardOutput "$TESTDRIVE/output" | ||
| $process = Start-Process ping -ArgumentList $pingParam -PassThru -RedirectStandardOutput "$TESTDRIVE/output" @extraArgs | ||
|
|
||
| $process.Length | Should -Be 1 | ||
| $process.Id | Should -BeGreaterThan 1 | ||
| # $process.ProcessName | Should Be "ping" | ||
| } | ||
|
|
||
| It "Should work correctly when used with full path name" { | ||
| $process = Start-Process $pingCommand -ArgumentList $pingParam -PassThru -RedirectStandardOutput "$TESTDRIVE/output" | ||
| $process = Start-Process $pingCommand -ArgumentList $pingParam -PassThru -RedirectStandardOutput "$TESTDRIVE/output" @extraArgs | ||
|
|
||
| $process.Length | Should -Be 1 | ||
| $process.Id | Should -BeGreaterThan 1 | ||
| # $process.ProcessName | Should Be "ping" | ||
| } | ||
|
|
||
| It "Should invoke correct path when used with FilePath argument" { | ||
| $process = Start-Process -FilePath $pingCommand -ArgumentList $pingParam -PassThru -RedirectStandardOutput "$TESTDRIVE/output" | ||
| $process = Start-Process -FilePath $pingCommand -ArgumentList $pingParam -PassThru -RedirectStandardOutput "$TESTDRIVE/output" @extraArgs | ||
|
|
||
| $process.Length | Should -Be 1 | ||
| $process.Id | Should -BeGreaterThan 1 | ||
| # $process.ProcessName | Should Be "ping" | ||
| } | ||
|
|
||
| It "Should invoke correct path when used with Path alias argument" { | ||
| $process = Start-Process -Path $pingCommand -ArgumentList $pingParam -PassThru -RedirectStandardOutput "$TESTDRIVE/output" | ||
| $process = Start-Process -Path $pingCommand -ArgumentList $pingParam -PassThru -RedirectStandardOutput "$TESTDRIVE/output" @extraArgs | ||
|
|
||
| $process.Length | Should -Be 1 | ||
| $process.Id | Should -BeGreaterThan 1 | ||
| } | ||
|
|
||
| It "Should wait for command completion if used with Wait argument" { | ||
| $process = Start-Process ping -ArgumentList $pingParam -Wait -PassThru -RedirectStandardOutput "$TESTDRIVE/output" | ||
| $process = Start-Process ping -ArgumentList $pingParam -Wait -PassThru -RedirectStandardOutput "$TESTDRIVE/output" @extraArgs | ||
| } | ||
|
|
||
| It "Should work correctly with WorkingDirectory argument" { | ||
| $process = Start-Process ping -WorkingDirectory $pingDirectory -ArgumentList $pingParam -PassThru -RedirectStandardOutput "$TESTDRIVE/output" | ||
| $process = Start-Process ping -WorkingDirectory $pingDirectory -ArgumentList $pingParam -PassThru -RedirectStandardOutput "$TESTDRIVE/output" @extraArgs | ||
|
|
||
| $process.Length | Should -Be 1 | ||
| $process.Id | Should -BeGreaterThan 1 | ||
| # $process.ProcessName | Should Be "ping" | ||
| } | ||
|
|
||
| It "Should handle stderr redirection without error" { | ||
| $process = Start-Process ping -ArgumentList $pingParam -PassThru -RedirectStandardError $tempFile -RedirectStandardOutput "$TESTDRIVE/output" | ||
| $process = Start-Process ping -ArgumentList $pingParam -PassThru -RedirectStandardError $tempFile -RedirectStandardOutput "$TESTDRIVE/output" @extraArgs | ||
|
|
||
| $process.Length | Should -Be 1 | ||
| $process.Id | Should -BeGreaterThan 1 | ||
| # $process.ProcessName | Should Be "ping" | ||
| } | ||
|
|
||
| It "Should handle stdout redirection without error" { | ||
| $process = Start-Process ping -ArgumentList $pingParam -Wait -RedirectStandardOutput $tempFile | ||
| $process = Start-Process ping -ArgumentList $pingParam -Wait -RedirectStandardOutput $tempFile @extraArgs | ||
| $dirEntry = get-childitem $tempFile | ||
| $dirEntry.Length | Should -BeGreaterThan 0 | ||
| } | ||
|
|
||
| # Marking this test 'pending' to unblock daily builds. Filed issue : https://github.com/PowerShell/PowerShell/issues/2396 | ||
| It "Should handle stdin redirection without error" -Pending { | ||
| $process = Start-Process sort -Wait -RedirectStandardOutput $tempFile -RedirectStandardInput $assetsFile | ||
| $process = Start-Process sort -Wait -RedirectStandardOutput $tempFile -RedirectStandardInput $assetsFile @extraArgs | ||
| $dirEntry = get-childitem $tempFile | ||
| $dirEntry.Length | Should -BeGreaterThan 0 | ||
| } | ||
|
|
@@ -116,13 +120,31 @@ Describe "Start-Process" -Tags @("Feature") { | |
|
|
||
| It "Should be able to use the -WhatIf switch without performing the actual action" { | ||
| $pingOutput = Join-Path $TestDrive "pingOutput.txt" | ||
| { Start-Process -Wait $pingCommand -ArgumentList $pingParam -RedirectStandardOutput $pingOutput -WhatIf -ErrorAction Stop } | Should -Not -Throw | ||
| { Start-Process -Wait $pingCommand -ArgumentList $pingParam -RedirectStandardOutput $pingOutput -WhatIf -ErrorAction Stop @extraArgs} | Should -Not -Throw | ||
| $pingOutput | Should -Not -Exist | ||
| } | ||
|
|
||
| It "Should return null when using -WhatIf switch with -PassThru" { | ||
| Start-Process $pingCommand -ArgumentList $pingParam -PassThru -WhatIf | Should -BeNullOrEmpty | ||
| } | ||
| } | ||
|
|
||
| It 'Should run without errors when -ArgumentList is $null' { | ||
| $process = Start-Process $pingCommand -ArgumentList $null -PassThru @extraArgs | ||
| $process.Length | Should -Be 1 | ||
| $process.Id | Should -BeGreaterThan 1 | ||
| } | ||
|
|
||
| It "Should run without errors when -ArgumentList is @()" { | ||
| $process = Start-Process $pingCommand -ArgumentList @() -PassThru @extraArgs | ||
| $process.Length | Should -Be 1 | ||
| $process.Id | Should -BeGreaterThan 1 | ||
|
Member
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. Same as above.
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. These are basic sanity tests to make sure the process was created and is running (has an ID). |
||
| } | ||
|
|
||
| It "Should run without errors when -ArgumentList is ''" { | ||
|
||
| $process = Start-Process $pingCommand -ArgumentList '' -PassThru @extraArgs | ||
| $process.Length | Should -Be 1 | ||
| $process.Id | Should -BeGreaterThan 1 | ||
|
Member
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. Same as above.
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. These are basic sanity tests to make sure the process was created and is running (has an ID). |
||
| } | ||
| } | ||
|
|
||
| Describe "Start-Process tests requiring admin" -Tags "Feature","RequireAdminOnWindows" { | ||
|
|
||
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.
Is this check required?
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.
These are basic sanity tests to make sure the process was created and is running (has an ID).
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.
If the process is not started the
$processis$null.