Skip to content

Commit a428757

Browse files
author
Kapil Borle
committed
Fix rule tests for PSv4
1 parent 0821897 commit a428757

File tree

4 files changed

+18
-12
lines changed

4 files changed

+18
-12
lines changed

Tests/Rules/AvoidUnloadableModuleOrMissingRequiredFieldInManifest.tests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ $noHashtableFilepath = Join-Path $directory "TestBadModule\NoHashtable.psd1"
99

1010
Describe "MissingRequiredFieldModuleManifest" {
1111
BeforeAll {
12-
Import-Module (Join-Path $directory "PSScriptAnalyzerTestHelper.psm1")
12+
Import-Module (Join-Path $directory "PSScriptAnalyzerTestHelper.psm1") -Force
1313
}
1414

1515
AfterAll{

Tests/Rules/PSCredentialType.tests.ps1

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Import-Module PSScriptAnalyzer
1+
Import-Module PSScriptAnalyzer
22
$violationMessage = "The Credential parameter in 'Credential' must be of type PSCredential. For PowerShell 4.0 and earlier, please define a credential transformation attribute, e.g. [System.Management.Automation.Credential()], after the PSCredential type attribute."
33
$violationName = "PSUsePSCredentialType"
44
$directory = Split-Path -Parent $MyInvocation.MyCommand.Path
@@ -16,9 +16,14 @@ Describe "PSCredentialType" {
1616
}
1717
}
1818

19-
Context "When there are no violations" {
20-
It "returns no violations" {
21-
$noViolations.Count | Should Be 0
19+
$expectedViolationCount = 0
20+
if ($PSVersionTable.PSVersion -lt [Version]'5.0')
21+
{
22+
$expectedViolationCount = 1
23+
}
24+
Context ("When there are {0} violations" -f $expectedViolationCount) {
25+
It ("returns {0} violations" -f $expectedViolationCount) {
26+
$noViolations.Count | Should Be $expectedViolationCount
2227
}
2328
}
2429
}

Tests/Rules/PSScriptAnalyzerTestHelper.psm1

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,20 @@ Function Get-ExtentText
55
[string] $scriptPath
66
)
77
$scriptContent = Get-Content -Path $scriptPath
8-
$start = [System.Management.Automation.Language.ScriptPosition]::new($scriptPath, $violation.StartLineNumber, $violation.StartColumnNumber, $scriptContent[$violation.StartLineNumber - 1])
9-
$end = [System.Management.Automation.Language.ScriptPosition]::new($scriptPath, $violation.EndLineNumber, $violation.EndColumnNumber, $scriptContent[$violation.EndLineNumber - 1])
10-
$extent = [System.Management.Automation.Language.ScriptExtent]::new($start, $end)
8+
$typeScriptPos = 'System.Management.Automation.Language.ScriptPosition'
9+
$start = New-Object -TypeName $typeScriptPos -ArgumentList @($scriptPath, $violation.StartLineNumber, $violation.StartColumnNumber, $scriptContent[$violation.StartLineNumber - 1])
10+
$end = New-Object -TypeName $typeScriptPos -ArgumentList @($scriptPath, $violation.EndLineNumber, $violation.EndColumnNumber, $scriptContent[$violation.EndLineNumber - 1])
11+
$extent = New-Object -TypeName 'System.Management.Automation.Language.ScriptExtent' -ArgumentList @($start, $end)
1112
return($extent.Text)
1213
}
1314

1415
Function Test-CorrectionExtent
1516
{
1617
Param(
1718
[string] $violationFilepath,
18-
[Microsoft.Windows.PowerShell.ScriptAnalyzer.Generic.DiagnosticRecord] $diagnosticRecord,
19-
[int] $correctionsCount,
20-
[string] $violationText,
19+
[Microsoft.Windows.PowerShell.ScriptAnalyzer.Generic.DiagnosticRecord] $diagnosticRecord,
20+
[int] $correctionsCount,
21+
[string] $violationText,
2122
[string] $correctionText
2223
)
2324
$corrections = $diagnosticRecord.SuggestedCorrections

appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,4 @@ on_finish:
5656
@(
5757
# You can add other artifacts here
5858
(ls $zipFile)
59-
) | % { Push-AppveyorArtifact $_.FullName }
59+
) | % { Push-AppveyorArtifact $_.FullName }

0 commit comments

Comments
 (0)