mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Add test coverage for additional Get-Module parameters (#8137)
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
# Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
# Licensed under the MIT License.
|
||||
|
||||
Describe "Get-Module" -Tags "CI" {
|
||||
Describe "Get-Module -ListAvailable" -Tags "CI" {
|
||||
|
||||
BeforeAll {
|
||||
$originalPSModulePath = $env:PSModulePath
|
||||
@@ -99,4 +99,53 @@ Describe "Get-Module" -Tags "CI" {
|
||||
$modules.Name -join "," | Should -BeExactly "Bar,Foo,Foo,Zoo,Zoo"
|
||||
$modules[3].Path | Should -BeExactly (Resolve-Path "$testdrive\Modules\Zoo\Too\Zoo.psm1").Path
|
||||
}
|
||||
|
||||
It "Get-Module -FullyQualifiedName <FullyQualifiedName> -ListAvailable" {
|
||||
$moduleSpecification = @{ModuleName = "Foo"; ModuleVersion = "2.0"}
|
||||
$modules = Get-Module -FullyQualifiedName $moduleSpecification -ListAvailable
|
||||
$modules | Should -HaveCount 1
|
||||
$modules.Name | Should -BeExactly "Foo"
|
||||
$modules.Version | Should -BeExactly "2.0"
|
||||
}
|
||||
|
||||
It "Get-Module <Name> -Refresh -ListAvailable" {
|
||||
$modules = Get-Module -Name 'Zoo' -ListAvailable
|
||||
$modules | Should -HaveCount 1
|
||||
$modules.Name | Should -BeExactly "Zoo"
|
||||
$modules.ExportedFunctions.Count | Should -Be 0 -Because 'No exports were defined'
|
||||
|
||||
New-ModuleManifest -Path "$testdrive\Modules\Zoo\Zoo.psd1" -FunctionsToExport 'Test-ZooFunction'
|
||||
|
||||
$modules = Get-Module -Name 'Zoo' -ListAvailable -Refresh
|
||||
$modules | Should -HaveCount 1
|
||||
$modules.Name | Should -BeExactly "Zoo"
|
||||
$modules.ExportedFunctions.Count | Should -Be 1 -Because 'We added a new function to export'
|
||||
}
|
||||
|
||||
Context "PSEdition" {
|
||||
|
||||
BeforeAll {
|
||||
New-Item -ItemType Directory -Path "$testdrive\Modules\DesktopOnlyModule" -Force > $null
|
||||
New-Item -ItemType Directory -Path "$testdrive\Modules\CoreOnlyModule" -Force > $null
|
||||
New-Item -ItemType Directory -Path "$testdrive\Modules\CoreAndDesktopModule" -Force > $null
|
||||
|
||||
New-ModuleManifest -Path "$testdrive\Modules\DesktopOnlyModule\DesktopOnlyModule.psd1" -CompatiblePSEditions Desktop
|
||||
New-ModuleManifest -Path "$testdrive\Modules\CoreOnlyModule\CoreOnlyModule.psd1" -CompatiblePSEditions Core
|
||||
New-ModuleManifest -Path "$testdrive\Modules\CoreAndDesktopModule\CoreAndDesktopModule.psd1" -CompatiblePSEditions Core, Desktop
|
||||
|
||||
New-Item -ItemType File -Path "$testdrive\Modules\DesktopOnlyModule\DesktopOnlyModule.psm1" > $null
|
||||
New-Item -ItemType File -Path "$testdrive\Modules\CoreOnlyModule\CoreOnlyModule.psm1" > $null
|
||||
New-Item -ItemType File -Path "$testdrive\Modules\CoreAndDesktopModule\CoreAndDesktopModule.psm1" > $null
|
||||
}
|
||||
|
||||
It "Get-Module -PSEdition <CompatiblePSEditions> -ListAvailable" -TestCases @(
|
||||
@{ CompatiblePSEditions = 'Desktop'; ExpectedModule = 'CoreAndDesktopModule', 'DesktopOnlyModule' },
|
||||
@{ CompatiblePSEditions = 'Core' ; ExpectedModule = 'CoreAndDesktopModule', 'CoreOnlyModule' }
|
||||
) {
|
||||
param ($CompatiblePSEditions, $ExpectedModule)
|
||||
$modules = Get-Module -PSEdition $CompatiblePSEditions -ListAvailable
|
||||
$modules | Should -HaveCount $ExpectedModule.Count
|
||||
$modules.Name | Sort-Object | Should -BeExactly $ExpectedModule
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user