|
| 1 | +#requires -Module ModuleBuilder |
| 2 | +Describe "ImportModuleManifest" { |
| 3 | + |
| 4 | + Context "Mandatory Parameter" { |
| 5 | + $CommandInfo = InModuleScope ModuleBuilder { Get-Command ImportModuleManifest } |
| 6 | + |
| 7 | + It 'has a mandatory Path parameter for the PSPath by pipeline' { |
| 8 | + $Path = $CommandInfo.Parameters['Path'] |
| 9 | + $Path | Should -Not -BeNullOrEmpty |
| 10 | + $Path.ParameterType | Should -Be ([string]) |
| 11 | + $Path.Aliases | Should -Be ("PSPath") |
| 12 | + $Path.Attributes.Where{ $_ -is [Parameter] }.Mandatory | Should -Be $true |
| 13 | + $Path.Attributes.Where{ $_ -is [Parameter] }.ValueFromPipelineByPropertyName | Should -Be $true |
| 14 | + } |
| 15 | + |
| 16 | + } |
| 17 | + |
| 18 | + Context "Parsing Manifests" { |
| 19 | + It "Does not cause errors for non-existent root modules" { |
| 20 | + New-ModuleManifest -Path TestDrive:\BadRoot.psd1 -Author TestName -RootModule NoSuchFile |
| 21 | + |
| 22 | + InModuleScope ModuleBuilder { |
| 23 | + ImportModuleManifest -Path TestDrive:\BadRoot.psd1 -ErrorAction Stop |
| 24 | + } |
| 25 | + } |
| 26 | + |
| 27 | + It "Returns the ModuleInfo with DefaultCommandPrefix instead of Prefix" { |
| 28 | + New-ModuleManifest -Path TestDrive:\TestPrefix.psd1 -Author TestName -DefaultCommandPrefix PrePre |
| 29 | + |
| 30 | + $Prefix = InModuleScope ModuleBuilder { |
| 31 | + $DebugPreference = "Continue" |
| 32 | + Get-ChildItem TestDrive:\TestPrefix.psd1 | ImportModuleManifest |
| 33 | + $DebugPreference = "SilentlyContinue" |
| 34 | + } |
| 35 | + |
| 36 | + $Prefix.Prefix | Should -BeNullOrEmpty |
| 37 | + $Prefix.DefaultCommandPrefix | Should -Be "PrePre" |
| 38 | + } |
| 39 | + |
| 40 | + It "Does cause errors for manifests that are invalid" { |
| 41 | + New-ModuleManifest -Path TestDrive:\Invalid.psd1 -Author TestName -ModuleVersion "1.0.0" |
| 42 | + Set-Content TestDrive:\Invalid.psd1 ( |
| 43 | + (Get-Content -Path TestDrive:\Invalid.psd1 -Raw) -replace "1.0.0" |
| 44 | + ) |
| 45 | + |
| 46 | + { |
| 47 | + InModuleScope ModuleBuilder { |
| 48 | + ImportModuleManifest -Path TestDrive:\Invalid.psd1 -ErrorAction Stop -WarningAction Stop |
| 49 | + } |
| 50 | + } | Should -Throw |
| 51 | + } |
| 52 | + } |
| 53 | + |
| 54 | + Context "Invalid module manifest" { |
| 55 | + # In the current PowerShell 5.1 and 6.1 |
| 56 | + # We can't make Get-Module -ListAvailable throw on a manifest |
| 57 | + # So I can't test the if($Problems = ... code |
| 58 | + } |
| 59 | +} |
0 commit comments