From 2f8f81a3fc639bebe431c437596ec5c0bcba0e2f Mon Sep 17 00:00:00 2001 From: Andrew Date: Wed, 14 Jun 2017 12:29:39 -0700 Subject: [PATCH 1/3] IPMO fix for some cases of NestedModules/RootModule path syntax --- .../engine/Modules/ModuleCmdletBase.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/System.Management.Automation/engine/Modules/ModuleCmdletBase.cs b/src/System.Management.Automation/engine/Modules/ModuleCmdletBase.cs index 7c5857db3a3..a71f93519c5 100644 --- a/src/System.Management.Automation/engine/Modules/ModuleCmdletBase.cs +++ b/src/System.Management.Automation/engine/Modules/ModuleCmdletBase.cs @@ -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); From 7d034924369832a4a74c083251455e68a753cddc Mon Sep 17 00:00:00 2001 From: Andrew Date: Wed, 14 Jun 2017 12:33:26 -0700 Subject: [PATCH 2/3] Added tests for #3693 fix --- .../Module/SubmodulePathInManifest.Tests.ps1 | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 test/powershell/engine/Module/SubmodulePathInManifest.Tests.ps1 diff --git a/test/powershell/engine/Module/SubmodulePathInManifest.Tests.ps1 b/test/powershell/engine/Module/SubmodulePathInManifest.Tests.ps1 new file mode 100644 index 00000000000..3c3987b020c --- /dev/null +++ b/test/powershell/engine/Module/SubmodulePathInManifest.Tests.ps1 @@ -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 " -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 " -TestCases $testCases { + param($SubModulePath) + + New-ModuleManifest $moduleFilePath -RootModule $SubModulePath + Import-Module $moduleFilePath + (Get-Module $moduleName).ExportedCommands.Keys.Contains('TestModuleFunction') | Should Be $true + } +} \ No newline at end of file From 56daa5153242ef53b5de7011464ed646c673a591 Mon Sep 17 00:00:00 2001 From: Andrew Date: Mon, 19 Jun 2017 15:34:09 -0700 Subject: [PATCH 3/3] Updated tests --- test/powershell/engine/Module/SubmodulePathInManifest.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/powershell/engine/Module/SubmodulePathInManifest.Tests.ps1 b/test/powershell/engine/Module/SubmodulePathInManifest.Tests.ps1 index 3c3987b020c..25c14a41730 100644 --- a/test/powershell/engine/Module/SubmodulePathInManifest.Tests.ps1 +++ b/test/powershell/engine/Module/SubmodulePathInManifest.Tests.ps1 @@ -51,4 +51,4 @@ Import-Module $moduleFilePath (Get-Module $moduleName).ExportedCommands.Keys.Contains('TestModuleFunction') | Should Be $true } -} \ No newline at end of file +}