forked from PowerShell/PowerShell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGet-PSCallStack.Tests.ps1
More file actions
89 lines (79 loc) · 2.65 KB
/
Copy pathGet-PSCallStack.Tests.ps1
File metadata and controls
89 lines (79 loc) · 2.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
Describe "Get-PSCallStack DRT Unit Tests" -Tags "CI" {
BeforeAll {
$scriptFileName = "GetTryCatchCallStack.ps1"
$scriptFilePath = Join-Path $TestDrive -ChildPath $scriptFileName
}
It "Verifies that the script block of a catch clause does not show up on the call stack" {
$fileStream = @"
function foo()
{
try
{
throw 1
}
catch
{
bar
}
}
function bar()
{
try
{
throw 1
}
catch
{
try
{
throw 1
}
catch
{
Get-PSCallStack
}
}
}
foo
"@
$fileStream > $scriptFilePath
$results = & "$scriptFilePath"
$results.Count | Should -BeGreaterThan 3
$results[0].Command | Should -BeExactly "bar"
$results[0].ScriptName | Should -Be $scriptFilePath
$results[0].ScriptLineNumber | Should -Be 27
$results[0].InvocationInfo.ScriptLineNumber | Should -Be 9
$results[1].Command | Should -BeExactly "foo"
$results[1].ScriptName | Should -Be $scriptFilePath
$results[1].ScriptLineNumber | Should -Be 9
$results[1].InvocationInfo.ScriptLineNumber | Should -Be 32
#InvocationInfo.ScriptLineNumber: Gets the line number of the script that contains the command
$results[2].Command | Should -Be $scriptFileName
$results[2].ScriptName | Should -Be $scriptFilePath
$results[2].ScriptLineNumber | Should -Be 32
$results[2].InvocationInfo.ScriptLineNumber | Should -Be 46
}
It "Verify that the script block of a trap statement shows up on the call stack" {
$fileStream = @"
trap
{
Get-PSCallStack
continue
}
throw 1
"@
$fileStream > $scriptFilePath
$results = & "$scriptFilePath"
$results.Count | Should -BeGreaterThan 2
$results[0].Command | Should -Be $scriptFileName
$results[0].ScriptName | Should -Be $scriptFilePath
$results[0].ScriptLineNumber | Should -Be 3
$results[0].InvocationInfo.ScriptLineNumber | Should -Be 77
$results[1].Command | Should -Be $scriptFileName
$results[1].ScriptName | Should -Be $scriptFilePath
$results[1].ScriptLineNumber | Should -Be 7
$results[1].InvocationInfo.ScriptLineNumber | Should -Be 77
}
}