Skip to content

Commit

Permalink
added a test to ensure Set-Location is not added to background job sc…
Browse files Browse the repository at this point in the history
…ript block to set working directory
  • Loading branch information
ayousuf23 committed Oct 13, 2021
1 parent bd5dc97 commit a8f79c8
Showing 1 changed file with 5 additions and 1 deletion.
Expand Up @@ -178,7 +178,7 @@ Describe "Debug-job test" -Tag "Feature" {
}
}

Describe "Ampersand background test" -Tag "CI","Slow" {
Describe "Ampersand background test" -Tag "CI" {
Context "Simple background job" {
AfterEach {
Get-Job | Remove-Job -Force
Expand Down Expand Up @@ -218,6 +218,10 @@ Describe "Ampersand background test" -Tag "CI","Slow" {
$j = Get-Location | ForEach-Object -MemberName Path &
Receive-Job -Wait $j | Should -Be ($PWD.Path)
}
It "Make sure Set-Location is not used in the job's script block to set the working directory" {
$j = (get-variable -value ExecutionContext).SessionState.PSVariable.Get("MyInvocation").Value.MyCommand.ScriptBlock &
(Receive-Job -Wait $j).ToString() | Should -BeExactly "(get-variable -value ExecutionContext).SessionState.PSVariable.Get(`"MyInvocation`").Value.MyCommand.ScriptBlock"
}
It "Test that output redirection is done in the background job" {
$j = Write-Output hello > $TESTDRIVE/hello.txt &
Receive-Job -Wait $j | Should -BeNullOrEmpty
Expand Down

0 comments on commit a8f79c8

Please sign in to comment.