From facb2284515259f4da4a83685103ad3626e66a2d Mon Sep 17 00:00:00 2001 From: Klaudia Algiz Date: Tue, 22 May 2018 19:57:03 -0700 Subject: [PATCH] Remove ShouldBeErrorId custom function. (#6891) --- .../Scripting/ParameterBinding.Tests.ps1 | 2 +- .../Trace-Command.Tests.ps1 | 7 +++-- .../Modules/HelpersCommon/HelpersCommon.psd1 | 2 +- .../Modules/HelpersCommon/HelpersCommon.psm1 | 28 ++----------------- 4 files changed, 8 insertions(+), 31 deletions(-) diff --git a/test/powershell/Language/Scripting/ParameterBinding.Tests.ps1 b/test/powershell/Language/Scripting/ParameterBinding.Tests.ps1 index a0dc9c1d66..7051da7946 100644 --- a/test/powershell/Language/Scripting/ParameterBinding.Tests.ps1 +++ b/test/powershell/Language/Scripting/ParameterBinding.Tests.ps1 @@ -252,7 +252,7 @@ Describe "Tests for parameter binding" -Tags "CI" { $a } - { get-foo -a '' } | ShouldBeErrorID 'ParameterArgumentValidationErrorEmptyStringNotAllowed,get-foo' + { get-foo -a '' } | Should -Throw -ErrorId 'ParameterArgumentValidationErrorEmptyStringNotAllowed,get-foo' } It 'Empty string is allowed when AllowEmptyString Attribute is set' { diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Trace-Command.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Trace-Command.Tests.ps1 index 91ff1eefd9..675686b8db 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Trace-Command.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Trace-Command.Tests.ps1 @@ -95,7 +95,7 @@ Describe "Trace-Command" -tags "CI" { } It "Get non-existing trace source" { - { '34E7F9FA-EBFB-4D21-A7D2-D7D102E2CC2F' | get-tracesource -ErrorAction Stop} | ShouldBeErrorID 'TraceSourceNotFound,Microsoft.PowerShell.Commands.GetTraceSourceCommand' + { '34E7F9FA-EBFB-4D21-A7D2-D7D102E2CC2F' | get-tracesource -ErrorAction Stop} | Should -Throw -ErrorId 'TraceSourceNotFound,Microsoft.PowerShell.Commands.GetTraceSourceCommand' } It "Set-TraceSource to file and RemoveFileListener wildcard" { @@ -105,11 +105,12 @@ Describe "Trace-Command" -tags "CI" { } It "Trace-Command -Command with error" { - { Trace-Command -Name ParameterBinding -Command 'Get-PSDrive' -ArgumentList 'NonExistingDrive' -Option ExecutionFlow -FilePath $filePath -Force -ListenerOption "ProcessId,TimeStamp" -ErrorAction Stop } | ShouldBeErrorID 'GetLocationNoMatchingDrive,Microsoft.PowerShell.Commands.TraceCommandCommand' + { Trace-Command -Name ParameterBinding -Command 'Get-PSDrive' -ArgumentList 'NonExistingDrive' -Option ExecutionFlow -FilePath $filePath -Force -ListenerOption "ProcessId,TimeStamp" -ErrorAction Stop } | + Should -Throw -ErrorId 'GetLocationNoMatchingDrive,Microsoft.PowerShell.Commands.TraceCommandCommand' } It "Trace-Command fails for non-filesystem paths" { - { Trace-Command -Name ParameterBinding -Expression {$null} -FilePath "Env:\Test" -ErrorAction Stop } | ShouldBeErrorID 'FileListenerPathResolutionFailed,Microsoft.PowerShell.Commands.TraceCommandCommand' + { Trace-Command -Name ParameterBinding -Expression {$null} -FilePath "Env:\Test" -ErrorAction Stop } | Should -Throw -ErrorId 'FileListenerPathResolutionFailed,Microsoft.PowerShell.Commands.TraceCommandCommand' } It "Trace-Command to readonly file" { diff --git a/test/tools/Modules/HelpersCommon/HelpersCommon.psd1 b/test/tools/Modules/HelpersCommon/HelpersCommon.psd1 index c9e3c61872..d8ef7f01e6 100644 --- a/test/tools/Modules/HelpersCommon/HelpersCommon.psd1 +++ b/test/tools/Modules/HelpersCommon/HelpersCommon.psd1 @@ -16,5 +16,5 @@ Copyright = 'Copyright (c) Microsoft Corporation. All rights reserved.' Description = 'Temporary module contains functions for using in tests' -FunctionsToExport = 'Wait-UntilTrue', 'Test-IsElevated', 'ShouldBeErrorId', 'Wait-FileToBePresent', 'Get-RandomFileName', 'Enable-Testhook', 'Disable-Testhook', 'Set-TesthookResult', 'Test-TesthookIsSet' +FunctionsToExport = 'Wait-UntilTrue', 'Test-IsElevated', 'Wait-FileToBePresent', 'Get-RandomFileName', 'Enable-Testhook', 'Disable-Testhook', 'Set-TesthookResult', 'Test-TesthookIsSet' } diff --git a/test/tools/Modules/HelpersCommon/HelpersCommon.psm1 b/test/tools/Modules/HelpersCommon/HelpersCommon.psm1 index 0b970f245c..afae562245 100644 --- a/test/tools/Modules/HelpersCommon/HelpersCommon.psm1 +++ b/test/tools/Modules/HelpersCommon/HelpersCommon.psm1 @@ -56,30 +56,6 @@ function Test-IsElevated } return $IsElevated } -#This function follows the pester naming convention -function ShouldBeErrorId -{ - param([Parameter(ValueFromPipeline, Mandatory)] - [ScriptBlock] - $sb, - - [Parameter(Mandatory, Position=0)] - [string] - $FullyQualifiedErrorId) - - try - { - & $sb | Out-Null - Throw "No Exception!" - } - catch - { - $_.FullyQualifiedErrorId | Should Be $FullyQualifiedErrorId | Out-Null - # Write the exception to output that allow us to check later other properies of the exception - Write-Output $_ - } -} - function Get-RandomFileName { [System.IO.Path]::GetFileNameWithoutExtension([IO.Path]::GetRandomFileName()) @@ -90,7 +66,7 @@ function Get-RandomFileName # note these manipulate private data in the PowerShell engine which will # enable us to not actually alter the system or mock returned data # -$SCRIPT:TesthookType = [system.management.automation.internal.internaltesthooks] +$SCRIPT:TesthookType = [system.management.automation.internal.internaltesthooks] function Test-TesthookIsSet { param ( @@ -132,7 +108,7 @@ function Set-TesthookResult param ( [ValidateNotNullOrEmpty()] [Parameter(Mandatory=$true)] - $testhookName, + $testhookName, [ValidateNotNullOrEmpty()] [Parameter(Mandatory=$true)] $value