CRTL-C during a test keeps AfterAll from executing
I should think that AfterAll is also executed
Describe 'before all after all' {
BeforeAll{
Write-Verbose "in BeforeAll" -Verbose
}
it "it" {
Start-Sleep -Seconds 2
}
AfterAll {
Write-Verbose "in AfterAll" -Verbose
}
}
Example hitting ctl-c during it:
Describing before all after all VERBOSE: in BeforeAll VERBOSE: in it Note: After all was not run
Example of full run
Describing before all after all VERBOSE: in BeforeAll VERBOSE: in it [+] it 2.13s VERBOSE: in AfterAll
How would you suggest we fix that? :) We already use try/finally to execute the AfterAll blocks; I don't know of a way to make PowerShell code any more "guaranteed" than with a finally block. If the PowerShell engine isn't executing those after Control+C is pressed, what more can we do?
could something like this be implemented? http://sushihangover.blogspot.com/2012/03/powershell-using-try-finally-block-to.html
I think I could add the [console]::TreatControlCAsInput lines to the try/catch in Descripe.ps1. I just don't know where would be a good place to poll for Ctrl-C input.
Normally, Ctrl+C wouldn't blow past finally, right? Try stopping this loop:
& {
try {
foreach($i in 1..100){ Sleep -Milli 500; Write-Host $i }
}
catch {
Write-Warning "Catch"
}
finally {
Write-Warning "Finally"
}
}
Ah, I see the problem now. Fix coming shortly.