Skip to content

Commit 804ead7

Browse files
author
Kapil Borle
committed
Fix failing tests
Sets the path of the test helper module correctly.
1 parent 7de186a commit 804ead7

4 files changed

Lines changed: 4 additions & 7 deletions

File tree

Tests/Rules/AvoidUsingAlias.tests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ $directory = Split-Path -Parent $MyInvocation.MyCommand.Path
55
$violationFilepath = Join-Path $directory 'AvoidUsingAlias.ps1'
66
$violations = Invoke-ScriptAnalyzer $violationFilepath | Where-Object {$_.RuleName -eq $violationName}
77
$noViolations = Invoke-ScriptAnalyzer $directory\AvoidUsingAliasNoViolations.ps1 | Where-Object {$_.RuleName -eq $violationName}
8+
Import-Module (Join-Path $directory "PSScriptAnalyzerTestHelper.psm1")
89

910
Describe "AvoidUsingAlias" {
1011
Context "When there are violations" {
@@ -17,7 +18,6 @@ Describe "AvoidUsingAlias" {
1718
}
1819

1920
It "suggests correction" {
20-
Import-Module .\PSScriptAnalyzerTestHelper.psm1
2121
Test-CorrectionExtent $violationFilepath $violations[0] 1 'iex' 'Invoke-Expression'
2222
$violations[0].SuggestedCorrections[0].Description | Should Be 'Replace iex with Invoke-Expression'
2323

Tests/Rules/AvoidUsingPlainTextForPassword.tests.ps1

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
Import-Module PSScriptAnalyzer
2-
32
$violationMessage = [regex]::Escape("Parameter '`$password' should use SecureString, otherwise this will expose sensitive information. See ConvertTo-SecureString for more information.")
43
$violationName = "PSAvoidUsingPlainTextForPassword"
54
$directory = Split-Path -Parent $MyInvocation.MyCommand.Path
65
$violationFilepath = Join-Path $directory 'AvoidUsingPlainTextForPassword.ps1'
76
$violations = Invoke-ScriptAnalyzer $violationFilepath | Where-Object {$_.RuleName -eq $violationName}
87
$noViolations = Invoke-ScriptAnalyzer $directory\AvoidUsingPlainTextForPasswordNoViolations.ps1 | Where-Object {$_.RuleName -eq $violationName}
8+
Import-Module (Join-Path $directory "PSScriptAnalyzerTestHelper.psm1")
99

1010
Describe "AvoidUsingPlainTextForPassword" {
1111
Context "When there are violations" {
@@ -14,7 +14,6 @@ Describe "AvoidUsingPlainTextForPassword" {
1414
}
1515

1616
It "suggests corrections" {
17-
Import-Module .\PSScriptAnalyzerTestHelper.psm1
1817
Test-CorrectionExtent $violationFilepath $violations[0] 1 '$passphrases' '[SecureString] $passphrases'
1918
$violations[0].SuggestedCorrections[0].Description | Should Be 'Set $passphrases type to SecureString'
2019

Tests/Rules/MisleadingBacktick.tests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ $directory = Split-Path -Parent $MyInvocation.MyCommand.Path
44
$violationFilepath = Join-Path $directory 'MisleadingBacktick.ps1'
55
$violations = Invoke-ScriptAnalyzer $violationFilepath | Where-Object {$_.RuleName -eq $writeHostName}
66
$noViolations = Invoke-ScriptAnalyzer $directory\NoMisleadingBacktick.ps1 | Where-Object {$_.RuleName -eq $clearHostName}
7+
Import-Module (Join-Path $directory "PSScriptAnalyzerTestHelper.psm1")
78

89
Describe "Avoid Misleading Backticks" {
910
Context "When there are violations" {
@@ -12,7 +13,6 @@ Describe "Avoid Misleading Backticks" {
1213
}
1314

1415
It "suggests correction" {
15-
Import-Module .\PSScriptAnalyzerTestHelper.psm1
1616
Test-CorrectionExtent $violationFilepath $violations[0] 1 ' ' ''
1717
Test-CorrectionExtent $violationFilepath $violations[1] 1 ' ' ''
1818
Test-CorrectionExtent $violationFilepath $violations[2] 1 ' ' ''

Tests/Rules/UseToExportFieldsInManifest.tests.ps1

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ $testManifestBadVariablesWildcardPath = "ManifestBadVariablesWildcard.psd1"
1010
$testManifestBadAllPath = "ManifestBadAll.psd1"
1111
$testManifestGoodPath = "ManifestGood.psd1"
1212
$testManifestInvalidPath = "ManifestInvalid.psd1"
13+
Import-Module (Join-Path $directory "PSScriptAnalyzerTestHelper.psm1")
1314

1415
Function Run-PSScriptAnalyzerRule
1516
{
@@ -40,7 +41,6 @@ Describe "UseManifestExportFields" {
4041
}
4142

4243
It "suggests corrections for FunctionsToExport with wildcard" {
43-
Import-Module .\PSScriptAnalyzerTestHelper.psm1
4444
$violations = Run-PSScriptAnalyzerRule $testManifestBadFunctionsWildcardPath
4545
$violationFilepath = Join-path $testManifestPath $testManifestBadFunctionsWildcardPath
4646
Test-CorrectionExtent $violationFilepath $violations[0] 1 "'*'" "@('Get-Foo', 'Get-Bar')"
@@ -54,7 +54,6 @@ Describe "UseManifestExportFields" {
5454
}
5555

5656
It "suggests corrections for FunctionsToExport with null" {
57-
Import-Module .\PSScriptAnalyzerTestHelper.psm1
5857
$violations = Run-PSScriptAnalyzerRule $testManifestBadFunctionsNullPath
5958
$violationFilepath = Join-path $testManifestPath $testManifestBadFunctionsNullPath
6059
Test-CorrectionExtent $violationFilepath $violations[0] 1 '$null' "@('Get-Foo', 'Get-Bar')"
@@ -84,7 +83,6 @@ Describe "UseManifestExportFields" {
8483
}
8584

8685
It "suggests corrections for AliasesToExport with wildcard" {
87-
Import-Module .\PSScriptAnalyzerTestHelper.psm1
8886
$violations = Run-PSScriptAnalyzerRule $testManifestBadAliasesWildcardPath
8987
$violationFilepath = Join-path $testManifestPath $testManifestBadAliasesWildcardPath
9088
Test-CorrectionExtent $violationFilepath $violations[0] 1 "'*'" "@('gfoo', 'gbar')"

0 commit comments

Comments
 (0)