1
+ # Check if PSScriptAnalyzer is already loaded so we don't
2
+ # overwrite a test version of Invoke-ScriptAnalyzer by
3
+ # accident
4
+ if (! (Get-Module PSScriptAnalyzer) -and ! $testingLibraryUsage )
5
+ {
6
+ Import-Module - Verbose PSScriptAnalyzer
7
+ }
8
+
9
+ $directory = Split-Path - Parent $MyInvocation.MyCommand.Path
10
+ $violations = Invoke-ScriptAnalyzer $directory \GlobalSuppression.ps1
11
+ $suppression = Invoke-ScriptAnalyzer $directory \GlobalSuppression.ps1 - Profile $directory \Profile.ps1
12
+
13
+ Describe " GlobalSuppression" {
14
+ Context " Exclude Rule" {
15
+ It " Raises 1 violation for uninitialized variable and 1 for cmdlet alias" {
16
+ $withoutProfile = $violations | Where-Object { $_.RuleName -eq " PSAvoidUsingCmdletAliases" -or $_.RuleName -eq " PSAvoidUninitializedVariable" }
17
+ $withoutProfile.Count | Should Be 2
18
+ }
19
+
20
+ It " Does not raise any violations for uninitialized variable and cmdlet alias with profile" {
21
+ $withProfile = $suppression | Where-Object { $_.RuleName -eq " PSAvoidUsingCmdletAliases" -or $_.RuleName -eq " PSAvoidUninitializedVariable" }
22
+ $withProfile.Count | Should be 0
23
+ }
24
+ }
25
+
26
+ Context " Include Rule" {
27
+ It " Raises 1 violation for computername hard-coded" {
28
+ $withoutProfile = $violations | Where-Object { $_.RuleName -eq " PSAvoidUsingComputerNameHardcoded" }
29
+ $withoutProfile.Count | Should Be 1
30
+ }
31
+
32
+ It " Does not raise any violations for computername hard-coded" {
33
+ $withProfile = $suppression | Where-Object { $_.RuleName -eq " PSAvoidUsingComputerNameHardcoded" }
34
+ $withProfile.Count | Should be 0
35
+ }
36
+ }
37
+
38
+ Context " Severity" {
39
+ It " Raises 1 violation for internal url without profile" {
40
+ $withoutProfile = $violations | Where-Object { $_.RuleName -eq " PSAvoidUsingInternalURLs" }
41
+ $withoutProfile.Count | Should Be 1
42
+ }
43
+
44
+ It " Does not raise any violations for internal urls with profile" {
45
+ $withProfile = $suppression | Where-Object { $_.RuleName -eq " PSAvoidUsingInternalURLs" }
46
+ $withProfile.Count | Should be 0
47
+ }
48
+ }
49
+ }
0 commit comments