How should non-terminating errors in Assert-Throw behave?
nohwnd opened this issue · comments
Jakub Jareš commented
PowerShell has two types of errors: terminating and non-terminating. For the moment Assert-Throw
only catches terminating errors. To force catching even non-terminating errors you need to change $ErrorActionPreference
to Stop
in the test script block as so:
{
$ErrorActionPreference = 'stop'
Write-Error "this is terminating error"
} | Assert-Throw
This is inconvenient to do for every test, and hard to discover, and should imho be handled by the framework.
The proposed behavior is to be strict and force $ErrorActionPreference = 'stop'
in every Assert-Throw
, and only optionally relaxing this rule by specifying -AllowNonTerminatingError
switch:
{
# $ErrorActionPreference = 'stop' is set by the framework
Write-Error "this is terminating error"
} | Assert-Throw
{
# $ErrorActionPreference = 'continue' is set by the framework
Write-Error "this is non-terminating error"
} | Assert-Throw -AllowNonTerminatingError
Thoughts?
Jakub Jareš commented
Piloting this in 0.7.0