Skip to content

Commit 58d18d8

Browse files
tablackburnclaude
andauthored
style: re-sync test scaffolding to canonical template (post-#36) (#55)
* 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. * 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) <noreply@anthropic.com> * 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) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 09b763f commit 58d18d8

3 files changed

Lines changed: 21 additions & 17 deletions

File tree

tests/Help.tests.ps1

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,10 @@ BeforeDiscovery {
7070
build the module. #>
7171
if ($null -eq $Env:BHBuildOutput) {
7272
# Populate BuildHelpers env vars so build.psake.ps1's properties block has
73-
# the values it needs (BHPSModuleManifest, BHProjectName) when running
73+
# the values it needs (BHPSModuleManifest, BHProjectName) - when running
7474
# via ./build.ps1 this happens before psake; running tests in isolation
7575
# bypasses that, so we do it here.
76-
Set-BuildEnvironment -Path (Split-Path -Parent $PSScriptRoot) -Force
76+
Set-BuildEnvironment -Path (Split-Path -Path $PSScriptRoot -Parent) -Force
7777
$buildFilePath = Join-Path -Path $PSScriptRoot -ChildPath '..\build.psake.ps1'
7878
$invokePsakeParameters = @{
7979
TaskList = 'Build'
@@ -83,10 +83,10 @@ BeforeDiscovery {
8383
}
8484

8585
# PowerShellBuild outputs to Output/<ModuleName>/<Version>/, override BHBuildOutput
86-
$projectRoot = Split-Path -Parent $PSScriptRoot
87-
$sourceManifest = Join-Path $projectRoot "$Env:BHProjectName/$Env:BHProjectName.psd1"
88-
$moduleVersion = (Import-PowerShellDataFile -Path $sourceManifest).ModuleVersion
89-
$Env:BHBuildOutput = Join-Path $projectRoot "Output/$Env:BHProjectName/$moduleVersion"
86+
$projectRoot = Split-Path -Path $PSScriptRoot -Parent
87+
$sourceManifest = Join-Path -Path $projectRoot -ChildPath "$Env:BHProjectName/$Env:BHProjectName.psd1"
88+
$moduleVersion = (Import-PowerShellDataFile $sourceManifest).ModuleVersion
89+
$Env:BHBuildOutput = Join-Path -Path $projectRoot -ChildPath "Output/$Env:BHProjectName/$moduleVersion"
9090

9191
# Define the path to the module manifest
9292
$moduleManifestFilename = $Env:BHProjectName + '.psd1'
@@ -105,7 +105,7 @@ BeforeDiscovery {
105105

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

110110
# Get module commands
111111
$getCommandParameters = @{
@@ -128,10 +128,10 @@ BeforeAll {
128128
build the module. #>
129129
if ($null -eq $Env:BHBuildOutput) {
130130
# Populate BuildHelpers env vars so build.psake.ps1's properties block has
131-
# the values it needs (BHPSModuleManifest, BHProjectName) when running
131+
# the values it needs (BHPSModuleManifest, BHProjectName) - when running
132132
# via ./build.ps1 this happens before psake; running tests in isolation
133133
# bypasses that, so we do it here.
134-
Set-BuildEnvironment -Path (Split-Path -Parent $PSScriptRoot) -Force
134+
Set-BuildEnvironment -Path (Split-Path -Path $PSScriptRoot -Parent) -Force
135135
$buildFilePath = Join-Path -Path $PSScriptRoot -ChildPath '..\build.psake.ps1'
136136
$invokePsakeParameters = @{
137137
TaskList = 'Build'
@@ -149,10 +149,10 @@ Describe "Test help for <_.Name>" -ForEach $commands {
149149
# -ForEach, which Pester evaluates during discovery (before BeforeAll runs).
150150
$command = $_
151151
$commandName = $command.Name
152-
$commandHelp = Get-Help -Name $command.Name -ErrorAction 'SilentlyContinue'
153-
$commandParameters = global:FilterOutCommonParameters -Parameters $command.ParameterSets.Parameters
152+
$commandHelp = Get-Help $command.Name -ErrorAction 'SilentlyContinue'
153+
$commandParameters = global:FilterOutCommonParameters $command.ParameterSets.Parameters
154154
$commandParameterNames = $commandParameters.Name
155-
$helpParameters = global:FilterOutCommonParameters -Parameters $commandHelp.Parameters.Parameter
155+
$helpParameters = global:FilterOutCommonParameters $commandHelp.Parameters.Parameter
156156
$helpParameterNames = $helpParameters.Name
157157
$helpLinks = $commandHelp.relatedLinks.navigationLink.uri | Where-Object { $_ -match '^https?://' }
158158
}
@@ -161,10 +161,10 @@ Describe "Test help for <_.Name>" -ForEach $commands {
161161
# These variables are needed in both discovery and test phases so we need to duplicate them here
162162
$command = $_
163163
$commandName = $_.Name
164-
$commandHelp = Get-Help -Name $command.Name -ErrorAction 'SilentlyContinue'
165-
$commandParameters = global:FilterOutCommonParameters -Parameters $command.ParameterSets.Parameters
164+
$commandHelp = Get-Help $command.Name -ErrorAction 'SilentlyContinue'
165+
$commandParameters = global:FilterOutCommonParameters $command.ParameterSets.Parameters
166166
$commandParameterNames = $commandParameters.Name
167-
$helpParameters = global:FilterOutCommonParameters -Parameters $commandHelp.Parameters.Parameter
167+
$helpParameters = global:FilterOutCommonParameters $commandHelp.Parameters.Parameter
168168
$helpParameterNames = $helpParameters.Name
169169
}
170170

tests/Meta.tests.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ BeforeAll {
22
Set-StrictMode -Version 'Latest'
33

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

77
$projectRoot = $Env:BHProjectPath
88
if (-not $projectRoot) {
@@ -24,7 +24,7 @@ BeforeAll {
2424
$unicodeFilesCount | Should -Be 0
2525

2626
$fileName = $textFile.FullName
27-
(Get-Content $fileName -Raw) | Select-String "`t" | Foreach-Object {
27+
(Get-Content -Path $fileName -Raw) | Select-String "`t" | Foreach-Object {
2828
Write-Warning (
2929
"There are tabs in $fileName." +
3030
' Use Fixer "Get-TextFilesList `$pwd | ConvertTo-SpaceIndentation".'

tests/MetaFixers.psm1

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ function ConvertTo-UTF8 {
2727
[OutputType([void])]
2828
param(
2929
[Parameter(Mandatory = $true, ValueFromPipeline = $true)]
30+
[ValidateNotNull()]
3031
[System.IO.FileInfo]$FileInfo
3132
)
3233

@@ -56,6 +57,7 @@ function ConvertTo-SpaceIndentation {
5657
[OutputType([void])]
5758
param(
5859
[Parameter(Mandatory = $true, ValueFromPipeline = $true)]
60+
[ValidateNotNull()]
5961
[System.IO.FileInfo]$FileInfo
6062
)
6163

@@ -85,6 +87,7 @@ function Get-TextFilesList {
8587
[OutputType([System.IO.FileInfo])]
8688
param(
8789
[Parameter(Mandatory = $true, ValueFromPipeline = $true)]
90+
[ValidateNotNullOrEmpty()]
8891
[string]$Root
8992
)
9093

@@ -159,6 +162,7 @@ function Get-UnicodeFilesList {
159162
[OutputType([System.IO.FileInfo])]
160163
param(
161164
[Parameter(Mandatory = $true)]
165+
[ValidateNotNullOrEmpty()]
162166
[string]$Root
163167
)
164168

0 commit comments

Comments
 (0)