Skip to content

Commit 0703994

Browse files
committed
Add tests and correct typo
1 parent f0e44b2 commit 0703994

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

Engine/Commands/InvokeScriptAnalyzerCommand.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ private void AnalyzeFile(string filePath)
275275
// Use a List of KVP rather than dictionary, since for a script containing inline functions with same signature, keys clash
276276
List<KeyValuePair<CommandInfo, IScriptExtent>> cmdInfoTable = new List<KeyValuePair<CommandInfo, IScriptExtent>>();
277277

278-
//Check wild card input for the Include/ExcludRules and create regex match patterns
278+
//Check wild card input for the Include/ExcludeRules and create regex match patterns
279279
List<Regex> includeRegexList = new List<Regex>();
280280
List<Regex> excludeRegexList = new List<Regex>();
281281
if (includeRule != null)
@@ -358,6 +358,7 @@ private void AnalyzeFile(string filePath)
358358
if (exclude.IsMatch(scriptRule.GetName()))
359359
{
360360
excludeRegexMatch = true;
361+
break;
361362
}
362363
}
363364
if ((includeRule == null || includeRule.Contains(scriptRule.GetName(), StringComparer.OrdinalIgnoreCase) || includeRegexMatch) &&
@@ -433,6 +434,7 @@ private void AnalyzeFile(string filePath)
433434
if (exclude.IsMatch(commandRule.GetName()))
434435
{
435436
excludeRegexMatch = true;
437+
break;
436438
}
437439
}
438440
if ((includeRule == null || includeRule.Contains(commandRule.GetName(), StringComparer.OrdinalIgnoreCase) || includeRegexMatch) &&
@@ -480,6 +482,7 @@ private void AnalyzeFile(string filePath)
480482
if (exclude.IsMatch(tokenRule.GetName()))
481483
{
482484
excludeRegexMatch = true;
485+
break;
483486
}
484487
}
485488
if ((includeRule == null || includeRule.Contains(tokenRule.GetName(), StringComparer.OrdinalIgnoreCase) || includeRegexMatch) &&
@@ -524,6 +527,7 @@ private void AnalyzeFile(string filePath)
524527
if (exclude.IsMatch(dscResourceRule.GetName()))
525528
{
526529
excludeRegexMatch = true;
530+
break;
527531
}
528532
}
529533
if ((includeRule == null || includeRule.Contains(dscResourceRule.GetName(), StringComparer.OrdinalIgnoreCase) || includeRegexMatch) &&

Tests/Engine/InvokeScriptAnalyzer.tests.ps1

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ $sa = Get-Command Invoke-ScriptAnalyzer
33
$directory = Split-Path -Parent $MyInvocation.MyCommand.Path
44
$singularNouns = "PSUseSingularNouns"
55
$rules = $singularNouns, "PSUseApprovedVerbs"
6+
$avoidRules = "PSAvoid*"
7+
$useRules = "PSUse*"
68

79
Describe "Test available parameters" {
810
$params = $sa.Parameters
@@ -103,6 +105,12 @@ Describe "Test ExcludeRule" {
103105
}
104106
}
105107

108+
Context "Support wild card" {
109+
It "supports wild card exclusions of input rules"{
110+
$excludeWildCard = Invoke-ScriptAnalyzer $directory\..\Rules\BadCmdlet.ps1 -ExcludeRule $avoidRules | Where-Object {$_.RuleName -match $avoidRules}
111+
}
112+
}
113+
106114
}
107115

108116
Describe "Test IncludeRule" {
@@ -124,6 +132,18 @@ Describe "Test IncludeRule" {
124132
$wrongInclude.Count | Should Be 0
125133
}
126134
}
135+
136+
Context "IncludeRule supports wild card" {
137+
It "includes 1 wildcard rule"{
138+
$includeWildcard = Invoke-ScriptAnalyzer $directory\..\Rules\BadCmdlet.ps1 -IncludeRule $avoidRules
139+
$includeWildcard.Count | Should be 5
140+
}
141+
142+
it "includes 2 wildcardrules" {
143+
$includeWildcard = Invoke-ScriptAnalyzer $directory\..\Rules\BadCmdlet.ps1 -IncludeRule $avoidRules, $useRules
144+
$includeWildcard.Count | Should be 7
145+
}
146+
}
127147
}
128148

129149
Describe "Test Exclude And Include" {

0 commit comments

Comments
 (0)