From 3266d6a027eec63d12c34ab6b8ca92081a79ecec Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Sat, 29 Feb 2020 18:12:05 +0100 Subject: [PATCH 1/2] Fixes a bug to find module manifest when there are no build manifest --- Source/Private/GetBuildInfo.ps1 | 12 +++++----- Tests/Integration/Source1.Tests.ps1 | 34 ++++++++++++++++++++++++++++- 2 files changed, 39 insertions(+), 7 deletions(-) diff --git a/Source/Private/GetBuildInfo.ps1 b/Source/Private/GetBuildInfo.ps1 index 458e6e3..bdebdff 100644 --- a/Source/Private/GetBuildInfo.ps1 +++ b/Source/Private/GetBuildInfo.ps1 @@ -77,16 +77,13 @@ function GetBuildInfo { } Write-Debug "Finished parsing Build Manifest $BuildManifest" - $BuildInfo = $BuildInfo | Update-Object $ParameterValues - Write-Debug "Using Module Manifest $($BuildInfo.SourcePath)" - $BuildManifestParent = if ($BuildManifest) { Split-Path -Parent $BuildManifest } else { Get-Location -PSProvider FileSystem } - if (-Not $BuildInfo.SourcePath) { + if ((-not $BuildInfo.SourcePath) -and $ParameterValues["SourcePath"] -notmatch '\.psd1') { # Find a module manifest (or maybe several) $ModuleInfo = Get-ChildItem $BuildManifestParent -Recurse -Filter *.psd1 -ErrorAction SilentlyContinue | ImportModuleManifest -ErrorAction SilentlyContinue @@ -102,13 +99,16 @@ function GetBuildInfo { } if (@($ModuleInfo).Count -eq 1) { Write-Debug "Updating BuildInfo SourcePath to $($ModuleInfo.Path)" - $BuildInfo = $BuildInfo | Update-Object @{ SourcePath = $ModuleInfo.Path } + $ParameterValues["SourcePath"] = $ModuleInfo.Path } - if (-Not $BuildInfo.SourcePath) { + if (-Not $ModuleInfo) { throw "Can't find a module manifest in $BuildManifestParent" } } + $BuildInfo = $BuildInfo | Update-Object $ParameterValues + Write-Debug "Using Module Manifest $($BuildInfo.SourcePath)" + # Make sure the SourcePath is absolute and points at an actual file if (!(Split-Path -IsAbsolute $BuildInfo.SourcePath) -and $BuildManifestParent) { $BuildInfo.SourcePath = Join-Path $BuildManifestParent $BuildInfo.SourcePath | Convert-Path diff --git a/Tests/Integration/Source1.Tests.ps1 b/Tests/Integration/Source1.Tests.ps1 index fab20ad..f076306 100644 --- a/Tests/Integration/Source1.Tests.ps1 +++ b/Tests/Integration/Source1.Tests.ps1 @@ -88,7 +88,7 @@ Describe "Regression test for #84: Multiple Aliases per command will Export" -Ta } Describe "Supports building without a build.psd1" -Tag Integration { - Copy-Item $PSScriptRoot\Source1 TestDrive:\Source1 -Recurse + Copy-Item $PSScriptRoot\Source1 TestDrive:\Source1 -Recurse Remove-Item TestDrive:\Source1\build.psd1 $Build = @{ } @@ -115,6 +115,38 @@ Describe "Supports building without a build.psd1" -Tag Integration { $Build.Metadata.FunctionsToExport | Should -Be @("Get-Source", "Set-Source") } } +Describe "Supports building without a build.psd1 and not specifying a module manifest" -Tag Integration { + Copy-Item $PSScriptRoot\Source1 TestDrive:\source -Recurse + Remove-Item TestDrive:\source\build.psd1 + + Push-Location -StackName 'IntegrationTest' -Path TestDrive:\ + + $Build = @{ } + + It "No longer fails if there's no build.psd1" { + $BuildParameters = @{ + SourcePath = "TestDrive:\source" + OutputDirectory = "TestDrive:\Result1" + VersionedOutputDirectory = $true + } + + $Build.Output = Build-Module @BuildParameters -Passthru + } + + It "Creates the same module as with a build.psd1" { + $Build.Metadata = Import-Metadata $Build.Output.Path + } + + It "Should update AliasesToExport in the manifest" { + $Build.Metadata.AliasesToExport | Should -Be @("GS", "GSou", "SS", "SSou") + } + + It "Should update FunctionsToExport in the manifest" { + $Build.Metadata.FunctionsToExport | Should -Be @("Get-Source", "Set-Source") + } + + Pop-Location -StackName 'IntegrationTest' +} Describe "Regression test for #88 not copying prefix files" -Tag Integration, Regression { $Output = Build-Module $PSScriptRoot\build.psd1 -Passthru From 84709a8e27f22513c0af9eadb4bd255762ee1807 Mon Sep 17 00:00:00 2001 From: Joel Bennett Date: Sat, 29 Feb 2020 22:21:28 -0500 Subject: [PATCH 2/2] Make the "same module" tests more significant --- Tests/Integration/Source1.Tests.ps1 | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/Tests/Integration/Source1.Tests.ps1 b/Tests/Integration/Source1.Tests.ps1 index f076306..c32c291 100644 --- a/Tests/Integration/Source1.Tests.ps1 +++ b/Tests/Integration/Source1.Tests.ps1 @@ -89,6 +89,13 @@ Describe "Regression test for #84: Multiple Aliases per command will Export" -Ta Describe "Supports building without a build.psd1" -Tag Integration { Copy-Item $PSScriptRoot\Source1 TestDrive:\Source1 -Recurse + # This is the old build, with a build.psd1 + $Output = Build-Module TestDrive:\Source1\build.psd1 -Passthru + $ManifestContent = Get-Content $Output.Path + $ModuleContent = Get-Content ([IO.Path]::ChangeExtension($Output.Path, ".psm1")) + Remove-Item (Split-Path $Output.Path) -Recurse + + # Then remove the build.psd1 and rebuild it Remove-Item TestDrive:\Source1\build.psd1 $Build = @{ } @@ -105,6 +112,8 @@ Describe "Supports building without a build.psd1" -Tag Integration { It "Creates the same module as with a build.psd1" { $Build.Metadata = Import-Metadata $Build.Output.Path + Get-Content $Build.Output.Path | Should -Be $ManifestContent + Get-Content ([IO.Path]::ChangeExtension($Build.Output.Path, ".psm1")) | Should -Be $ModuleContent } It "Should update AliasesToExport in the manifest" { @@ -115,8 +124,16 @@ Describe "Supports building without a build.psd1" -Tag Integration { $Build.Metadata.FunctionsToExport | Should -Be @("Get-Source", "Set-Source") } } -Describe "Supports building without a build.psd1 and not specifying a module manifest" -Tag Integration { +Describe "Supports building discovering the module without a build.psd1" -Tag Integration { Copy-Item $PSScriptRoot\Source1 TestDrive:\source -Recurse + + # This is the old build, with a build.psd1 + $Output = Build-Module TestDrive:\source\build.psd1 -Passthru + $ManifestContent = Get-Content $Output.Path + $ModuleContent = Get-Content ([IO.Path]::ChangeExtension($Output.Path, ".psm1")) + Remove-Item (Split-Path $Output.Path) -Recurse + + # Then remove the build.psd1 and rebuild it Remove-Item TestDrive:\source\build.psd1 Push-Location -StackName 'IntegrationTest' -Path TestDrive:\ @@ -124,17 +141,13 @@ Describe "Supports building without a build.psd1 and not specifying a module man $Build = @{ } It "No longer fails if there's no build.psd1" { - $BuildParameters = @{ - SourcePath = "TestDrive:\source" - OutputDirectory = "TestDrive:\Result1" - VersionedOutputDirectory = $true - } - - $Build.Output = Build-Module @BuildParameters -Passthru + $Build.Output = Build-Module -Passthru } It "Creates the same module as with a build.psd1" { $Build.Metadata = Import-Metadata $Build.Output.Path + Get-Content $Build.Output.Path | Should -Be $ManifestContent + Get-Content ([IO.Path]::ChangeExtension($Build.Output.Path, ".psm1")) | Should -Be $ModuleContent } It "Should update AliasesToExport in the manifest" {