Skip to content

Commit aa40394

Browse files
committed
Fix failing tests
1 parent 23b22e7 commit aa40394

File tree

3 files changed

+53
-47
lines changed

3 files changed

+53
-47
lines changed

Engine/ScriptAnalyzer.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -391,11 +391,11 @@ private void Initialize(
391391
{
392392
this.outputWriter.ThrowTerminatingError(
393393
new ErrorRecord(
394-
new Exception(),
394+
new Exception(),
395395
string.Format(
396-
CultureInfo.CurrentCulture,
397-
Strings.RulesNotFound),
398-
ErrorCategory.ResourceExists,
396+
CultureInfo.CurrentCulture,
397+
Strings.RulesNotFound),
398+
ErrorCategory.ResourceExists,
399399
this));
400400
}
401401

Tests/Engine/CustomizedRule.tests.ps1

Lines changed: 38 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -123,44 +123,47 @@ Describe "Test importing correct customized rules" {
123123
$customizedRulePath.Count | Should Be 1
124124
}
125125

126-
It "will show the custom rule in the results when given a rule folder path with trailing backslash" {
127-
$customizedRulePath = Invoke-ScriptAnalyzer $directory\TestScript.ps1 -CustomizedRulePath $directory\samplerule\ | Where-Object {$_.Message -eq $message}
128-
$customizedRulePath.Count | Should Be 1
129-
}
130-
131-
It "will show the custom rules when given a glob" {
132-
$customizedRulePath = Invoke-ScriptAnalyzer $directory\TestScript.ps1 -CustomizedRulePath $directory\samplerule\samplerule* | Where-Object {$_.Message -eq $message}
133-
$customizedRulePath.Count | Should be 3
134-
}
135-
136-
It "will show the custom rules when given recurse switch" {
137-
$customizedRulePath = Invoke-ScriptAnalyzer $directory\TestScript.ps1 -RecurseCustomRulePath -CustomizedRulePath $directory\samplerule | Where-Object {$_.Message -eq $message}
138-
$customizedRulePath.Count | Should be 3
139-
}
126+
if (!$testingLibraryUsage)
127+
{
128+
It "will show the custom rule in the results when given a rule folder path with trailing backslash" {
129+
$customizedRulePath = Invoke-ScriptAnalyzer $directory\TestScript.ps1 -CustomizedRulePath $directory\samplerule\ | Where-Object {$_.Message -eq $message}
130+
$customizedRulePath.Count | Should Be 1
131+
}
132+
133+
It "will show the custom rules when given a glob" {
134+
$customizedRulePath = Invoke-ScriptAnalyzer $directory\TestScript.ps1 -CustomizedRulePath $directory\samplerule\samplerule* | Where-Object {$_.Message -eq $message}
135+
$customizedRulePath.Count | Should be 3
136+
}
137+
138+
It "will show the custom rules when given recurse switch" {
139+
$customizedRulePath = Invoke-ScriptAnalyzer $directory\TestScript.ps1 -RecurseCustomRulePath -CustomizedRulePath $directory\samplerule | Where-Object {$_.Message -eq $message}
140+
$customizedRulePath.Count | Should be 3
141+
}
140142

141-
It "will show the custom rules when given glob with recurse switch" {
142-
$customizedRulePath = Invoke-ScriptAnalyzer $directory\TestScript.ps1 -RecurseCustomRulePath -CustomizedRulePath $directory\samplerule\samplerule* | Where-Object {$_.Message -eq $message}
143-
$customizedRulePath.Count | Should be 4
144-
}
145-
146-
It "will show the custom rules when given glob with recurse switch" {
147-
$customizedRulePath = Invoke-ScriptAnalyzer $directory\TestScript.ps1 -RecurseCustomRulePath -CustomizedRulePath $directory\samplerule* | Where-Object {$_.Message -eq $message}
148-
$customizedRulePath.Count | Should be 3
149-
}
150-
151-
It "Using IncludeDefaultRules Switch with CustomRulePath" {
152-
$customizedRulePath = Invoke-ScriptAnalyzer $directory\TestScript.ps1 -CustomRulePath $directory\samplerule\samplerule.psm1 -IncludeDefaultRules
153-
$customizedRulePath.Count | Should Be 2
154-
}
143+
It "will show the custom rules when given glob with recurse switch" {
144+
$customizedRulePath = Invoke-ScriptAnalyzer $directory\TestScript.ps1 -RecurseCustomRulePath -CustomizedRulePath $directory\samplerule\samplerule* | Where-Object {$_.Message -eq $message}
145+
$customizedRulePath.Count | Should be 4
146+
}
147+
148+
It "will show the custom rules when given glob with recurse switch" {
149+
$customizedRulePath = Invoke-ScriptAnalyzer $directory\TestScript.ps1 -RecurseCustomRulePath -CustomizedRulePath $directory\samplerule* | Where-Object {$_.Message -eq $message}
150+
$customizedRulePath.Count | Should be 3
151+
}
152+
153+
It "Using IncludeDefaultRules Switch with CustomRulePath" {
154+
$customizedRulePath = Invoke-ScriptAnalyzer $directory\TestScript.ps1 -CustomRulePath $directory\samplerule\samplerule.psm1 -IncludeDefaultRules
155+
$customizedRulePath.Count | Should Be 2
156+
}
155157

156-
It "Using IncludeDefaultRules Switch without CustomRulePath" {
157-
$customizedRulePath = Invoke-ScriptAnalyzer $directory\TestScript.ps1 -IncludeDefaultRules
158-
$customizedRulePath.Count | Should Be 1
159-
}
158+
It "Using IncludeDefaultRules Switch without CustomRulePath" {
159+
$customizedRulePath = Invoke-ScriptAnalyzer $directory\TestScript.ps1 -IncludeDefaultRules
160+
$customizedRulePath.Count | Should Be 1
161+
}
160162

161-
It "Not Using IncludeDefaultRules Switch and without CustomRulePath" {
162-
$customizedRulePath = Invoke-ScriptAnalyzer $directory\TestScript.ps1
163-
$customizedRulePath.Count | Should Be 1
163+
It "Not Using IncludeDefaultRules Switch and without CustomRulePath" {
164+
$customizedRulePath = Invoke-ScriptAnalyzer $directory\TestScript.ps1
165+
$customizedRulePath.Count | Should Be 1
166+
}
164167
}
165168

166169
}

