diff --git a/test/powershell/Language/Operators/ComparisonOperator.Tests.ps1 b/test/powershell/Language/Operators/ComparisonOperator.Tests.ps1 index 703b8c203a..c3357854ac 100644 --- a/test/powershell/Language/Operators/ComparisonOperator.Tests.ps1 +++ b/test/powershell/Language/Operators/ComparisonOperator.Tests.ps1 @@ -50,13 +50,13 @@ Describe "ComparisonOperator" -tag "CI" { } It "Should return error if right hand is not a valid type: 'hello' " -TestCases @( - @{operator = "-is"; type = "'foo'"}, - @{operator = "-isnot"; type = "'foo'"}, - @{operator = "-is"; type = "[foo]"}, - @{operator = "-isnot"; type = "[foo]"} + @{operator = "-is"; type = "'foo'"; expectedError='RuntimeException,Microsoft.PowerShell.Commands.InvokeExpressionCommand'}, + @{operator = "-isnot"; type = "'foo'"; expectedError='RuntimeException,Microsoft.PowerShell.Commands.InvokeExpressionCommand'}, + @{operator = "-is"; type = "[foo]"; expectedError='TypeNotFound,Microsoft.PowerShell.Commands.InvokeExpressionCommand'}, + @{operator = "-isnot"; type = "[foo]"; expectedError='TypeNotFound,Microsoft.PowerShell.Commands.InvokeExpressionCommand'} ) { - param($operator, $type) - { Invoke-Expression "'Hello' $operator $type" | Should Be ErrorId "RuntimeException" } + param($operator, $type, $expectedError) + { Invoke-Expression "'Hello' $operator $type" } | ShouldBeErrorId $expectedError } It "Should succeed in comparing type: " -TestCases @( diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/xml.tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/xml.tests.ps1 index a3bf1bc05f..7a8f2ad001 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/xml.tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/xml.tests.ps1 @@ -54,20 +54,32 @@ } } - It "non filesystem path using " -TestCases @( - @{parameter="literalPath"}, - @{parameter="path"} + It "Verifies a non filesystem path using should fail" -TestCases @( + @{parameter="literalPath"; expectedError='ProcessingFile,Microsoft.PowerShell.Commands.SelectXmlCommand'}, + @{parameter="path"; expectedError='ProcessingFile,Microsoft.PowerShell.Commands.SelectXmlCommand'} ) { - param($parameter) - $__data = "abcdefg" - $params = @{$parameter="variable:__data"} - { Select-XML @params "Root" | Should BeErrorId 'ProcessingFile,Microsoft.PowerShell.Commands.SelectXmlCommand' } + param($parameter, $expectedError) + try + { + $env:xmltestfile = '' + $file = 'env:xmltestfile' + $params = @{$parameter=$file} + $err = $null + Select-XML @params "Root" -ErrorVariable err + $err.FullyQualifiedErrorId | Should Be $expectedError + } + finally + { + Remove-Item -Path 'env:xmltestfile' + } } It "Invalid xml file" { $testfile = "$testdrive/test.xml" Set-Content -Path $testfile -Value "" - { Select-Xml -Path $testfile -XPath foo | ShouldBeErrorId 'ProcessingFile,Microsoft.PowerShell.Commands.SelectXmlCommand' } + $err = $null + Select-Xml -Path $testfile -XPath foo -ErrorVariable err + $err.FullyQualifiedErrorId | Should Be 'ProcessingFile,Microsoft.PowerShell.Commands.SelectXmlCommand' } It "-xml works with inputstream" { @@ -79,12 +91,16 @@ } It "Returns error for invalid xmlnamespace" { + $err = $null [xml]$xml = "helloworld" - { Select-Xml -Xml $xml -XPath foo -Namespace @{c=$null} | ShouldBeErrorId "PrefixError,Microsoft.PowerShell.Commands.SelectXmlCommand" } + Select-Xml -Xml $xml -XPath foo -Namespace @{c=$null} -ErrorVariable err + $err.FullyQualifiedErrorId | Should Be 'PrefixError,Microsoft.PowerShell.Commands.SelectXmlCommand' } It "Returns error for invalid content" { - { Select-Xml -Content "hello" -XPath foo | ShouldBeErrorId "InvalidCastToXmlDocument,Microsoft.PowerShell.Commands.SelectXmlCommand" } + $err = $null + Select-Xml -Content "hello" -XPath foo -ErrorVariable err + $err.FullyQualifiedErrorId | Should Be 'InvalidCastToXmlDocument,Microsoft.PowerShell.Commands.SelectXmlCommand' } It "ToString() works correctly on nested node" {