mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Correct case of $error special variable
This commit is contained in:
@@ -70,10 +70,10 @@ Describe -Name "Windows MSI" -Fixture {
|
||||
$uploadedLog = $false
|
||||
}
|
||||
BeforeEach {
|
||||
$Error.Clear()
|
||||
$error.Clear()
|
||||
}
|
||||
AfterEach {
|
||||
if ($Error.Count -ne 0 -and !$uploadedLog) {
|
||||
if ($error.Count -ne 0 -and !$uploadedLog) {
|
||||
Copy-Item -Path $msiLog -Destination $env:temp -Force
|
||||
Write-Verbose "MSI log is at $env:temp\msilog.txt" -Verbose
|
||||
$uploadedLog = $true
|
||||
|
||||
@@ -88,7 +88,7 @@ Describe "ConsoleHost unit tests" -tags "Feature" {
|
||||
}
|
||||
|
||||
AfterEach {
|
||||
$Error.Clear()
|
||||
$error.Clear()
|
||||
}
|
||||
|
||||
It "Clear-Host does not injects data into PowerShell output stream" {
|
||||
|
||||
@@ -229,7 +229,7 @@ Describe 'Positive Parse Properties Tests' -Tags "CI" {
|
||||
'111' -Match '1'
|
||||
$Matches
|
||||
$Matches
|
||||
$Error[0]
|
||||
$error[0]
|
||||
$error
|
||||
$pwd
|
||||
foreach ($i in 1..10) {$foreach}
|
||||
|
||||
@@ -255,7 +255,7 @@ try
|
||||
It "$Description" {
|
||||
|
||||
$Result = [PSObject] @{Output = $true ; Error = $null}
|
||||
$Error.Clear()
|
||||
$error.Clear()
|
||||
try
|
||||
{
|
||||
$null = Unregister-PSSessionConfiguration -name $SessionConfigName -ErrorAction stop
|
||||
|
||||
@@ -104,7 +104,7 @@ Describe "Basic FileSystem Provider Tests" -Tags "CI" {
|
||||
|
||||
It "Verify Rename-Item will not rename to an existing name" {
|
||||
{ Rename-Item -Path $testFile -NewName $testDir -ErrorAction Stop } | Should -Throw -ErrorId "RenameItemIOError,Microsoft.PowerShell.Commands.RenameItemCommand"
|
||||
$Error[0].Exception | Should -BeOfType System.IO.IOException
|
||||
$error[0].Exception | Should -BeOfType System.IO.IOException
|
||||
$testFile | Should -Exist
|
||||
}
|
||||
|
||||
@@ -133,7 +133,7 @@ Describe "Basic FileSystem Provider Tests" -Tags "CI" {
|
||||
|
||||
It "Verify Move-Item will not move to an existing file" {
|
||||
{ Move-Item -Path $testDir -Destination $testFile -ErrorAction Stop } | Should -Throw -ErrorId "MoveDirectoryItemIOError,Microsoft.PowerShell.Commands.MoveItemCommand"
|
||||
$Error[0].Exception | Should -BeOfType System.IO.IOException
|
||||
$error[0].Exception | Should -BeOfType System.IO.IOException
|
||||
$testDir | Should -Exist
|
||||
}
|
||||
|
||||
@@ -748,8 +748,8 @@ Describe "Copy-Item can avoid copying an item onto itself" -Tags "CI", "RequireA
|
||||
else
|
||||
{
|
||||
{ Copy-Item -Path $sourcePath -Destination $destinationPath -ErrorAction Stop } | Should -Throw -ErrorId "CopyError,Microsoft.PowerShell.Commands.CopyItemCommand"
|
||||
$Error[0].Exception | Should -BeOfType System.IO.IOException
|
||||
$Error[0].Exception.Data[$selfCopyKey] | Should -Not -BeNullOrEmpty
|
||||
$error[0].Exception | Should -BeOfType System.IO.IOException
|
||||
$error[0].Exception.Data[$selfCopyKey] | Should -Not -BeNullOrEmpty
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -811,8 +811,8 @@ Describe "Copy-Item can avoid copying an item onto itself" -Tags "CI", "RequireA
|
||||
)
|
||||
|
||||
{ Copy-Item -Path $Source -Destination $Destination -ErrorAction Stop } | Should -Throw -ErrorId "CopyError,Microsoft.PowerShell.Commands.CopyItemCommand"
|
||||
$Error[0].Exception | Should -BeOfType System.IO.IOException
|
||||
$Error[0].Exception.Data[$selfCopyKey] | Should -Not -BeNullOrEmpty
|
||||
$error[0].Exception | Should -BeOfType System.IO.IOException
|
||||
$error[0].Exception.Data[$selfCopyKey] | Should -Not -BeNullOrEmpty
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -65,9 +65,9 @@ Describe "Test-Connection" -tags "CI" {
|
||||
Should -Throw -ErrorId "TestConnectionException,Microsoft.PowerShell.Commands.TestConnectionCommand"
|
||||
# Error code = 11001 - Host not found.
|
||||
if (!$isWindows) {
|
||||
$Error[0].Exception.InnerException.ErrorCode | Should -Be -131073
|
||||
$error[0].Exception.InnerException.ErrorCode | Should -Be -131073
|
||||
} else {
|
||||
$Error[0].Exception.InnerException.ErrorCode | Should -Be 11001
|
||||
$error[0].Exception.InnerException.ErrorCode | Should -Be 11001
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
# Licensed under the MIT License.
|
||||
|
||||
Describe 'Get-Error tests' -Tag CI {
|
||||
It 'Get-Error resolves $Error[0] and includes InnerException' {
|
||||
It 'Get-Error resolves $error[0] and includes InnerException' {
|
||||
try {
|
||||
1/0
|
||||
}
|
||||
@@ -103,7 +103,7 @@ Describe 'Get-Error tests' -Tag CI {
|
||||
|
||||
$null = Get-Error
|
||||
|
||||
$Error[0].pstypenames | Should -Be System.Management.Automation.ErrorRecord, System.Object
|
||||
$error[0].pstypenames | Should -Be System.Management.Automation.ErrorRecord, System.Object
|
||||
}
|
||||
|
||||
It 'Get-Error adds ExceptionType for Exceptions' {
|
||||
|
||||
@@ -47,10 +47,10 @@ Describe "Stream writer tests" -Tags "CI" {
|
||||
}
|
||||
|
||||
Context "Error automatic variable" {
|
||||
It "Should write error messages to the `$Error automatic variable" {
|
||||
It "Should write error messages to the `$error automatic variable" {
|
||||
Write-Error "Test Error Message" -ErrorAction SilentlyContinue
|
||||
|
||||
$Error[0] | Should -Match "Test Error Message"
|
||||
$error[0] | Should -Match "Test Error Message"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user