diff --git a/CHANGELOG.md b/CHANGELOG.md index 7707f3b..8ca8e39 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/tests/Help.tests.ps1 b/tests/Help.tests.ps1 index 7cf307c..f61606d 100644 --- a/tests/Help.tests.ps1 +++ b/tests/Help.tests.ps1 @@ -59,7 +59,7 @@ BeforeDiscovery { # PowerShellBuild outputs to Output///, 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 @@ -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) { @@ -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?://' } } @@ -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 } diff --git a/tests/Manifest.tests.ps1 b/tests/Manifest.tests.ps1 index 0762051..d492528 100644 --- a/tests/Manifest.tests.ps1 +++ b/tests/Manifest.tests.ps1 @@ -71,7 +71,7 @@ BeforeDiscovery { # PowerShellBuild outputs to Output///, 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 @@ -110,7 +110,7 @@ BeforeAll { # PowerShellBuild outputs to Output///, 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 @@ -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\\?\[(?(\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 diff --git a/tests/Meta.tests.ps1 b/tests/Meta.tests.ps1 index c1813ec..c3addf4 100644 --- a/tests/Meta.tests.ps1 +++ b/tests/Meta.tests.ps1 @@ -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." + @@ -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".' diff --git a/tests/MetaFixers.psm1 b/tests/MetaFixers.psm1 index 43da225..5c614df 100644 --- a/tests/MetaFixers.psm1 +++ b/tests/MetaFixers.psm1 @@ -167,6 +167,6 @@ function Get-UnicodeFilesList { ) $root | Get-TextFilesList | Where-Object { - Test-FileUnicode -FileInfo $_ + Test-FileUnicode $_ } } diff --git a/tests/Unit/Private/Invoke-{{Prefix}}Helper.tests.ps1 b/tests/Unit/Private/Invoke-{{Prefix}}Helper.tests.ps1 index 250662c..0811a60 100644 --- a/tests/Unit/Private/Invoke-{{Prefix}}Helper.tests.ps1 +++ b/tests/Unit/Private/Invoke-{{Prefix}}Helper.tests.ps1 @@ -19,15 +19,15 @@ BeforeDiscovery { # PowerShellBuild outputs to Output/// $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 { @@ -36,12 +36,12 @@ 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' } } @@ -49,18 +49,18 @@ InModuleScope -ModuleName $Env:BHProjectName -ScriptBlock { 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 } } diff --git a/tests/Unit/Public/Get-{{Prefix}}Example.tests.ps1 b/tests/Unit/Public/Get-{{Prefix}}Example.tests.ps1 index 051affa..5763829 100644 --- a/tests/Unit/Public/Get-{{Prefix}}Example.tests.ps1 +++ b/tests/Unit/Public/Get-{{Prefix}}Example.tests.ps1 @@ -19,15 +19,15 @@ BeforeDiscovery { # PowerShellBuild outputs to Output/// $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' { @@ -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!' } @@ -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 } }