|
| 1 | +BeforeAll { |
| 2 | + $integrationTestScript = "$PSScriptRoot$([IO.Path]::DirectorySeparatorChar)integration-test-script.ps1" |
| 3 | + $integrationTestScriptContent = Get-Content -Raw $integrationTestScript |
| 4 | + |
| 5 | + $checkOutput = { |
| 6 | + param([string[]] $output, [string[]] $expected) |
| 7 | + # Remove color codes |
| 8 | + $output = $output -replace '\x1b\[[0-9;]*[a-z]', '' |
| 9 | + |
| 10 | + # Remove escape sequences (these appear on macOS and Linux) |
| 11 | + $output = $output -replace '\e\[\?1[hl]', '' |
| 12 | + |
| 13 | + # Remove warnings |
| 14 | + $output = $output | Where-Object { $_ -notmatch 'WARNING: warning CS1701: Assuming assembly reference' } |
| 15 | + |
| 16 | + # Remove empty lines |
| 17 | + $output = $output | Where-Object { $_ -ne '' } |
| 18 | + |
| 19 | + # Print out so that we can compare the whole output if the test fails |
| 20 | + $output | Write-Host |
| 21 | + |
| 22 | + for ($i = 0; $i -lt $expected.Count -and $i -lt $output.Count; $i++) |
| 23 | + { |
| 24 | + $output[$i] | Should -Be $expected[$i] -Because "Output line $i" |
| 25 | + } |
| 26 | + $output.Count | Should -Be $expected.Count |
| 27 | + } |
| 28 | +} |
| 29 | + |
| 30 | +# These fail when THIS script is executed on Windows PowerShell 5.1 or Poweshell 7.3 or lower with the following error: |
| 31 | +# ParserError: |
| 32 | +# Line | |
| 33 | +# 28 | $($prop): $value |
| 34 | +# | ~ |
| 35 | +# | Unexpected token ':' in expression or statement. |
| 36 | +# |
| 37 | +# It looks like the variable `$integrationTestScriptContent` is expanded in place and then evaluted as an expression. |
| 38 | +# Let's just skip these versions. We test Windows PowerShell as the target anyway in a test case. |
| 39 | +# And we can live without testing on PowerShell 7.2 & 7.3 because we have tests for 7.4. |
| 40 | +Describe 'Out-Sentry captures expected stack traces for command argument' -Skip:(($PSVersionTable.PSVersion.Major -eq 7 -and $PSVersionTable.PSVersion.Minor -le 3) -or $PSVersionTable.PSEdition -eq 'Desktop') { |
| 41 | + BeforeEach { |
| 42 | + Push-Location "$PSScriptRoot" |
| 43 | + $expected = @( |
| 44 | + '----------------' |
| 45 | + 'AbsolutePath: <No file>' |
| 46 | + 'AddressMode: ' |
| 47 | + 'ColumnNumber: ' |
| 48 | + 'ContextLine: ' |
| 49 | + 'FileName: ' |
| 50 | + 'FramesOmitted: ' |
| 51 | + 'Function: <ScriptBlock>' |
| 52 | + 'FunctionId: ' |
| 53 | + 'ImageAddress: ' |
| 54 | + 'InApp: True' |
| 55 | + 'InstructionAddress: ' |
| 56 | + 'LineNumber: 1' |
| 57 | + 'Module: ' |
| 58 | + 'Package: ' |
| 59 | + 'Platform: ' |
| 60 | + 'PostContext: ' |
| 61 | + 'PreContext: ' |
| 62 | + 'SymbolAddress: ' |
| 63 | + 'Vars: ' |
| 64 | + '----------------' |
| 65 | + 'AbsolutePath: <No file>' |
| 66 | + 'AddressMode: ' |
| 67 | + 'ColumnNumber: ' |
| 68 | + 'ContextLine: ' |
| 69 | + 'FileName: ' |
| 70 | + 'FramesOmitted: ' |
| 71 | + 'Function: <ScriptBlock>' |
| 72 | + 'FunctionId: ' |
| 73 | + 'ImageAddress: ' |
| 74 | + 'InApp: True' |
| 75 | + 'InstructionAddress: ' |
| 76 | + 'LineNumber: 14' |
| 77 | + 'Module: ' |
| 78 | + 'Package: ' |
| 79 | + 'Platform: ' |
| 80 | + 'PostContext: ' |
| 81 | + 'PreContext: ' |
| 82 | + 'SymbolAddress: ' |
| 83 | + 'Vars: ' |
| 84 | + '----------------' |
| 85 | + 'AbsolutePath: ' |
| 86 | + 'AddressMode: ' |
| 87 | + 'ColumnNumber: 5' |
| 88 | + "ContextLine: funcA 'throw' 'error'" |
| 89 | + 'FileName: ' |
| 90 | + 'FramesOmitted: ' |
| 91 | + 'Function: ' |
| 92 | + 'FunctionId: ' |
| 93 | + 'ImageAddress: ' |
| 94 | + 'InApp: True' |
| 95 | + 'InstructionAddress: ' |
| 96 | + 'LineNumber: 14' |
| 97 | + 'Module: ' |
| 98 | + 'Package: ' |
| 99 | + 'Platform: ' |
| 100 | + 'PostContext: ' |
| 101 | + 'PreContext: ' |
| 102 | + 'SymbolAddress: ' |
| 103 | + 'Vars: ' |
| 104 | + ) |
| 105 | + |
| 106 | + } |
| 107 | + |
| 108 | + AfterEach { |
| 109 | + Pop-Location |
| 110 | + } |
| 111 | + |
| 112 | + It 'Windows PowerShell' -Skip:($env:OS -ne 'Windows_NT') { |
| 113 | + $output = powershell.exe -Command "& {$integrationTestScriptContent}" -ErrorAction Continue |
| 114 | + $checkOutput.Invoke($output, $expected) |
| 115 | + } |
| 116 | + |
| 117 | + It 'PowerShell' { |
| 118 | + $output = pwsh -Command "& {$integrationTestScriptContent}" -ErrorAction Continue |
| 119 | + $checkOutput.Invoke($output, $expected) |
| 120 | + } |
| 121 | +} |
| 122 | + |
| 123 | +Describe 'Out-Sentry captures expected stack traces for piped command' { |
| 124 | + BeforeEach { |
| 125 | + Push-Location "$PSScriptRoot" |
| 126 | + $expected = @( |
| 127 | + '----------------' |
| 128 | + 'AbsolutePath: <No file>' |
| 129 | + 'AddressMode: ' |
| 130 | + 'ColumnNumber: ' |
| 131 | + 'ContextLine: ' |
| 132 | + 'FileName: ' |
| 133 | + 'FramesOmitted: ' |
| 134 | + 'Function: <ScriptBlock>' |
| 135 | + 'FunctionId: ' |
| 136 | + 'ImageAddress: ' |
| 137 | + 'InApp: True' |
| 138 | + 'InstructionAddress: ' |
| 139 | + 'LineNumber: 3' |
| 140 | + 'Module: ' |
| 141 | + 'Package: ' |
| 142 | + 'Platform: ' |
| 143 | + 'PostContext: ' |
| 144 | + 'PreContext: ' |
| 145 | + 'SymbolAddress: ' |
| 146 | + 'Vars: ' |
| 147 | + '----------------' |
| 148 | + 'AbsolutePath: ' |
| 149 | + 'AddressMode: ' |
| 150 | + 'ColumnNumber: 5' |
| 151 | + "ContextLine: funcA 'throw' 'error'" |
| 152 | + 'FileName: ' |
| 153 | + 'FramesOmitted: ' |
| 154 | + 'Function: ' |
| 155 | + 'FunctionId: ' |
| 156 | + 'ImageAddress: ' |
| 157 | + 'InApp: True' |
| 158 | + 'InstructionAddress: ' |
| 159 | + 'LineNumber: 3' |
| 160 | + 'Module: ' |
| 161 | + 'Package: ' |
| 162 | + 'Platform: ' |
| 163 | + 'PostContext: ' |
| 164 | + 'PreContext: ' |
| 165 | + 'SymbolAddress: ' |
| 166 | + 'Vars: ' |
| 167 | + ) |
| 168 | + } |
| 169 | + |
| 170 | + AfterEach { |
| 171 | + Pop-Location |
| 172 | + } |
| 173 | + |
| 174 | + It 'Windows PowerShell' -Skip:($env:OS -ne 'Windows_NT') { |
| 175 | + $output = $integrationTestScriptContent | powershell.exe -Command - |
| 176 | + $checkOutput.Invoke($output, $expected) |
| 177 | + } |
| 178 | + |
| 179 | + It 'PowerShell' { |
| 180 | + $output = $integrationTestScriptContent | pwsh -Command - |
| 181 | + $checkOutput.Invoke($output, $expected) |
| 182 | + } |
| 183 | +} |
| 184 | + |
| 185 | +Describe 'Out-Sentry captures expected stack traces for file input' { |
| 186 | + BeforeEach { |
| 187 | + Push-Location "$PSScriptRoot" |
| 188 | + $expected = @( |
| 189 | + '----------------' |
| 190 | + 'AbsolutePath: <No file>' |
| 191 | + 'AddressMode: ' |
| 192 | + 'ColumnNumber: ' |
| 193 | + 'ContextLine: ' |
| 194 | + 'FileName: ' |
| 195 | + 'FramesOmitted: ' |
| 196 | + 'Function: <ScriptBlock>' |
| 197 | + 'FunctionId: ' |
| 198 | + 'ImageAddress: ' |
| 199 | + 'InApp: True' |
| 200 | + 'InstructionAddress: ' |
| 201 | + 'LineNumber: 1' |
| 202 | + 'Module: ' |
| 203 | + 'Package: ' |
| 204 | + 'Platform: ' |
| 205 | + 'PostContext: ' |
| 206 | + 'PreContext: ' |
| 207 | + 'SymbolAddress: ' |
| 208 | + 'Vars: ' |
| 209 | + '----------------' |
| 210 | + "AbsolutePath: $integrationTestScript" |
| 211 | + 'AddressMode: ' |
| 212 | + 'ColumnNumber: 5' |
| 213 | + "ContextLine: funcA 'throw' 'error'" |
| 214 | + 'FileName: ' |
| 215 | + 'FramesOmitted: ' |
| 216 | + 'Function: <ScriptBlock>' |
| 217 | + 'FunctionId: ' |
| 218 | + 'ImageAddress: ' |
| 219 | + 'InApp: True' |
| 220 | + 'InstructionAddress: ' |
| 221 | + 'LineNumber: 14' |
| 222 | + 'Module: ' |
| 223 | + 'Package: ' |
| 224 | + 'Platform: ' |
| 225 | + 'PostContext: }' |
| 226 | + 'catch' |
| 227 | + '{' |
| 228 | + ' $_ | Out-Sentry | Out-Null' |
| 229 | + '}' |
| 230 | + 'PreContext: $transport = [RecordingTransport]::new()' |
| 231 | + 'StartSentryForEventTests ([ref] $events) ([ref] $transport)' |
| 232 | + 'try' |
| 233 | + '{' |
| 234 | + 'SymbolAddress: ' |
| 235 | + 'Vars: ' |
| 236 | + ) |
| 237 | + } |
| 238 | + |
| 239 | + AfterEach { |
| 240 | + Pop-Location |
| 241 | + } |
| 242 | + |
| 243 | + It 'Windows PowerShell' -Skip:($env:OS -ne 'Windows_NT') { |
| 244 | + $PSNativeCommandUseErrorActionPreference = $false |
| 245 | + $output = powershell.exe $integrationTestScript |
| 246 | + $checkOutput.Invoke($output, $expected) |
| 247 | + } |
| 248 | + |
| 249 | + It 'PowerShell' { |
| 250 | + $PSNativeCommandUseErrorActionPreference = $false |
| 251 | + $output = pwsh -Command $integrationTestScript |
| 252 | + $checkOutput.Invoke($output, $expected) |
| 253 | + } |
| 254 | +} |
0 commit comments