Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How should non-terminating errors in Assert-Throw behave? #17

Open
nohwnd opened this issue Aug 3, 2017 · 1 comment
Open

How should non-terminating errors in Assert-Throw behave? #17

nohwnd opened this issue Aug 3, 2017 · 1 comment

Comments

@nohwnd
Copy link
Owner

nohwnd commented 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 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?

@nohwnd nohwnd changed the title How non-terminating errors in Assert-Throw behave? How should non-terminating errors in Assert-Throw behave? Aug 3, 2017
@nohwnd
Copy link
Owner Author

nohwnd commented Aug 3, 2017

Piloting this in 0.7.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant