From fdc19ff663b8b303ea8b81342f25093897cc0d0c Mon Sep 17 00:00:00 2001 From: Trent Blackburn Date: Tue, 12 May 2026 00:24:39 -0400 Subject: [PATCH 1/3] style: align test scaffolding with canonical PSMTplt Apply the three style rules from PowerShellModuleTemplate#23 to the Help/Meta/MetaFixers test files this repo inherited from the template: - Named parameters on multi-arg cmdlet calls (Split-Path, Join-Path, Test-Path, Get-Module, Get-Content, Select-String, Get-TextFilesList, Test-FileUnicode) - ValidateNotNull / ValidateNotNullOrEmpty validators on mandatory param entries in tests/MetaFixers.psm1 - Test-FileUnicode call inside Get-UnicodeFilesList now uses named -FileInfo parameter Also fixes a stale $parameterNames reference in the last Context block of Help.tests.ps1 (should be $commandParameterNames). Bug bundled in per the cross-repo audit. tests/Manifest.tests.ps1 is the older Module Dependency variant (no Test-VersionConstraint helper, -Child typo on Join-Path) and is deferred to a separate uplift PR. Behavior is unchanged. --- tests/Help.tests.ps1 | 18 +++++++++--------- tests/Meta.tests.ps1 | 6 +++--- tests/MetaFixers.psm1 | 6 +++++- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/tests/Help.tests.ps1 b/tests/Help.tests.ps1 index cf7c16c..c581777 100644 --- a/tests/Help.tests.ps1 +++ b/tests/Help.tests.ps1 @@ -73,7 +73,7 @@ BeforeDiscovery { # the values it needs (BHPSModuleManifest, BHProjectName) — when running # via ./build.ps1 this happens before psake; running tests in isolation # bypasses that, so we do it here. - Set-BuildEnvironment -Path (Split-Path -Parent $PSScriptRoot) -Force + Set-BuildEnvironment -Path (Split-Path -Path $PSScriptRoot -Parent) -Force $buildFilePath = Join-Path -Path $PSScriptRoot -ChildPath '..\build.psake.ps1' $invokePsakeParameters = @{ TaskList = 'Build' @@ -83,10 +83,10 @@ BeforeDiscovery { } # PowerShellBuild outputs to Output///, override BHBuildOutput - $projectRoot = Split-Path -Parent $PSScriptRoot - $sourceManifest = Join-Path $projectRoot "$Env:BHProjectName/$Env:BHProjectName.psd1" + $projectRoot = Split-Path -Path $PSScriptRoot -Parent + $sourceManifest = Join-Path -Path $projectRoot -ChildPath "$Env:BHProjectName/$Env:BHProjectName.psd1" $moduleVersion = (Import-PowerShellDataFile -Path $sourceManifest).ModuleVersion - $Env:BHBuildOutput = Join-Path $projectRoot "Output/$Env:BHProjectName/$moduleVersion" + $Env:BHBuildOutput = Join-Path -Path $projectRoot -ChildPath "Output/$Env:BHProjectName/$moduleVersion" # Define the path to the module manifest $moduleManifestFilename = $Env:BHProjectName + '.psd1' @@ -98,18 +98,18 @@ BeforeDiscovery { 'Classes' ) | ForEach-Object { $path = Join-Path -Path $Env:BHBuildOutput -ChildPath $_ - if (Test-Path $path) { + if (Test-Path -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 $Env:BHProjectName | Remove-Module -Force -ErrorAction 'Ignore' + Get-Module -Name $Env:BHProjectName | Remove-Module -Force -ErrorAction 'Ignore' Import-Module -Name $moduleManifestPath -Verbose:$false -ErrorAction 'Stop' # Get module commands $getCommandParameters = @{ - Module = (Get-Module $Env:BHProjectName) + Module = (Get-Module -Name $Env:BHProjectName) CommandType = [System.Management.Automation.CommandTypes[]]'Cmdlet, Function' # Not alias } if ($PSVersionTable.PSVersion.Major -lt 6) { @@ -131,7 +131,7 @@ BeforeAll { # the values it needs (BHPSModuleManifest, BHProjectName) — when running # via ./build.ps1 this happens before psake; running tests in isolation # bypasses that, so we do it here. - Set-BuildEnvironment -Path (Split-Path -Parent $PSScriptRoot) -Force + Set-BuildEnvironment -Path (Split-Path -Path $PSScriptRoot -Parent) -Force $buildFilePath = Join-Path -Path $PSScriptRoot -ChildPath '..\build.psake.ps1' $invokePsakeParameters = @{ TaskList = 'Build' @@ -248,7 +248,7 @@ Describe "Test help for <_.Name>" -ForEach $commands { # Shouldn't find extra parameters in help It 'finds help parameter in code: <_>' { - $_ -in $parameterNames | Should -Be $true + $_ -in $commandParameterNames | Should -Be $true } } } diff --git a/tests/Meta.tests.ps1 b/tests/Meta.tests.ps1 index 68298f0..c1813ec 100644 --- a/tests/Meta.tests.ps1 +++ b/tests/Meta.tests.ps1 @@ -9,11 +9,11 @@ BeforeAll { $projectRoot = $PSScriptRoot } - $allTextFiles = Get-TextFilesList $projectRoot + $allTextFiles = Get-TextFilesList -Root $projectRoot $unicodeFilesCount = 0 $totalTabsCount = 0 foreach ($textFile in $allTextFiles) { - if (Test-FileUnicode $textFile) { + if (Test-FileUnicode -FileInfo $textFile) { $unicodeFilesCount++ Write-Warning ( "File $($textFile.FullName) contains 0x00 bytes." + @@ -24,7 +24,7 @@ BeforeAll { $unicodeFilesCount | Should -Be 0 $fileName = $textFile.FullName - (Get-Content $fileName -Raw) | Select-String "`t" | Foreach-Object { + (Get-Content -Path $fileName -Raw) | Select-String -Pattern "`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 7dec0c8..43da225 100644 --- a/tests/MetaFixers.psm1 +++ b/tests/MetaFixers.psm1 @@ -27,6 +27,7 @@ function ConvertTo-UTF8 { [OutputType([void])] param( [Parameter(Mandatory = $true, ValueFromPipeline = $true)] + [ValidateNotNull()] [System.IO.FileInfo]$FileInfo ) @@ -56,6 +57,7 @@ function ConvertTo-SpaceIndentation { [OutputType([void])] param( [Parameter(Mandatory = $true, ValueFromPipeline = $true)] + [ValidateNotNull()] [System.IO.FileInfo]$FileInfo ) @@ -85,6 +87,7 @@ function Get-TextFilesList { [OutputType([System.IO.FileInfo])] param( [Parameter(Mandatory = $true, ValueFromPipeline = $true)] + [ValidateNotNullOrEmpty()] [string]$Root ) @@ -159,10 +162,11 @@ function Get-UnicodeFilesList { [OutputType([System.IO.FileInfo])] param( [Parameter(Mandatory = $true)] + [ValidateNotNullOrEmpty()] [string]$Root ) $root | Get-TextFilesList | Where-Object { - Test-FileUnicode $_ + Test-FileUnicode -FileInfo $_ } } From 122766d4577cddcf70b9401074a252b8362494c9 Mon Sep 17 00:00:00 2001 From: Trent Blackburn Date: Thu, 28 May 2026 20:18:03 -0400 Subject: [PATCH 2/3] style: re-sync test scaffolding to post-#36 canonical template PowerShellModuleTemplate#36 (merged after this branch opened) scoped the named-parameter rule: name parameters only on calls passing two or more arguments (a trailing switch counts); single-argument calls stay positional. #36 explicitly calls out this PR as a consumer to re-sync. Revert the over-naming on single-argument calls so these files match the current canonical template: - Help.tests.ps1: Import-PowerShellDataFile, Test-Path, Import-Module, Get-Help, and global:FilterOutCommonParameters back to positional. Split-Path -Path .. -Parent and Join-Path -Path .. -ChildPath stay named (two-plus arguments). - Meta.tests.ps1: Import-Module back to positional; Get-Content -Path .. -Raw stays named (switch counts as an argument). - MetaFixers.psm1: Test-FileUnicode call in Get-UnicodeFilesList back to positional. Kept: the four ValidateNotNull/ValidateNotNullOrEmpty validators (added by template #23, not reverted by #36) and the comment-based-help .EXAMPLE calls (#36 leaves these named for teaching clarity). MetaFixers.psm1 and Meta.tests.ps1 are now byte-identical to upstream; Help.tests.ps1 differs only in this repo's local divergences (the Set-BuildEnvironment bootstrap and comment-based help). Behavior unchanged. Co-Authored-By: Claude Opus 4.8 (1M context) --- tests/Help.tests.ps1 | 22 +++++++++++----------- tests/Meta.tests.ps1 | 8 ++++---- tests/MetaFixers.psm1 | 2 +- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/tests/Help.tests.ps1 b/tests/Help.tests.ps1 index 32477ae..e776ac5 100644 --- a/tests/Help.tests.ps1 +++ b/tests/Help.tests.ps1 @@ -85,7 +85,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 @@ -98,18 +98,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) { @@ -149,10 +149,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?://' } } @@ -161,10 +161,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/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 $_ } } From b2e05c53c071448c5804ff7d202a26c17f0f06e2 Mon Sep 17 00:00:00 2001 From: Trent Blackburn Date: Thu, 28 May 2026 20:24:36 -0400 Subject: [PATCH 3/3] style: replace em-dashes with hyphens in Help.tests.ps1 comment The two em-dashes (U+2014) in the local Set-BuildEnvironment comment block were the sole non-ASCII content in the file, tripping PSScriptAnalyzer's PSUseBOMForUnicodeEncodedFile rule. Replace them with ASCII hyphens so the file is pure ASCII (matching the canonical template files) and PSSA is clean without adding a BOM or a suppression. Co-Authored-By: Claude Opus 4.8 (1M context) --- tests/Help.tests.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Help.tests.ps1 b/tests/Help.tests.ps1 index e776ac5..25f7216 100644 --- a/tests/Help.tests.ps1 +++ b/tests/Help.tests.ps1 @@ -70,7 +70,7 @@ BeforeDiscovery { build the module. #> if ($null -eq $Env:BHBuildOutput) { # Populate BuildHelpers env vars so build.psake.ps1's properties block has - # the values it needs (BHPSModuleManifest, BHProjectName) — when running + # the values it needs (BHPSModuleManifest, BHProjectName) - when running # via ./build.ps1 this happens before psake; running tests in isolation # bypasses that, so we do it here. Set-BuildEnvironment -Path (Split-Path -Path $PSScriptRoot -Parent) -Force @@ -128,7 +128,7 @@ BeforeAll { build the module. #> if ($null -eq $Env:BHBuildOutput) { # Populate BuildHelpers env vars so build.psake.ps1's properties block has - # the values it needs (BHPSModuleManifest, BHProjectName) — when running + # the values it needs (BHPSModuleManifest, BHProjectName) - when running # via ./build.ps1 this happens before psake; running tests in isolation # bypasses that, so we do it here. Set-BuildEnvironment -Path (Split-Path -Path $PSScriptRoot -Parent) -Force