Based on standard practices, we need to have a copyright and license notice at the top of each source file. Removed existing copyrights and updated/added copyright notices for .h, .cpp, .cs, .ps1, and .psm1 files. Updated module manifests for consistency to have Author = "PowerShell" and Company = "Microsoft Corporation". Removed multiple line breaks. Separate PR coming to update contribution document for new source files: #6140 Manually reviewed each change. Fix #6073
31 lines
1.4 KiB
PowerShell
31 lines
1.4 KiB
PowerShell
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
# Licensed under the MIT License.
|
|
|
|
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"
|
|
}
|
|
}
|
|
}
|