forked from PowerShell/PowerShell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTrap.Tests.ps1
More file actions
28 lines (24 loc) · 1.3 KB
/
Copy pathTrap.Tests.ps1
File metadata and controls
28 lines (24 loc) · 1.3 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
Describe "Test trap" -Tags "CI" {
Context "Trap with flow control" {
It "Line after exception should NOT be continued when it's from a nested script block" {
$a = . {trap {"trapped"; continue;}; . {"hello"; throw "exception"; "world"}}
$a.Length | Should Be 2
$a -join "," | Should Be "hello,trapped"
}
It "Line after exception should NOT be continued and both inner and outter traps should be triggered" {
$a = . {trap {"outer trap"; continue;}; . {trap {"inner trap"; break;}; "hello"; throw "exception"; "world"}}
$a.Length | Should Be 3
$a -join "," | Should Be "hello,inner trap,outer trap"
}
It "Line after exception should be invoked after continue" {
$a = . {trap {"outer trap"; continue;} "hello"; throw "exception"; "world"}
$a.Length | Should Be 3
$a -join "," | Should Be "hello,outer trap,world"
}
It "Line after exception should NOT be invoked and inner trap should not be triggered" {
$a = . {trap {"outer trap"; continue;}; . {trap [system.Argumentexception] {"inner trap"; continue;}; "hello"; throw "exception"; "world"}}
$a.Length | Should Be 2
$a -join "," | Should Be "hello,outer trap"
}
}
}