forked from PowerShell/PowerShell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestModuleManifest.ps1
More file actions
127 lines (95 loc) · 6.02 KB
/
Copy pathTestModuleManifest.ps1
File metadata and controls
127 lines (95 loc) · 6.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
Import-Module $PSScriptRoot\..\..\Common\Test.Helpers.psm1
Describe "Test-ModuleManifest tests" -tags "CI" {
AfterEach {
Remove-Item -Recurse -Force -ErrorAction SilentlyContinue testdrive:/module
}
It "module manifest containing paths with backslashes or forwardslashes are resolved correctly" {
New-Item -ItemType Directory -Path testdrive:/module
New-Item -ItemType Directory -Path testdrive:/module/foo
New-Item -ItemType Directory -Path testdrive:/module/bar
New-Item -ItemType File -Path testdrive:/module/foo/bar.psm1
New-Item -ItemType File -Path testdrive:/module/bar/foo.psm1
$testModulePath = "testdrive:/module/test.psd1"
$fileList = "foo\bar.psm1","bar/foo.psm1"
New-ModuleManifest -NestedModules $fileList -RootModule foo\bar.psm1 -RequiredAssemblies $fileList -Path $testModulePath -TypesToProcess $fileList -FormatsToProcess $fileList -ScriptsToProcess $fileList -FileList $fileList -ModuleList $fileList
Test-Path $testModulePath | Should Be $true
# use -ErrorAction Stop to cause test to fail if Test-ModuleManifest writes to error stream
Test-ModuleManifest -Path $testModulePath -ErrorAction Stop | Should BeOfType System.Management.Automation.PSModuleInfo
}
It "module manifest containing missing files returns error" -TestCases (
@{parameter = "RequiredAssemblies"; error = "Modules_InvalidRequiredAssembliesInModuleManifest"},
@{parameter = "NestedModules"; error = "Modules_InvalidNestedModuleinModuleManifest"},
@{parameter = "RequiredModules"; error = "Modules_InvalidRequiredModulesinModuleManifest"},
@{parameter = "FileList"; error = "Modules_InvalidFilePathinModuleManifest"},
@{parameter = "ModuleList"; error = "Modules_InvalidModuleListinModuleManifest"},
@{parameter = "TypesToProcess"; error = "Modules_InvalidManifest"},
@{parameter = "FormatsToProcess"; error = "Modules_InvalidManifest"},
@{parameter = "RootModule"; error = "Modules_InvalidRootModuleInModuleManifest"},
@{parameter = "ScriptsToProcess"; error = "Modules_InvalidManifest"}
) {
param ($parameter, $error)
New-Item -ItemType Directory -Path testdrive:/module
New-Item -ItemType Directory -Path testdrive:/module/foo
New-Item -ItemType File -Path testdrive:/module/foo/bar.psm1
$testModulePath = "testdrive:/module/test.psd1"
$args = @{$parameter = "doesnotexist.psm1"}
New-ModuleManifest -Path $testModulePath @args
[string]$errorId = "$error,Microsoft.PowerShell.Commands.TestModuleManifestCommand"
{ Test-ModuleManifest -Path $testModulePath -ErrorAction Stop } | ShouldBeErrorId $errorId
}
It "module manifest containing valid unprocessed rootmodule file type succeeds" -TestCases (
@{rootModuleValue = "foo.psm1"},
@{rootModuleValue = "foo.dll"}
) {
param($rootModuleValue)
New-Item -ItemType Directory -Path testdrive:/module
$testModulePath = "testdrive:/module/test.psd1"
New-Item -ItemType File -Path testdrive:/module/$rootModuleValue
New-ModuleManifest -Path $testModulePath -RootModule $rootModuleValue
$moduleManifest = Test-ModuleManifest -Path $testModulePath -ErrorAction Stop
$moduleManifest | Should BeOfType System.Management.Automation.PSModuleInfo
$moduleManifest.RootModule | Should Be $rootModuleValue
}
It "module manifest containing valid processed empty rootmodule file type fails" -TestCases (
@{rootModuleValue = "foo.cdxml"; error = "System.Xml.XmlException"}, # fails when cmdlet tries to read it as XML
@{rootModuleValue = "foo.xaml"; error = "NotSupported"} # not supported on PowerShell Core
) {
param($rootModuleValue, $error)
New-Item -ItemType Directory -Path testdrive:/module
$testModulePath = "testdrive:/module/test.psd1"
New-Item -ItemType File -Path testdrive:/module/$rootModuleValue
New-ModuleManifest -Path $testModulePath -RootModule $rootModuleValue
{ Test-ModuleManifest -Path $testModulePath -ErrorAction Stop } | ShouldBeErrorId "$error,Microsoft.PowerShell.Commands.TestModuleManifestCommand"
}
It "module manifest containing empty rootmodule succeeds" -TestCases (
@{rootModuleValue = $null},
@{rootModuleValue = ""}
) {
param($rootModuleValue)
New-Item -ItemType Directory -Path testdrive:/module
$testModulePath = "testdrive:/module/test.psd1"
New-ModuleManifest -Path $testModulePath -RootModule $rootModuleValue
$moduleManifest = Test-ModuleManifest -Path $testModulePath -ErrorAction Stop
$moduleManifest | Should BeOfType System.Management.Automation.PSModuleInfo
$moduleManifest.RootModule | Should BeNullOrEmpty
}
It "module manifest containing invalid rootmodule returns error" -TestCases (
@{rootModuleValue = "foo.psd1"; error = "Modules_InvalidManifest"}
) {
param($rootModuleValue, $error)
$testModulePath = "testdrive:/module/test.psd1"
New-Item -ItemType Directory -Path testdrive:/module
New-Item -ItemType File -Path testdrive:/module/$rootModuleValue
New-ModuleManifest -Path $testModulePath -RootModule $rootModuleValue
{ Test-ModuleManifest -Path $testModulePath -ErrorAction Stop } | ShouldBeErrorId "$error,Microsoft.PowerShell.Commands.TestModuleManifestCommand"
}
It "module manifest containing non-existing rootmodule returns error" -TestCases (
@{rootModuleValue = "doesnotexist.psm1"; error = "Modules_InvalidRootModuleInModuleManifest"}
) {
param($rootModuleValue, $error)
$testModulePath = "testdrive:/module/test.psd1"
New-Item -ItemType Directory -Path testdrive:/module
New-ModuleManifest -Path $testModulePath -RootModule $rootModuleValue
{ Test-ModuleManifest -Path $testModulePath -ErrorAction Stop } | ShouldBeErrorId "$error,Microsoft.PowerShell.Commands.TestModuleManifestCommand"
}
}