From 1d85aa7c276bbc75ebe6e1d7d767ce800fc679f6 Mon Sep 17 00:00:00 2001 From: Paul Higinbotham Date: Mon, 22 Jun 2020 14:20:46 -0700 Subject: [PATCH] Fix tests writing errors to console. --- .../Get-FileHash.Tests.ps1 | 6 +++--- .../Get-RunspaceDebug.Tests.ps1 | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-FileHash.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-FileHash.Tests.ps1 index 6cb3118fecd..4dc0c946cf1 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-FileHash.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-FileHash.Tests.ps1 @@ -24,14 +24,14 @@ Describe "Get-FileHash" -Tags "CI" { } It "Should write non-terminating error if argument is a folder" { - $result = $PSHOME, "${pshome}\pwsh.dll" | Get-FileHash -ErrorVariable errorVariable + $result = $PSHOME, "${pshome}\pwsh.dll" | Get-FileHash -ErrorVariable errorVariable -ErrorAction SilentlyContinue $result.Count | Should -Be 1 $errorVariable.FullyQualifiedErrorId | Should -BeExactly "UnauthorizedAccessError,Microsoft.PowerShell.Commands.GetFileHashCommand" } It "Should write non-terminating error if a file is locked" -Skip:(-not $IsWindows) { $pagefilePath = (Get-CimInstance -ClassName Win32_PageFileusage).Name - $result = $pagefilePath, "${pshome}\pwsh.dll" | Get-FileHash -ErrorVariable errorVariable + $result = $pagefilePath, "${pshome}\pwsh.dll" | Get-FileHash -ErrorVariable errorVariable -ErrorAction SilentlyContinue $result.Count | Should -Be 1 $errorVariable.FullyQualifiedErrorId | Should -BeExactly "FileReadError,Microsoft.PowerShell.Commands.GetFileHashCommand" } @@ -89,7 +89,7 @@ Describe "Get-FileHash" -Tags "CI" { $newPath = Get-FileHash -Path $testDocumentCopy | Rename-Item -NewName {$_.Hash} -PassThru $newPath.FullName | Should -Exist - Remove-Item -Path $testDocumentCopy -Force + Remove-Item -Path $testDocumentCopy -Force -ErrorAction SilentlyContinue } } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-RunspaceDebug.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-RunspaceDebug.Tests.ps1 index 30423b861f5..d9dab9b1067 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-RunspaceDebug.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-RunspaceDebug.Tests.ps1 @@ -4,10 +4,10 @@ Describe "Get-RunspaceDebug" -Tags "CI" { Context "Check return types of RunspaceDebug" { - It "Should return Microsoft.Powershell.Commands.PSRunspaceDebug as the return type" { - $rs = Get-RunspaceDebug - $rs | Should -Not -BeNullOrEmpty - $rs[0] | Should -BeOfType Microsoft.PowerShell.Commands.PSRunspaceDebug - } + It "Should return Microsoft.Powershell.Commands.PSRunspaceDebug as the return type" { + $rs = Get-RunspaceDebug -ErrorAction SilentlyContinue + $rs | Should -Not -BeNullOrEmpty + $rs[0] | Should -BeOfType Microsoft.PowerShell.Commands.PSRunspaceDebug + } } }