File tree Expand file tree Collapse file tree 1 file changed +21
-4
lines changed Expand file tree Collapse file tree 1 file changed +21
-4
lines changed Original file line number Diff line number Diff line change 1
- Import-Module PSScriptAnalyzer
1
+ $directory = Split-Path - Parent $MyInvocation.MyCommand.Path
2
+ $testRootDirectory = Split-Path - Parent $directory
3
+
4
+ Import-Module PSScriptAnalyzer
5
+ Import-Module (Join-Path $testRootDirectory ' PSScriptAnalyzerTestHelper.psm1' )
6
+
2
7
$violationMessage = " The variable 'declaredVar2' is assigned but never used."
3
8
$violationName = " PSUseDeclaredVarsMoreThanAssignments"
4
- $directory = Split-Path - Parent $MyInvocation.MyCommand.Path
5
9
$violations = Invoke-ScriptAnalyzer $directory \UseDeclaredVarsMoreThanAssignments.ps1 | Where-Object {$_.RuleName -eq $violationName }
6
10
$noViolations = Invoke-ScriptAnalyzer $directory \UseDeclaredVarsMoreThanAssignmentsNoViolations.ps1 | Where-Object {$_.RuleName -eq $violationName }
7
11
@@ -29,8 +33,21 @@ function MyFunc2() {
29
33
$a + $a
30
34
}
31
35
'@
32
- $local :violations = Invoke-ScriptAnalyzer - ScriptDefinition $target - IncludeRule $violationName
33
- $local :violations.Count | Should Be 1
36
+ Invoke-ScriptAnalyzer - ScriptDefinition $target - IncludeRule $violationName | `
37
+ Get-Count | `
38
+ Should Be 1
39
+ }
40
+
41
+ It " does not flag `$ InformationPreference variable" {
42
+ Invoke-ScriptAnalyzer - ScriptDefinition ' $InformationPreference=Stop' - IncludeRule $violationName | `
43
+ Get-Count | `
44
+ Should Be 0
45
+ }
46
+
47
+ It " does not flag `$ PSModuleAutoLoadingPreference variable" {
48
+ Invoke-ScriptAnalyzer - ScriptDefinition ' $PSModuleAutoLoadingPreference=None' - IncludeRule $violationName | `
49
+ Get-Count | `
50
+ Should Be 0
34
51
}
35
52
}
36
53
You can’t perform that action at this time.
0 commit comments