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+
27$violationMessage = " The variable 'declaredVar2' is assigned but never used."
38$violationName = " PSUseDeclaredVarsMoreThanAssignments"
4- $directory = Split-Path - Parent $MyInvocation.MyCommand.Path
59$violations = Invoke-ScriptAnalyzer $directory \UseDeclaredVarsMoreThanAssignments.ps1 | Where-Object {$_.RuleName -eq $violationName }
610$noViolations = Invoke-ScriptAnalyzer $directory \UseDeclaredVarsMoreThanAssignmentsNoViolations.ps1 | Where-Object {$_.RuleName -eq $violationName }
711
@@ -29,8 +33,21 @@ function MyFunc2() {
2933 $a + $a
3034}
3135'@
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
3451 }
3552 }
3653
You can’t perform that action at this time.
0 commit comments