11Import-Module PSScriptAnalyzer
22$directory = Split-Path - Parent $MyInvocation.MyCommand.Path
3+ $testRootDirectory = Split-Path - Parent $directory
4+ Import-Module (Join-Path $testRootDirectory ' PSScriptAnalyzerTestHelper.psm1' )
5+
36$testManifestPath = Join-Path $directory " TestManifest"
47$testManifestBadFunctionsWildcardPath = " ManifestBadFunctionsWildcard.psd1"
58$testManifestBadFunctionsWildcardInArrayPath = " ManifestBadFunctionsWildcardInArray.psd1"
@@ -12,7 +15,7 @@ $testManifestGoodPath = "ManifestGood.psd1"
1215$testManifestInvalidPath = " ManifestInvalid.psd1"
1316Import-Module (Join-Path $directory " PSScriptAnalyzerTestHelper.psm1" )
1417
15- Function Run-PSScriptAnalyzerRule
18+ Function Run-PSScriptAnalyzerRule
1619{
1720 Param (
1821 [Parameter (Mandatory )]
@@ -28,37 +31,36 @@ Describe "UseManifestExportFields" {
2831 Context " Invalid manifest file" {
2932 It " does not process the manifest" {
3033 $results = Run- PSScriptAnalyzerRule $testManifestInvalidPath
31- $results | Should BeNullOrEmpty
32- }
34+ $results | Should BeNullOrEmpty
35+ }
3336 }
3437
3538 Context " Manifest contains violations" {
36-
3739 It " detects FunctionsToExport with wildcard" {
3840 $results = Run- PSScriptAnalyzerRule $testManifestBadFunctionsWildcardPath
3941 $results.Count | Should be 1
4042 $results [0 ].Extent.Text | Should be " '*'"
4143 }
4244
43- It " suggests corrections for FunctionsToExport with wildcard" {
44- $violations = Run- PSScriptAnalyzerRule $testManifestBadFunctionsWildcardPath
45- $violationFilepath = Join-path $testManifestPath $testManifestBadFunctionsWildcardPath
46- Test-CorrectionExtent $violationFilepath $violations [0 ] 1 " '*'" " @('Get-Bar', 'Get-Foo')"
47- $violations [0 ].SuggestedCorrections[0 ].Description | Should Be " Replace '*' with @('Get-Bar', 'Get-Foo')"
48- }
45+ It " suggests corrections for FunctionsToExport with wildcard" {
46+ $violations = Run- PSScriptAnalyzerRule $testManifestBadFunctionsWildcardPath
47+ $violationFilepath = Join-path $testManifestPath $testManifestBadFunctionsWildcardPath
48+ Test-CorrectionExtent $violationFilepath $violations [0 ] 1 " '*'" " @('Get-Bar', 'Get-Foo')"
49+ $violations [0 ].SuggestedCorrections[0 ].Description | Should Be " Replace '*' with @('Get-Bar', 'Get-Foo')"
50+ }
4951
5052 It " detects FunctionsToExport with null" {
5153 $results = Run- PSScriptAnalyzerRule $testManifestBadFunctionsNullPath
5254 $results.Count | Should be 1
5355 $results [0 ].Extent.Text | Should be ' $null'
5456 }
5557
56- It " suggests corrections for FunctionsToExport with null and line wrapping" {
57- $violations = Run- PSScriptAnalyzerRule $testManifestBadFunctionsNullPath
58- $violationFilepath = Join-path $testManifestPath $testManifestBadFunctionsNullPath
59- $expectedCorrectionExtent = " @('Get-Foo1', 'Get-Foo10', 'Get-Foo11', 'Get-Foo12', 'Get-Foo2', 'Get-Foo3', {0}`t`t 'Get-Foo4', 'Get-Foo5', 'Get-Foo6', 'Get-Foo7', 'Get-Foo8', {0}`t`t 'Get-Foo9')" -f [System.Environment ]::NewLine
60- Test-CorrectionExtent $violationFilepath $violations [0 ] 1 ' $null' $expectedCorrectionExtent
61- }
58+ It " suggests corrections for FunctionsToExport with null and line wrapping" {
59+ $violations = Run- PSScriptAnalyzerRule $testManifestBadFunctionsNullPath
60+ $violationFilepath = Join-path $testManifestPath $testManifestBadFunctionsNullPath
61+ $expectedCorrectionExtent = " @('Get-Foo1', 'Get-Foo10', 'Get-Foo11', 'Get-Foo12', 'Get-Foo2', 'Get-Foo3', {0}`t`t 'Get-Foo4', 'Get-Foo5', 'Get-Foo6', 'Get-Foo7', 'Get-Foo8', {0}`t`t 'Get-Foo9')" -f [System.Environment ]::NewLine
62+ Test-CorrectionExtent $violationFilepath $violations [0 ] 1 ' $null' $expectedCorrectionExtent
63+ }
6264
6365 It " detects array element containing wildcard" {
6466 # if more than two elements contain wildcard we can show only the first one as of now.
@@ -69,7 +71,6 @@ Describe "UseManifestExportFields" {
6971
7072 }
7173
72-
7374 It " detects CmdletsToExport with wildcard" {
7475 $results = Run- PSScriptAnalyzerRule $testManifestBadCmdletsWildcardPath
7576 $results.Count | Should be 1
@@ -82,11 +83,11 @@ Describe "UseManifestExportFields" {
8283 $results [0 ].Extent.Text | Should be " '*'"
8384 }
8485
85- It " suggests corrections for AliasesToExport with wildcard" {
86- $violations = Run- PSScriptAnalyzerRule $testManifestBadAliasesWildcardPath
87- $violationFilepath = Join-path $testManifestPath $testManifestBadAliasesWildcardPath
88- Test-CorrectionExtent $violationFilepath $violations [0 ] 1 " '*'" " @('gbar', 'gfoo')"
89- }
86+ It " suggests corrections for AliasesToExport with wildcard" {
87+ $violations = Run- PSScriptAnalyzerRule $testManifestBadAliasesWildcardPath
88+ $violationFilepath = Join-path $testManifestPath $testManifestBadAliasesWildcardPath
89+ Test-CorrectionExtent $violationFilepath $violations [0 ] 1 " '*'" " @('gbar', 'gfoo')"
90+ }
9091
9192 It " detects all the *ToExport violations" {
9293 $results = Run- PSScriptAnalyzerRule $testManifestBadAllPath
@@ -98,7 +99,7 @@ Describe "UseManifestExportFields" {
9899 It " detects all the *ToExport fields explicitly stating lists" {
99100 $results = Run- PSScriptAnalyzerRule $testManifestGoodPath
100101 $results.Count | Should be 0
101- }
102+ }
102103 }
103104
104105 Context " When given a non module manifest file" {
0 commit comments