Skip to content

Commit c8c7af0

Browse files
tablackburnclaude
andcommitted
test(manifest): parse changelog version with Select-String instead of foreach
Replace the foreach-over-Get-Content changelog-version parse with Select-String, which returns the first matching line's named capture group directly — no loop and no break. The foreach existed only to avoid the canonical template's unreliable `ForEach-Object { ... break }`; Select-String removes the need for either form. Mirrors the upstream fix in tablackburn/PowerShellModuleTemplate#37. Build + Pester pass locally: 786 passed, 0 failed, 23 skipped. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 7281471 commit c8c7af0

1 file changed

Lines changed: 4 additions & 8 deletions

File tree

tests/Manifest.tests.ps1

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -154,16 +154,12 @@ BeforeAll {
154154
$requirements = Import-PowerShellDataFile $requirementsPath -ErrorAction 'Stop'
155155

156156
# Parse the version from the changelog
157-
# Note: Use foreach statement (not ForEach-Object) because 'break' doesn't work reliably in ForEach-Object
158157
$changelogPath = Join-Path -Path $Env:BHProjectPath -ChildPath 'CHANGELOG.md'
159158
$changelogVersionPattern = '^##\s\\?\[(?<Version>(\d+\.){1,3}\d+)\\?\]' # Matches on a line that starts with '## [Version]' or '## \[Version\]'
160-
$changelogVersion = $null
161-
foreach ($line in Get-Content $changelogPath) {
162-
if ($line -match $changelogVersionPattern) {
163-
$changelogVersion = $matches.Version
164-
break
165-
}
166-
}
159+
# Select-String returns the first matching line's named capture directly — no loop and no
160+
# 'break' (which is unreliable inside ForEach-Object, since a pipeline is not a loop).
161+
$changelogVersion = (Select-String -Path $changelogPath -Pattern $changelogVersionPattern |
162+
Select-Object -First 1).Matches[0].Groups['Version'].Value
167163
}
168164
Describe 'Module manifest' {
169165

0 commit comments

Comments
 (0)