Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,12 @@ private PSModuleInfo ImportModule_LocallyViaName(ImportModuleOptions importModul
}
else if (Directory.Exists(rootedPath))
{
// If the path ends with a directory separator, remove it
if (rootedPath.EndsWith(Path.DirectorySeparatorChar))
{
rootedPath = Path.GetDirectoryName(rootedPath);
}

// Load the latest valid version if it is a multi-version module directory
foundModule = LoadUsingMultiVersionModuleBase(rootedPath,
ManifestProcessingFlags.LoadElements |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Describe "Import-Module" -Tags "CI" {
BeforeEach {
Remove-Module -Name $moduleName -Force
(Get-Module -Name $moduleName).Name | Should -BeNullOrEmpty
Remove-Module -Name TestModule -Force -ErrorAction SilentlyContinue
}

AfterEach {
Expand All @@ -30,6 +31,15 @@ Describe "Import-Module" -Tags "CI" {
(Get-Module -Name $moduleName).Name | Should -BeExactly $moduleName
}

It "should be able to load a module with a trailing directory separator: <modulePath>" -TestCases @(
@{ modulePath = (Get-Module -ListAvailable $moduleName).ModuleBase + [System.IO.Path]::DirectorySeparatorChar; expectedName = $moduleName },
@{ modulePath = Join-Path -Path $TestDrive -ChildPath "\Modules\TestModule\"; expectedName = "TestModule" }
) {
param( $modulePath, $expectedName )
{ Import-Module -Name $modulePath -ErrorAction Stop } | Should -Not -Throw
(Get-Module -Name $expectedName).Name | Should -BeExactly $expectedName
}

It "should be able to add a module with using ModuleInfo switch" {
$a = Get-Module -ListAvailable $moduleName
{ Import-Module -ModuleInfo $a } | Should -Not -Throw
Expand Down