Skip to content

Commit 006d957

Browse files
author
Quoc Truong
committed
Fix test failures
1 parent 5866510 commit 006d957

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

Tests/Engine/LibraryUsage.tests.ps1

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,15 @@ $directory = Split-Path -Parent $MyInvocation.MyCommand.Path
66
# wraps the usage of ScriptAnalyzer as a .NET library
77
function Invoke-ScriptAnalyzer {
88
param (
9-
[parameter(Mandatory = $true, Position = 0)]
9+
[CmdletBinding(DefaultParameterSetName="File")]
10+
11+
[parameter(Mandatory = $true, Position = 0, ParameterSetName="File")]
1012
[Alias("PSPath")]
1113
[string] $Path,
1214

15+
[parameter(Mandatory = $true, ParameterSetName="ScriptDefinition")]
16+
[string] $ScriptDefinition,
17+
1318
[Parameter(Mandatory = $false)]
1419
[string[]] $CustomizedRulePath = $null,
1520

@@ -41,7 +46,12 @@ function Invoke-ScriptAnalyzer {
4146
$SuppressedOnly.IsPresent
4247
);
4348

44-
return $scriptAnalyzer.AnalyzePath($Path, $Recurse.IsPresent);
49+
if ($PSCmdlet.ParameterSetName -eq "File") {
50+
return $scriptAnalyzer.AnalyzePath($Path, $Recurse.IsPresent);
51+
}
52+
else {
53+
return $scriptAnalyzer.AnalyzeScriptDefinition($ScriptDefinition);
54+
}
4555
}
4656

4757
# Define an implementation of the IOutputWriter interface

Tests/Engine/RuleSuppression.tests.ps1

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Describe "RuleSuppressionWithoutScope" {
1414
Context "Function" {
1515
It "Does not raise violations" {
1616
$suppression = $violations | Where-Object { $_.RuleName -eq "PSProvideCommentHelp" }
17+
$suppression.Count | Should Be 0
1718
$suppression = $violationsUsingScriptDefinition | Where-Object { $_.RuleName -eq "PSProvideCommentHelp" }
1819
$suppression.Count | Should Be 0
1920
}
@@ -22,6 +23,7 @@ Describe "RuleSuppressionWithoutScope" {
2223
Context "Class" {
2324
It "Does not raise violations" {
2425
$suppression = $violations | Where-Object {$_.RuleName -eq "PSAvoidUsingInvokeExpression" }
26+
$suppression.Count | Should Be 0
2527
$suppression = $violationsUsingScriptDefinition | Where-Object {$_.RuleName -eq "PSAvoidUsingInvokeExpression" }
2628
$suppression.Count | Should Be 0
2729
}
@@ -30,6 +32,7 @@ Describe "RuleSuppressionWithoutScope" {
3032
Context "FunctionInClass" {
3133
It "Does not raise violations" {
3234
$suppression = $violations | Where-Object {$_.RuleName -eq "PSAvoidUsingCmdletAliases" }
35+
$suppression.Count | Should Be 0
3336
$suppression = $violationsUsingScriptDefinition | Where-Object {$_.RuleName -eq "PSAvoidUsingCmdletAliases" }
3437
$suppression.Count | Should Be 0
3538
}
@@ -38,6 +41,7 @@ Describe "RuleSuppressionWithoutScope" {
3841
Context "Script" {
3942
It "Does not raise violations" {
4043
$suppression = $violations | Where-Object {$_.RuleName -eq "PSProvideCommentHelp" }
44+
$suppression.Count | Should Be 0
4145
$suppression = $violationsUsingScriptDefinition | Where-Object {$_.RuleName -eq "PSProvideCommentHelp" }
4246
$suppression.Count | Should Be 0
4347
}
@@ -46,6 +50,7 @@ Describe "RuleSuppressionWithoutScope" {
4650
Context "RuleSuppressionID" {
4751
It "Only suppress violations for that ID" {
4852
$suppression = $violations | Where-Object {$_.RuleName -eq "PSProvideDefaultParameterValue" }
53+
$suppression.Count | Should Be 1
4954
$suppression = $violationsUsingScriptDefinition | Where-Object {$_.RuleName -eq "PSProvideDefaultParameterValue" }
5055
$suppression.Count | Should Be 1
5156
}
@@ -56,6 +61,7 @@ Describe "RuleSuppressionWithScope" {
5661
Context "FunctionScope" {
5762
It "Does not raise violations" {
5863
$suppression = $violations | Where-Object {$_.RuleName -eq "PSAvoidUsingPositionalParameters" }
64+
$suppression.Count | Should Be 0
5965
$suppression = $violationsUsingScriptDefinition | Where-Object {$_.RuleName -eq "PSAvoidUsingPositionalParameters" }
6066
$suppression.Count | Should Be 0
6167
}
@@ -64,6 +70,7 @@ Describe "RuleSuppressionWithScope" {
6470
Context "ClassScope" {
6571
It "Does not raise violations" {
6672
$suppression = $violations | Where-Object {$_.RuleName -eq "PSAvoidUsingConvertToSecureStringWithPlainText" }
73+
$suppression.Count | Should Be 0
6774
$suppression = $violationsUsingScriptDefinition | Where-Object {$_.RuleName -eq "PSAvoidUsingConvertToSecureStringWithPlainText" }
6875
$suppression.Count | Should Be 0
6976
}

0 commit comments

Comments
 (0)