1
1
Import-Module PSScriptAnalyzer
2
2
$directory = Split-Path - Parent $MyInvocation.MyCommand.Path
3
+ $testRootDirectory = Split-Path - Parent $directory
4
+ Import-Module (Join-Path $testRootDirectory ' PSScriptAnalyzerTestHelper.psm1' )
5
+
3
6
$testManifestPath = Join-Path $directory " TestManifest"
4
7
$testManifestBadFunctionsWildcardPath = " ManifestBadFunctionsWildcard.psd1"
5
8
$testManifestBadFunctionsWildcardInArrayPath = " ManifestBadFunctionsWildcardInArray.psd1"
@@ -12,7 +15,7 @@ $testManifestGoodPath = "ManifestGood.psd1"
12
15
$testManifestInvalidPath = " ManifestInvalid.psd1"
13
16
Import-Module (Join-Path $directory " PSScriptAnalyzerTestHelper.psm1" )
14
17
15
- Function Run-PSScriptAnalyzerRule
18
+ Function Run-PSScriptAnalyzerRule
16
19
{
17
20
Param (
18
21
[Parameter (Mandatory )]
@@ -28,37 +31,36 @@ Describe "UseManifestExportFields" {
28
31
Context " Invalid manifest file" {
29
32
It " does not process the manifest" {
30
33
$results = Run- PSScriptAnalyzerRule $testManifestInvalidPath
31
- $results | Should BeNullOrEmpty
32
- }
34
+ $results | Should BeNullOrEmpty
35
+ }
33
36
}
34
37
35
38
Context " Manifest contains violations" {
36
-
37
39
It " detects FunctionsToExport with wildcard" {
38
40
$results = Run- PSScriptAnalyzerRule $testManifestBadFunctionsWildcardPath
39
41
$results.Count | Should be 1
40
42
$results [0 ].Extent.Text | Should be " '*'"
41
43
}
42
44
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
+ }
49
51
50
52
It " detects FunctionsToExport with null" {
51
53
$results = Run- PSScriptAnalyzerRule $testManifestBadFunctionsNullPath
52
54
$results.Count | Should be 1
53
55
$results [0 ].Extent.Text | Should be ' $null'
54
56
}
55
57
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
+ }
62
64
63
65
It " detects array element containing wildcard" {
64
66
# if more than two elements contain wildcard we can show only the first one as of now.
@@ -69,7 +71,6 @@ Describe "UseManifestExportFields" {
69
71
70
72
}
71
73
72
-
73
74
It " detects CmdletsToExport with wildcard" {
74
75
$results = Run- PSScriptAnalyzerRule $testManifestBadCmdletsWildcardPath
75
76
$results.Count | Should be 1
@@ -82,11 +83,11 @@ Describe "UseManifestExportFields" {
82
83
$results [0 ].Extent.Text | Should be " '*'"
83
84
}
84
85
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
+ }
90
91
91
92
It " detects all the *ToExport violations" {
92
93
$results = Run- PSScriptAnalyzerRule $testManifestBadAllPath
@@ -98,7 +99,7 @@ Describe "UseManifestExportFields" {
98
99
It " detects all the *ToExport fields explicitly stating lists" {
99
100
$results = Run- PSScriptAnalyzerRule $testManifestGoodPath
100
101
$results.Count | Should be 0
101
- }
102
+ }
102
103
}
103
104
104
105
Context " When given a non module manifest file" {
0 commit comments