Team Ai
Datasetpublic

MegaBites-AI/Windows-powershell

sourceHugging Facemitupdated 6mo agoView on Hugging Face
0likes308downloads
Get-Error.Tests.ps1108 linesDownload Raw Back to Microsoft.PowerShell.Core
1# Copyright (c) Microsoft Corporation.2# Licensed under the MIT License.3 4Describe "Get-Error" -Tags "CI" {5    It "Does not hang when serializing exception with array with type instances" {6        $ps = [PowerShell]::Create()7        $null = $ps.AddScript(@'8            class GetErrorWithTypeArray : Exception {9                [type[]]$Values10                [type]$Type11 12                GetErrorWithTypeArray ([string]$Message) : base($Message) {13                    $this.Values = [type[]]@([string], [int])14                    $this.Type = [bool]15                }16            }17            try { throw [GetErrorWithTypeArray]::new("") } catch {}18            Get-Error | Out-String19'@)20 21        $task = $ps.BeginInvoke()22        if (-not $task.AsyncWaitHandle.WaitOne(5000)) {23            $null = $ps.BeginStop($null, $null)24            throw "Timed out waiting for Get-Error to serialize"25        }26 27        $result = $ps.EndInvoke($task)28        $result.Count | Should -Be 129        $result[0] | Should -BeOfType ([string])30 31        $formattedError = (@(32            $result[0] -split "\r?\n" | ForEach-Object {33                $_.TrimEnd()34            }35        ) -join ([Environment]::NewLine)).Trim()36 37        $formattedError | Should -Be @'38Exception        :39    Values  :40              [System.String]41              [System.Int32]42    Type    : [System.Boolean]43    HResult : -214623308844CategoryInfo     : OperationStopped: (:) [], GetErrorWithTypeArray45InvocationInfo   :46    ScriptLineNumber : 1047    OffsetInLine     : 1948    HistoryId        : 149    Line             : try { throw [GetErrorWithTypeArray]::new("") } catch {}50 51    Statement        : throw [GetErrorWithTypeArray]::new("")52    PositionMessage  : At line:10 char:1953                       +             try { throw [GetErrorWithTypeArray]::new("") } catch {}54                       +                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~55    CommandOrigin    : Internal56ScriptStackTrace : at <ScriptBlock>, <No file>: line 1057'@.Trim()58    }59 60    It "Formats strings and primitive types in an array" {61        $ps = [PowerShell]::Create()62        $null = $ps.AddScript(@'63            class GetErrorPrimitiveArray : Exception {64                [object[]]$Values65 66                GetErrorPrimitiveArray ([string]$Message) : base($Message) {67                    $this.Values = @(1, "alpha", 0.5)68                }69            }70            try { throw [GetErrorPrimitiveArray]::new("") } catch {}71            Get-Error | Out-String72'@)73 74        $result = $ps.Invoke()75        $result.Count | Should -Be 176        $result[0] | Should -BeOfType ([string])77 78        $formattedError = (@(79            $result[0] -split "\r?\n" | ForEach-Object {80                $_.TrimEnd()81            }82        ) -join ([Environment]::NewLine)).Trim()83 84        $formattedError | Should -Be @'85Exception        :86    Type    : GetErrorPrimitiveArray87    Values  :88              189              alpha90              0.591    HResult : -214623308892CategoryInfo     : OperationStopped: (:) [], GetErrorPrimitiveArray93InvocationInfo   :94    ScriptLineNumber : 895    OffsetInLine     : 1996    HistoryId        : 197    Line             : try { throw [GetErrorPrimitiveArray]::new("") } catch {}98 99    Statement        : throw [GetErrorPrimitiveArray]::new("")100    PositionMessage  : At line:8 char:19101                       +             try { throw [GetErrorPrimitiveArray]::new("") } catch {}102                       +                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~103    CommandOrigin    : Internal104ScriptStackTrace : at <ScriptBlock>, <No file>: line 8105'@.Trim()106    }107}108