Skip to content

Commit dbe3143

Browse files
author
Kapil Borle
committed
Creates a workaround the failing tests.
We have set the CustomRulePath parameter in the cmdlet implementation in LibraryUsage.tests.ps1 to "string[]" type whereas in the c# implementation it is of "string" type. If we set the CustomRulePath parameter here to "string", then the library usage test fails when run as an administrator. We want to note that the library usage test doesn't fail when run as a non-admin user. Even if we create a "[string[]]" type object and pass it to Initialize method, the tests fail to run as an admin with the following error message. 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)
1 parent 50ea056 commit dbe3143

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

Tests/Engine/InvokeScriptAnalyzer.tests.ps1

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,14 @@ Describe "Test available parameters" {
4141
}
4242

4343
It "accepts a string" {
44-
$params["CustomRulePath"].ParameterType.FullName | Should Be "System.String"
44+
if ($testingLibraryUsage)
45+
{
46+
$params["CustomRulePath"].ParameterType.FullName | Should Be "System.String[]"
47+
}
48+
else
49+
{
50+
$params["CustomRulePath"].ParameterType.FullName | Should Be "System.String"
51+
}
4552
}
4653

4754
It "has a CustomizedRulePath alias"{

Tests/Engine/LibraryUsage.tests.ps1

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ function Invoke-ScriptAnalyzer {
1717

1818
[Parameter(Mandatory = $false)]
1919
[Alias("CustomizedRulePath")]
20-
[string] $CustomRulePath = $null,
20+
[string[]] $CustomRulePath = $null,
2121

2222
[Parameter(Mandatory = $false)]
2323
[switch] $RecurseCustomRulePath,
@@ -41,17 +41,18 @@ function Invoke-ScriptAnalyzer {
4141
[Parameter(Mandatory = $false)]
4242
[string] $Profile = $null
4343
)
44-
[string[]]$customRulePathArr = @($CustomRulePath);
45-
if ($CustomRulePath -eq $null)
46-
{
47-
$customRulePathArr = $null;
48-
}
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)"
4950

5051
$scriptAnalyzer = New-Object "Microsoft.Windows.PowerShell.ScriptAnalyzer.ScriptAnalyzer";
5152
$scriptAnalyzer.Initialize(
5253
$runspace,
5354
$testOutputWriter,
54-
$customRulePathArr,
55+
$CustomRulePath,
5556
$IncludeRule,
5657
$ExcludeRule,
5758
$Severity,

0 commit comments

Comments
 (0)