forked from microsoft/PSRule
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFromFileWithError.Rule.ps1
85 lines (70 loc) · 1.62 KB
/
FromFileWithError.Rule.ps1
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
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
#
# Pester unit test rules for error handling
#
# Synopsis: Should pass
Rule 'WithPass' {
$Assert.Pass();
}
# Synopsis: Should fail
Rule 'WithFail' {
$Assert.Fail('This is a fail');
}
# Synopsis: Should fail
Rule 'WithNonBoolean' {
$True
'false' # Not a boolean
}
Rule 'WithDependency1' -DependsOn 'WithDependency2' {
$True;
}
Rule 'WithDependency2' -DependsOn 'WithDependency3' {
$True;
}
Rule 'WithDependency3' -DependsOn 'WithDependency1' {
$True;
}
Rule 'WithDependency4' -DependsOn 'WithDependency5' {
$True;
}
# Synopsis: Should pass because exception is caught.
Rule 'WithTryCatch' {
try {
$Null = Get-Command PSRule_NotCommand -ErrorAction Stop;
$True;
}
catch {
$False;
}
}
# Synopsis: With parsing error.
Rule 'WithParameterNotFound' {
$item = Get-Item -MisspelledParameter MyItem;
$True;
}
# Synopsis: With throw.
Rule 'WithThrow' {
throw 'Some error'
}
# Synopsis: Should pass because error is suppressed.
Rule 'WithCmdletErrorActionIgnore' {
$result = Get-Command PSRule_NotCommand -ErrorAction Ignore;
$Null -ne $result;
}
# Synopsis: Rule using the default stop action.
Rule 'WithRuleErrorActionDefault' {
Write-Error 'Some error 1';
Write-Error 'Some error 2';
$True;
}
# Synopsis: Rule ignoring errors.
Rule 'WithRuleErrorActionIgnore' -ErrorAction Ignore {
Write-Error 'Some error';
$True;
}
# Synopsis: Rule to generate a PowerShell parsing exception
Rule 'WithParseError' {
$Null = Get-Item -MisspelledParameter MyItem
$True;
}