From c6a012e08ae4c96d4fa6be69ba6aeeb4928189ae Mon Sep 17 00:00:00 2001 From: Joel Bennett Date: Thu, 7 Mar 2024 02:01:16 -0500 Subject: [PATCH] Add regression tests for build.psd1 parameters --- Tests/Integration/Parameters.Tests.ps1 | 29 ++++++++++ Tests/Integration/Parameters/Parameters.psd1 | 56 +++++++++++++++++++ .../Parameters/Private/GetFinale.ps1 | 7 +++ .../Parameters/Private/GetMyAlias.ps1 | 1 + .../Parameters/Private/GetPreview.ps1 | 7 +++ .../Private/TestUnExportedAliases.ps1 | 13 +++++ .../Parameters/Public/Get-Source.ps1 | 7 +++ .../Parameters/Public/Set-Source.ps1 | 6 ++ Tests/Integration/Parameters/build.psd1 | 7 +++ .../Integration/Result3/Parameters/ReadMe.md | 0 10 files changed, 133 insertions(+) create mode 100644 Tests/Integration/Parameters.Tests.ps1 create mode 100644 Tests/Integration/Parameters/Parameters.psd1 create mode 100644 Tests/Integration/Parameters/Private/GetFinale.ps1 create mode 100644 Tests/Integration/Parameters/Private/GetMyAlias.ps1 create mode 100644 Tests/Integration/Parameters/Private/GetPreview.ps1 create mode 100644 Tests/Integration/Parameters/Private/TestUnExportedAliases.ps1 create mode 100644 Tests/Integration/Parameters/Public/Get-Source.ps1 create mode 100644 Tests/Integration/Parameters/Public/Set-Source.ps1 create mode 100644 Tests/Integration/Parameters/build.psd1 create mode 100644 Tests/Integration/Result3/Parameters/ReadMe.md diff --git a/Tests/Integration/Parameters.Tests.ps1 b/Tests/Integration/Parameters.Tests.ps1 new file mode 100644 index 0000000..6206696 --- /dev/null +++ b/Tests/Integration/Parameters.Tests.ps1 @@ -0,0 +1,29 @@ +#requires -Module ModuleBuilder +. $PSScriptRoot\..\Convert-FolderSeparator.ps1 + +Describe "Parameters.Set in build manifest" -Tag Integration { + BeforeAll { + New-Item $PSScriptRoot\Result3\Parameters\ReadMe.md -ItemType File -Force + $Output = Build-Module $PSScriptRoot\Parameters\build.psd1 + if ($Output) { + $Module = [IO.Path]::ChangeExtension($Output.Path, "psm1") + $Metadata = Import-Metadata $Output.Path + } + } + + It "Passthru works" { + $Output | Should -Not -BeNullOrEmpty + } + + It "The Target is Build" { + "$PSScriptRoot\Result3\Parameters\ReadMe.md" | Should -Exist + } + + It "The version is set" { + $Metadata.ModuleVersion | Should -Be "3.0.0" + } + + It "The PreRelease is set" { + $Metadata.PrivateData.PSData.Prerelease | Should -Be 'alpha001' + } +} diff --git a/Tests/Integration/Parameters/Parameters.psd1 b/Tests/Integration/Parameters/Parameters.psd1 new file mode 100644 index 0000000..fa936e4 --- /dev/null +++ b/Tests/Integration/Parameters/Parameters.psd1 @@ -0,0 +1,56 @@ +@{ + # The module version should be SemVer.org compatible + ModuleVersion = "1.0.0" + + # PrivateData is where all third-party metadata goes + PrivateData = @{ + # PrivateData.PSData is the PowerShell Gallery data + PSData = @{ + # Prerelease string should be here, so we can set it + Prerelease = '' + + # Release Notes have to be here, so we can update them + ReleaseNotes = ' + A test module + ' + + # Tags applied to this module. These help with module discovery in online galleries. + Tags = 'Authoring','Build','Development','BestPractices' + + # A URL to the license for this module. + LicenseUri = 'https://github.com/PoshCode/ModuleBuilder/blob/master/LICENSE' + + # A URL to the main website for this project. + ProjectUri = 'https://github.com/PoshCode/ModuleBuilder' + + # A URL to an icon representing this module. + IconUri = 'https://github.com/PoshCode/ModuleBuilder/blob/resources/ModuleBuilder.png?raw=true' + } # End of PSData + } # End of PrivateData + + # The main script module that is automatically loaded as part of this module + RootModule = 'Parameters.psm1' + + # Modules that must be imported into the global environment prior to importing this module + RequiredModules = @() + + # Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix. + DefaultCommandPrefix = 'Param' + + # Always define FunctionsToExport as an empty @() which will be replaced on build + FunctionsToExport = @() + AliasesToExport = @() + + # ID used to uniquely identify this module + GUID = 'a264e183-e0f7-4219-bc80-c30d14e0e98e' + Description = 'A module for authoring and building PowerShell modules' + + # Common stuff for all our modules: + CompanyName = 'PoshCode' + Author = 'Joel Bennett' + Copyright = "Copyright 2024 Joel Bennett" + + # Minimum version of the Windows PowerShell engine required by this module + PowerShellVersion = '5.1' + CompatiblePSEditions = @('Core','Desktop') +} diff --git a/Tests/Integration/Parameters/Private/GetFinale.ps1 b/Tests/Integration/Parameters/Private/GetFinale.ps1 new file mode 100644 index 0000000..b6ed530 --- /dev/null +++ b/Tests/Integration/Parameters/Private/GetFinale.ps1 @@ -0,0 +1,7 @@ +using module ModuleBuilder + +function GetFinale { + [CmdletBinding()] + # [Alias("gf")] + param() +} diff --git a/Tests/Integration/Parameters/Private/GetMyAlias.ps1 b/Tests/Integration/Parameters/Private/GetMyAlias.ps1 new file mode 100644 index 0000000..dcfd009 --- /dev/null +++ b/Tests/Integration/Parameters/Private/GetMyAlias.ps1 @@ -0,0 +1 @@ +New-Alias -Name 'Get-MyAlias' -Value 'Get-ChildItem' diff --git a/Tests/Integration/Parameters/Private/GetPreview.ps1 b/Tests/Integration/Parameters/Private/GetPreview.ps1 new file mode 100644 index 0000000..1c822c5 --- /dev/null +++ b/Tests/Integration/Parameters/Private/GetPreview.ps1 @@ -0,0 +1,7 @@ +using module ModuleBuilder + +function GetPreview { + [CmdletBinding()] + # [Alias("gp")] + param() +} diff --git a/Tests/Integration/Parameters/Private/TestUnExportedAliases.ps1 b/Tests/Integration/Parameters/Private/TestUnExportedAliases.ps1 new file mode 100644 index 0000000..10e9fa0 --- /dev/null +++ b/Tests/Integration/Parameters/Private/TestUnExportedAliases.ps1 @@ -0,0 +1,13 @@ +function TestUnExportedAliases { + [CmdletBinding()] + param() + + New-Alias -Name 'New-NotExportedAlias1' -Value 'Write-Verbose' + Set-Alias -Name 'New-NotExportedAlias2' -Value 'Write-Verbose' +} + +New-Alias -Name 'New-NotExportedAlias3' -Value 'Write-Verbose' -Scope Global +Set-Alias -Name 'New-NotExportedAlias4' -Value 'Write-Verbose' -Scope Global + +New-Alias -Name 'New-NotExportedAlias5' -Value 'Write-Verbose' +Remove-Alias -Name 'New-NotExportedAlias5' diff --git a/Tests/Integration/Parameters/Public/Get-Source.ps1 b/Tests/Integration/Parameters/Public/Get-Source.ps1 new file mode 100644 index 0000000..dd4f19d --- /dev/null +++ b/Tests/Integration/Parameters/Public/Get-Source.ps1 @@ -0,0 +1,7 @@ +using module ModuleBuilder + +function Get-Source { + [CmdletBinding()] + [Alias("gs","gsou")] + param() +} diff --git a/Tests/Integration/Parameters/Public/Set-Source.ps1 b/Tests/Integration/Parameters/Public/Set-Source.ps1 new file mode 100644 index 0000000..c4c9cb5 --- /dev/null +++ b/Tests/Integration/Parameters/Public/Set-Source.ps1 @@ -0,0 +1,6 @@ +function Set-Source { + [CmdletBinding()] + [Alias("ss", "ssou")] + param() + "sto͞o′pĭd" +} diff --git a/Tests/Integration/Parameters/build.psd1 b/Tests/Integration/Parameters/build.psd1 new file mode 100644 index 0000000..67c7be4 --- /dev/null +++ b/Tests/Integration/Parameters/build.psd1 @@ -0,0 +1,7 @@ +@{ + Path = "Parameters.psd1" + OutputDirectory = "..\Result3" + SemVer = "3.0.0-alpha001" + Target = "Build" + Passthru = $true +} diff --git a/Tests/Integration/Result3/Parameters/ReadMe.md b/Tests/Integration/Result3/Parameters/ReadMe.md new file mode 100644 index 0000000..e69de29