2016-03-04 23:48:30 +01:00
|
|
|
Describe "Write-Error" {
|
|
|
|
It "Should be able to throw" {
|
2016-03-04 23:52:27 +01:00
|
|
|
Write-Error "test throw" -ErrorAction SilentlyContinue | Should Throw
|
2016-03-04 23:48:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
It "Should throw a non-terminating error" {
|
2016-03-04 23:52:27 +01:00
|
|
|
Write-Error "test throw" -ErrorAction SilentlyContinue
|
2016-03-04 23:48:30 +01:00
|
|
|
|
2016-03-04 23:52:27 +01:00
|
|
|
1 + 1 | Should Be 2
|
2016-03-04 23:48:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
It "Should trip an exception using the exception switch" {
|
2016-03-04 23:52:27 +01:00
|
|
|
$var = 0
|
|
|
|
try
|
|
|
|
{
|
|
|
|
Write-Error -Exception -Message "test throw"
|
|
|
|
}
|
|
|
|
catch [System.Exception]
|
|
|
|
{
|
|
|
|
|
|
|
|
$var++
|
|
|
|
}
|
|
|
|
finally
|
|
|
|
{
|
|
|
|
$var | Should Be 1
|
|
|
|
}
|
2016-03-04 23:48:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
It "Should output the error message to the `$error automatic variable" {
|
2016-03-04 23:52:27 +01:00
|
|
|
$theError = "Error: Too many input values."
|
|
|
|
write-error -message $theError -category InvalidArgument -ErrorAction SilentlyContinue
|
2016-03-04 23:48:30 +01:00
|
|
|
|
2016-03-04 23:52:27 +01:00
|
|
|
$error[0]| Should Be $theError
|
2016-03-04 23:48:30 +01:00
|
|
|
}
|
2015-11-19 00:59:00 +01:00
|
|
|
}
|