Skip to content
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ own `CHANGELOG.md` (generated from `CHANGELOG.template.md` during init).
### Changed

- Renamed required PowerShell Gallery publish secret `PS_GALLERY_KEY` → `PSGALLERY_API_KEY` so the secret name matches the env var name PowerShellBuild reads (eliminating the previous mapping caveat). New modules created from the template after this change pick up the new name automatically. **Migration for existing modules:** create a new `PSGALLERY_API_KEY` repo secret with the same value, update `.github/workflows/PublishModuleToPowerShellGallery.yaml` to reference `secrets.PSGALLERY_API_KEY`, then delete the old `PS_GALLERY_KEY` secret.
- Test scaffolding (`tests/Help.tests.ps1`, `tests/Manifest.tests.ps1`, `tests/Meta.tests.ps1`, `tests/MetaFixers.psm1`, and the `tests/Unit/` templates) no longer names parameters on single-argument calls (e.g. `Test-Path $path`, `Get-Module $name`, `Get-Help $command`), matching the scoped named-parameter rule — name parameters only when a call passes two or more arguments. A trailing switch counts as an argument, so `Split-Path -Path $x -Parent`, `Get-Content -Path $x -Raw`, and `Get-ChildItem -Path $x -Recurse` keep their names, as do genuinely multi-value calls (`Join-Path`, `Get-Command -Name … -CommandType …`) and `Test-Path -LiteralPath`.

## [2026.04.29] - 2026-04-29

Expand Down
22 changes: 11 additions & 11 deletions tests/Help.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ BeforeDiscovery {
# PowerShellBuild outputs to Output/<ModuleName>/<Version>/, override BHBuildOutput
$projectRoot = Split-Path -Path $PSScriptRoot -Parent
$sourceManifest = Join-Path -Path $projectRoot -ChildPath "$Env:BHProjectName/$Env:BHProjectName.psd1"
$moduleVersion = (Import-PowerShellDataFile -Path $sourceManifest).ModuleVersion
$moduleVersion = (Import-PowerShellDataFile $sourceManifest).ModuleVersion
$Env:BHBuildOutput = Join-Path -Path $projectRoot -ChildPath "Output/$Env:BHProjectName/$moduleVersion"

# Define the path to the module manifest
Expand All @@ -72,18 +72,18 @@ BeforeDiscovery {
'Classes'
) | ForEach-Object {
$path = Join-Path -Path $Env:BHBuildOutput -ChildPath $_
if (Test-Path -Path $path) {
if (Test-Path $path) {
$global:CustomTypes += (Get-ChildItem -Path $path -Recurse -ErrorAction 'SilentlyContinue').BaseName
}
}

# Remove all versions of the module from the session. Pester can't handle multiple versions.
Get-Module -Name $Env:BHProjectName | Remove-Module -Force -ErrorAction 'Ignore'
Import-Module -Name $moduleManifestPath -Verbose:$false -ErrorAction 'Stop'
Get-Module $Env:BHProjectName | Remove-Module -Force -ErrorAction 'Ignore'
Import-Module $moduleManifestPath -Verbose:$false -ErrorAction 'Stop'

# Get module commands
$getCommandParameters = @{
Module = (Get-Module -Name $Env:BHProjectName)
Module = (Get-Module $Env:BHProjectName)
CommandType = [System.Management.Automation.CommandTypes[]]'Cmdlet, Function' # Not alias
}
if ($PSVersionTable.PSVersion.Major -lt 6) {
Expand Down Expand Up @@ -116,10 +116,10 @@ Describe "Test help for <_.Name>" -ForEach $commands {
# -ForEach, which Pester evaluates during discovery (before BeforeAll runs).
$command = $_
$commandName = $command.Name
$commandHelp = Get-Help -Name $command.Name -ErrorAction 'SilentlyContinue'
$commandParameters = global:FilterOutCommonParameters -Parameters $command.ParameterSets.Parameters
$commandHelp = Get-Help $command.Name -ErrorAction 'SilentlyContinue'
$commandParameters = global:FilterOutCommonParameters $command.ParameterSets.Parameters
$commandParameterNames = $commandParameters.Name
$helpParameters = global:FilterOutCommonParameters -Parameters $commandHelp.Parameters.Parameter
$helpParameters = global:FilterOutCommonParameters $commandHelp.Parameters.Parameter
$helpParameterNames = $helpParameters.Name
$helpLinks = $commandHelp.relatedLinks.navigationLink.uri | Where-Object { $_ -match '^https?://' }
}
Expand All @@ -128,10 +128,10 @@ Describe "Test help for <_.Name>" -ForEach $commands {
# These variables are needed in both discovery and test phases so we need to duplicate them here
$command = $_
$commandName = $_.Name
$commandHelp = Get-Help -Name $command.Name -ErrorAction 'SilentlyContinue'
$commandParameters = global:FilterOutCommonParameters -Parameters $command.ParameterSets.Parameters
$commandHelp = Get-Help $command.Name -ErrorAction 'SilentlyContinue'
$commandParameters = global:FilterOutCommonParameters $command.ParameterSets.Parameters
$commandParameterNames = $commandParameters.Name
$helpParameters = global:FilterOutCommonParameters -Parameters $commandHelp.Parameters.Parameter
$helpParameters = global:FilterOutCommonParameters $commandHelp.Parameters.Parameter
$helpParameterNames = $helpParameters.Name
}

Expand Down
10 changes: 5 additions & 5 deletions tests/Manifest.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ BeforeDiscovery {
# PowerShellBuild outputs to Output/<ModuleName>/<Version>/, override BHBuildOutput
$projectRoot = Split-Path -Path $PSScriptRoot -Parent
$sourceManifest = Join-Path -Path $projectRoot -ChildPath "$Env:BHProjectName/$Env:BHProjectName.psd1"
$moduleVersion = (Import-PowerShellDataFile -Path $sourceManifest).ModuleVersion
$moduleVersion = (Import-PowerShellDataFile $sourceManifest).ModuleVersion
$Env:BHBuildOutput = Join-Path -Path $projectRoot -ChildPath "Output/$Env:BHProjectName/$moduleVersion"

# Define the path to the module manifest
Expand Down Expand Up @@ -110,7 +110,7 @@ BeforeAll {
# PowerShellBuild outputs to Output/<ModuleName>/<Version>/, override BHBuildOutput
$projectRoot = Split-Path -Path $PSScriptRoot -Parent
$sourceManifest = Join-Path -Path $projectRoot -ChildPath "$Env:BHProjectName/$Env:BHProjectName.psd1"
$moduleVersion = (Import-PowerShellDataFile -Path $sourceManifest).ModuleVersion
$moduleVersion = (Import-PowerShellDataFile $sourceManifest).ModuleVersion
$Env:BHBuildOutput = Join-Path -Path $projectRoot -ChildPath "Output/$Env:BHProjectName/$moduleVersion"

# Define the path to the module manifest
Expand All @@ -132,15 +132,15 @@ BeforeAll {
$manifestRawData = Import-PowerShellDataFile @importDataFileParameters

# Import ManifestHelpers.psm1 for SemVer helper functions
Import-Module -Name (Join-Path -Path $PSScriptRoot -ChildPath 'ManifestHelpers.psm1') -Verbose:$false -Force
Import-Module (Join-Path -Path $PSScriptRoot -ChildPath 'ManifestHelpers.psm1') -Verbose:$false -Force

$requirementsPath = Join-Path -Path $env:BHProjectPath -ChildPath 'requirements.psd1'
$requirements = Import-PowerShellDataFile -Path $requirementsPath -ErrorAction 'Stop'
$requirements = Import-PowerShellDataFile $requirementsPath -ErrorAction 'Stop'

# Parse the version from the changelog
$changelogPath = Join-Path -Path $Env:BHProjectPath -ChildPath 'CHANGELOG.md'
$changelogVersionPattern = '^##\s\\?\[(?<Version>(\d+\.){1,3}\d+)\\?\]' # Matches on a line that starts with '## [Version]' or '## \[Version\]'
$changelogVersion = Get-Content -Path $changelogPath | ForEach-Object {
$changelogVersion = Get-Content $changelogPath | ForEach-Object {
if ($_ -match $changelogVersionPattern) {
$changelogVersion = $matches.Version
break
Expand Down
8 changes: 4 additions & 4 deletions tests/Meta.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ BeforeAll {
Set-StrictMode -Version 'Latest'

# Make sure MetaFixers.psm1 is loaded - it contains Get-TextFilesList
Import-Module -Name (Join-Path -Path $PSScriptRoot -ChildPath 'MetaFixers.psm1') -Verbose:$false -Force
Import-Module (Join-Path -Path $PSScriptRoot -ChildPath 'MetaFixers.psm1') -Verbose:$false -Force

$projectRoot = $Env:BHProjectPath
if (-not $projectRoot) {
$projectRoot = $PSScriptRoot
}

$allTextFiles = Get-TextFilesList -Root $projectRoot
$allTextFiles = Get-TextFilesList $projectRoot
$unicodeFilesCount = 0
$totalTabsCount = 0
foreach ($textFile in $allTextFiles) {
if (Test-FileUnicode -FileInfo $textFile) {
if (Test-FileUnicode $textFile) {
$unicodeFilesCount++
Write-Warning (
"File $($textFile.FullName) contains 0x00 bytes." +
Expand All @@ -24,7 +24,7 @@ BeforeAll {
$unicodeFilesCount | Should -Be 0

$fileName = $textFile.FullName
(Get-Content -Path $fileName -Raw) | Select-String -Pattern "`t" | Foreach-Object {
(Get-Content -Path $fileName -Raw) | Select-String "`t" | Foreach-Object {
Write-Warning (
"There are tabs in $fileName." +
' Use Fixer "Get-TextFilesList `$pwd | ConvertTo-SpaceIndentation".'
Expand Down
2 changes: 1 addition & 1 deletion tests/MetaFixers.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,6 @@ function Get-UnicodeFilesList {
)

$root | Get-TextFilesList | Where-Object {
Test-FileUnicode -FileInfo $_
Test-FileUnicode $_
}
}
16 changes: 8 additions & 8 deletions tests/Unit/Private/Invoke-{{Prefix}}Helper.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ BeforeDiscovery {
# PowerShellBuild outputs to Output/<ModuleName>/<Version>/
$projectRoot = Split-Path -Path (Split-Path -Path (Split-Path -Path $PSScriptRoot -Parent) -Parent) -Parent
$sourceManifest = Join-Path -Path $projectRoot -ChildPath "$Env:BHProjectName/$Env:BHProjectName.psd1"
$moduleVersion = (Import-PowerShellDataFile -Path $sourceManifest).ModuleVersion
$moduleVersion = (Import-PowerShellDataFile $sourceManifest).ModuleVersion
$Env:BHBuildOutput = Join-Path -Path $projectRoot -ChildPath "Output/$Env:BHProjectName/$moduleVersion"
}

BeforeAll {
# Import the module from the build output
$moduleManifestPath = Join-Path -Path $Env:BHBuildOutput -ChildPath "$Env:BHProjectName.psd1"
Get-Module -Name $Env:BHProjectName | Remove-Module -Force -ErrorAction 'Ignore'
Import-Module -Name $moduleManifestPath -Force -ErrorAction 'Stop'
Get-Module $Env:BHProjectName | Remove-Module -Force -ErrorAction 'Ignore'
Import-Module $moduleManifestPath -Force -ErrorAction 'Stop'
}

InModuleScope -ModuleName $Env:BHProjectName -ScriptBlock {
Expand All @@ -36,31 +36,31 @@ InModuleScope -ModuleName $Env:BHProjectName -ScriptBlock {
Context 'Basic functionality' {

It 'Returns the processed message' {
$result = Invoke-{{Prefix}}Helper -Message 'Test message'
$result = Invoke-{{Prefix}}Helper 'Test message'
$result | Should -Be 'Test message'
}

It 'Trims whitespace from message' {
$result = Invoke-{{Prefix}}Helper -Message ' Test message '
$result = Invoke-{{Prefix}}Helper ' Test message '
$result | Should -Be 'Test message'
}
}

Context 'Parameter validation' {

It 'Throws on empty message' {
{ Invoke-{{Prefix}}Helper -Message '' } | Should -Throw
{ Invoke-{{Prefix}}Helper '' } | Should -Throw
}

It 'Throws on null message' {
{ Invoke-{{Prefix}}Helper -Message $null } | Should -Throw
{ Invoke-{{Prefix}}Helper $null } | Should -Throw
}
}

Context 'Verbose output' {

It 'Writes verbose messages when -Verbose is specified' {
$verboseOutput = Invoke-{{Prefix}}Helper -Message 'Test' -Verbose 4>&1
$verboseOutput = Invoke-{{Prefix}}Helper 'Test' -Verbose 4>&1
$verboseOutput | Should -Not -BeNullOrEmpty
}
}
Expand Down
14 changes: 7 additions & 7 deletions tests/Unit/Public/Get-{{Prefix}}Example.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ BeforeDiscovery {
# PowerShellBuild outputs to Output/<ModuleName>/<Version>/
$projectRoot = Split-Path -Path (Split-Path -Path (Split-Path -Path $PSScriptRoot -Parent) -Parent) -Parent
$sourceManifest = Join-Path -Path $projectRoot -ChildPath "$Env:BHProjectName/$Env:BHProjectName.psd1"
$moduleVersion = (Import-PowerShellDataFile -Path $sourceManifest).ModuleVersion
$moduleVersion = (Import-PowerShellDataFile $sourceManifest).ModuleVersion
$Env:BHBuildOutput = Join-Path -Path $projectRoot -ChildPath "Output/$Env:BHProjectName/$moduleVersion"
}

BeforeAll {
# Import the module from the build output
$moduleManifestPath = Join-Path -Path $Env:BHBuildOutput -ChildPath "$Env:BHProjectName.psd1"
Get-Module -Name $Env:BHProjectName | Remove-Module -Force -ErrorAction 'Ignore'
Import-Module -Name $moduleManifestPath -Force -ErrorAction 'Stop'
Get-Module $Env:BHProjectName | Remove-Module -Force -ErrorAction 'Ignore'
Import-Module $moduleManifestPath -Force -ErrorAction 'Stop'
}

Describe 'Get-{{Prefix}}Example' {
Expand All @@ -40,7 +40,7 @@ Describe 'Get-{{Prefix}}Example' {
}

It 'Returns a greeting with specified name' {
$result = Get-{{Prefix}}Example -Name 'PowerShell'
$result = Get-{{Prefix}}Example 'PowerShell'
$result | Should -Be 'Hello, PowerShell!'
}

Expand All @@ -53,18 +53,18 @@ Describe 'Get-{{Prefix}}Example' {
Context 'Parameter validation' {

It 'Throws on empty name' {
{ Get-{{Prefix}}Example -Name '' } | Should -Throw
{ Get-{{Prefix}}Example '' } | Should -Throw
}

It 'Throws on null name' {
{ Get-{{Prefix}}Example -Name $null } | Should -Throw
{ Get-{{Prefix}}Example $null } | Should -Throw
}
}

Context 'Verbose output' {

It 'Writes verbose messages when -Verbose is specified' {
$verboseOutput = Get-{{Prefix}}Example -Name 'Test' -Verbose 4>&1
$verboseOutput = Get-{{Prefix}}Example 'Test' -Verbose 4>&1
$verboseOutput | Should -Not -BeNullOrEmpty
}
}
Expand Down
Loading