You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 frameworkWrite-Error"this is terminating error"
} |Assert-Throw
{
# $ErrorActionPreference = 'continue' is set by the frameworkWrite-Error"this is non-terminating error"
} |Assert-Throw-AllowNonTerminatingError
Thoughts?
The text was updated successfully, but these errors were encountered:
nohwnd
changed the title
How non-terminating errors in Assert-Throw behave?
How should non-terminating errors in Assert-Throw behave?
Aug 3, 2017
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?
The text was updated successfully, but these errors were encountered: