8000 Support importing module paths that end in trailing directory separator by SteveL-MSFT · Pull Request #6602 · PowerShell/PowerShell · GitHub
[go: up one dir, main page]

Skip to content

Support importing module paths that end in trailing directory separator #6602

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 13, 2018
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
0