forked from nightroman/PowerShellTraps
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.test.ps1
More file actions
32 lines (28 loc) · 1.02 KB
/
.test.ps1
File metadata and controls
32 lines (28 loc) · 1.02 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
$v2 = $PSVersionTable.PSVersion.Major -eq 2
# Synopsis: Good error in v2 and v3+
task Test-1-correct-error-location {
($r = try {.\Test-1-correct-error-location.ps1} catch {$_})
assert ($r.InvocationInfo.PositionMessage -like '*MissingCommand*')
}
# Synopsis: Good error in v2, misleading in v3+
task Test-2-misleading-error-location {
($r = try {.\Test-2-misleading-error-location.ps1} catch {$_})
if ($v2) {
assert ($r.InvocationInfo.PositionMessage -like '*MissingCommand*')
}
else {
assert ($r.InvocationInfo.PositionMessage -like '*WillThrow*')
}
}
# Synopsis: How to recover correct error location in v3+
task Test-3-recovering-error-location {
($r = try {.\Test-3-recovering-error-location.ps1} catch {$_})
if ($v2) {
assert ($r[0].InvocationInfo.PositionMessage -like '*MissingCommand*')
assert ($r[1].InvocationInfo.PositionMessage -like '*MissingCommand*')
}
else {
assert ($r[0].InvocationInfo.PositionMessage -like '*WillThrow*')
assert ($r[1].InvocationInfo.PositionMessage -like '*MissingCommand*')
}
}