Tests/Engine/LibraryUsage.tests.ps1

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,24 @@ function Invoke-ScriptAnalyzer {
3131
[ValidateSet("Warning", "Error", "Information", IgnoreCase = $true)]
3232
[Parameter(Mandatory = $false)]
3333
[string[]] $Severity = $null,
34-
34+
3535
[Parameter(Mandatory = $false)]
3636
[switch] $Recurse,
3737

38+
[Parameter(Mandatory = $false)]
39+
[switch] $IncludeDefaultRules,
40+
3841
[Parameter(Mandatory = $false)]
3942
[switch] $SuppressedOnly,
4043

4144
[Parameter(Mandatory = $false)]
4245
[string] $Profile = $null
43-
)
44-
# There is an inconsistency between this implementation and c# implementation of the cmdlet.
45-
# The CustomRulePath parameter here is of "string[]" type whereas in the c# implementation it is of "string" type.
46-
# If we set the CustomRulePath parameter here to "string[]", then the library usage test fails when run as an administrator.
47-
# We want to note that the library usage test doesn't fail when run as a non-admin user.
48-
# The following is the error statement when the test runs as an administrator.
49-
# Assert failed on "Initialize" with "7" argument(s): "Test failed due to terminating error: The module was expected to contain an assembly manifest. (Exception from HRESULT: 0x80131018)"
46+
)
47+
48+
if ($null -eq $CustomRulePath)
49+
{
50+
$IncludeDefaultRules = $true
51+
}
5052

5153
$scriptAnalyzer = New-Object "Microsoft.Windows.PowerShell.ScriptAnalyzer.ScriptAnalyzer";
5254
$scriptAnalyzer.Initialize(
@@ -56,6 +58,7 @@ function Invoke-ScriptAnalyzer {
5658
$IncludeRule,
5759
$ExcludeRule,
5860
$Severity,
61+
$IncludeDefaultRules.IsPresent,
5962
$SuppressedOnly.IsPresent,
6063
$Profile
6164
);

0 commit comments

Comments
 (0)