Repository navigation
Invoke-Item #1220
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
Invoke-Item #1220
Changes from all commits
eec3b33
61a6713
65f31c0
fd7a167
7cac07f
7bc1bff
e580941
946280b
aefeb80
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 |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| using namespace System.Diagnostics | ||
|
|
||
| Describe "Invoke-Item" { | ||
|
|
||
| $tmpDirectory = $TestDrive | ||
| $testfile = "testfile.txt" | ||
| $testfolder = "newDirectory" | ||
| $testlink = "testlink" | ||
| $FullyQualifiedFile = Join-Path -Path $tmpDirectory -ChildPath $testfile | ||
| $FullyQualifiedFolder = Join-Path -Path $tmpDirectory -ChildPath $testfolder | ||
| $FullyQualifiedLink = Join-Path -Path $tmpDirectory -ChildPath $testlink | ||
|
|
||
| function NewProcessStartInfo([string]$CommandLine, [switch]$RedirectStdIn) | ||
| { | ||
| return [ProcessStartInfo]@{ | ||
| FileName = $powershell | ||
| Arguments = $CommandLine | ||
| RedirectStandardInput = $RedirectStdIn | ||
| RedirectStandardOutput = $true | ||
| RedirectStandardError = $true | ||
| UseShellExecute = $false | ||
| } | ||
| } | ||
|
|
||
| function RunPowerShell([ProcessStartInfo]$debugfn) | ||
| { | ||
| $process = [Process]::Start($debugfn) | ||
| return $process | ||
| } | ||
|
|
||
| function EnsureChildHasExited([Process]$process, [int]$WaitTimeInMS = 15000) | ||
| { | ||
| $process.WaitForExit($WaitTimeInMS) | ||
|
|
||
| if (!$process.HasExited) | ||
| { | ||
| $process.HasExited | Should Be $true | ||
| $process.Kill() | ||
| } | ||
| } | ||
|
|
||
| function Clean-State | ||
| { | ||
| if (Test-Path $FullyQualifiedLink) | ||
| { | ||
| Remove-Item $FullyQualifiedLink -Force | ||
| } | ||
|
|
||
| if (Test-Path $FullyQualifiedFile) | ||
| { | ||
| Remove-Item $FullyQualifiedFile -Force | ||
| } | ||
|
|
||
| if (Test-Path $FullyQualifiedFolder) | ||
| { | ||
| Remove-Item $FullyQualifiedFolder -Force | ||
| } | ||
| } | ||
|
|
||
| BeforeAll { | ||
| $powershell = Join-Path -Path $PsHome -ChildPath "powershell" | ||
| } | ||
|
|
||
| #Both tests are pending due to a bug in Invoke-Item on Windows. Fixed for Linux | ||
|
|
||
| It "Should call the function without error" -Pending:$IsWindows { | ||
| { New-Item -Name $testfile -Path $tmpDirectory -ItemType file } | Should Not Throw | ||
| } | ||
|
|
||
| It "Should invoke a text file without error" -Pending:$IsWindows { | ||
| $debugfn = NewProcessStartInfo "-noprofile ""``Invoke-Item $FullyQualifiedFile`n" -RedirectStdIn | ||
| $process = RunPowerShell $debugfn | ||
|
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. Do you need to launch a whole new PowerShell process for this? Can't you just launch
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. Synced offline: II was failing silently on Linux with defunct threads, which would cause the host process to exit with an error code. This is the correct test. |
||
| EnsureChildHasExited $process | ||
| $process.ExitCode | Should Be 0 | ||
| } | ||
| } | ||
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.
Could you double check to make sure that on windows system, there is no two processes launched for invoke-item? Thanks.
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.
This PR is very old and this code has since been rewritten due to this not being supported on Windows at all. See #1325.