FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Fixing Import-Module on Linux for special cases of NestedModules/RootModule path format by anmenaga · Pull Request #4010 · PowerShell/PowerShell · GitHub

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

Filter by extension

Filter by extension .cs  (1) .ps1  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -613,19 +613,18 @@ private PSModuleInfo LoadModuleNamedInManifest(PSModuleInfo parentModule, Module
Guid? savedBaseGuid = BaseGuid;

var importingModule = 0 != (manifestProcessingFlags & ManifestProcessingFlags.LoadElements);

string extension = Path.GetExtension(moduleSpecification.Name);
// First check for fully-qualified paths - either absolute or relative
string rootedPath = ResolveRootedFilePath(moduleSpecification.Name, this.Context);
if (String.IsNullOrEmpty(rootedPath))
{
rootedPath = Path.Combine(moduleBase, moduleSpecification.Name);
rootedPath = FixupFileName(moduleBase, moduleSpecification.Name, extension);
}
else
{
wasRooted = true;
}

string extension = Path.GetExtension(moduleSpecification.Name);
try
{
this.Context.Modules.IncrementModuleNestingDepth(this, rootedPath);
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
Describe "Tests for paths of submodules in module manifest" -tags "CI" {

$moduleName = 'ModuleA'
$moduleFileName = "$moduleName.psd1"
$submoduleName = 'ModuleB'
$submoduleFileName = "$submoduleName.psm1"
$moduleRootPath = Join-Path $TestDrive $moduleName
$moduleFilePath = Join-Path $moduleRootPath $moduleFileName
$nestedModulePath = Join-Path $moduleRootPath $submoduleName
$nestedModuleFilePath = Join-Path $nestedModulePath $submoduleFileName

BeforeEach {

Remove-Module $moduleName -Force -ErrorAction SilentlyContinue
Remove-Item $moduleRootPath -Recurse -Force -ErrorAction SilentlyContinue

New-Item -ItemType Directory -Force -Path $nestedModulePath
"function TestModuleFunction{'Hello from TestModuleFunction'}" | Out-File $nestedModuleFilePath
}

$testCases = @(
@{ SubModulePath = "$submoduleName" }
@{ SubModulePath = "$submoduleName\$submoduleName" }
@{ SubModulePath = "$submoduleName/$submoduleName" }
@{ SubModulePath = "$submoduleName\$submoduleFileName" }
@{ SubModulePath = "$submoduleName/$submoduleFileName" }
@{ SubModulePath = ".\$submoduleName" }
@{ SubModulePath = ".\$submoduleName\$submoduleName" }
@{ SubModulePath = ".\$submoduleName/$submoduleName" }
@{ SubModulePath = ".\$submoduleName\$submoduleFileName" }
@{ SubModulePath = ".\$submoduleName/$submoduleFileName" }
@{ SubModulePath = "./$submoduleName" }
@{ SubModulePath = "./$submoduleName/$submoduleName" }
@{ SubModulePath = "./$submoduleName\$submoduleName" }
@{ SubModulePath = "./$submoduleName/$submoduleFileName" }
@{ SubModulePath = "./$submoduleName\$submoduleFileName" }
)

It "Test if NestedModule path is <SubModulePath>" -TestCases $testCases {
param($SubModulePath)

New-ModuleManifest $moduleFilePath -NestedModules @($SubModulePath)
Import-Module $moduleFilePath
(Get-Module $moduleName).ExportedCommands.Keys.Contains('TestModuleFunction') | Should Be $true
}

It "Test if RootModule path is <SubModulePath>" -TestCases $testCases {
param($SubModulePath)

New-ModuleManifest $moduleFilePath -RootModule $SubModulePath
Import-Module $moduleFilePath
(Get-Module $moduleName).ExportedCommands.Keys.Contains('TestModuleFunction') | Should Be $true
}
}

Back | FazBrowse Home | New Git URL