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:
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
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
toStop
in the test script block as so: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 everyAssert-Throw
, and only optionally relaxing this rule by specifying-AllowNonTerminatingError
switch:Thoughts?