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