Skip to content

Commit 6ed0a7f

Browse files
tablackburnclaude
andcommitted
fix(tests): parse changelog version with Select-String instead of break in ForEach-Object
The BeforeAll changelog-version parse in tests/Manifest.tests.ps1 used `Get-Content $changelogPath | ForEach-Object { ... break }`. `break` inside ForEach-Object is unreliable: a pipeline is not a loop, so `break` targets an enclosing loop if one exists, or otherwise terminates the block unexpectedly, rather than cleanly stopping at the first match. Replace it with Select-String, which returns the first matching line's named capture group directly — no loop and no break. Behavior is unchanged (still resolves to the topmost `## [Version]` entry). Surfaced while aligning a downstream module's Manifest test (tablackburn/ReScenePS#22). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 01cca97 commit 6ed0a7f

1 file changed

Lines changed: 4 additions & 6 deletions

File tree

tests/Manifest.tests.ps1

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,10 @@ BeforeAll {
140140
# Parse the version from the changelog
141141
$changelogPath = Join-Path -Path $Env:BHProjectPath -ChildPath 'CHANGELOG.md'
142142
$changelogVersionPattern = '^##\s\\?\[(?<Version>(\d+\.){1,3}\d+)\\?\]' # Matches on a line that starts with '## [Version]' or '## \[Version\]'
143-
$changelogVersion = Get-Content $changelogPath | ForEach-Object {
144-
if ($_ -match $changelogVersionPattern) {
145-
$changelogVersion = $matches.Version
146-
break
147-
}
148-
}
143+
# Select-String returns the first matching line's named capture directly — no loop and no
144+
# 'break' (which is unreliable inside ForEach-Object, since a pipeline is not a loop).
145+
$changelogVersion = (Select-String -Path $changelogPath -Pattern $changelogVersionPattern |
146+
Select-Object -First 1).Matches[0].Groups['Version'].Value
149147
}
150148
Describe 'Module manifest' {
151149

0 commit comments

Comments
 (0)