fix(tests): parse changelog version with Select-String instead of break in ForEach-Object#37
fix(tests): parse changelog version with Select-String instead of break in ForEach-Object#37tablackburn wants to merge 2 commits into
Conversation
…ak 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) <[email protected]>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughRefactors changelog version extraction in ChangesChangelog Version Extraction Refactoring
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
… 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) <[email protected]>
There was a problem hiding this comment.
Pull request overview
This PR updates the module-manifest Pester tests to parse the changelog version using Select-String, avoiding the unreliable use of break inside a ForEach-Object pipeline in BeforeAll.
Changes:
- Replaced
Get-Content | ForEach-Object { ... break }changelog parsing with aSelect-String-based approach. - Added an explanatory comment describing why
breakin this context is unreliable.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Capture the Select-String MatchInfo before indexing so a missing or malformed changelog heading leaves $changelogVersion as $null and fails the assertion cleanly, instead of throwing "Cannot index into a null array" in BeforeAll. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Summary
Replaces the changelog-version parse in
tests/Manifest.tests.ps1withSelect-String, removing a latentbreak-in-ForEach-Objectbug.BeforeAllparsed the module version fromCHANGELOG.mdwith:breakinside aForEach-Objectscript block is unreliable: a pipeline is not a loop, sobreaklooks for an enclosing loop and, finding none, terminates the surrounding block unexpectedly rather than cleanly stopping the pipeline at the first match. It also assigns$changelogVersiontwice (inside the block, then again to the pipeline's output).The replacement pulls the first matching line's named capture group directly — no loop, no
break:Validation
The raw template isn't Pester-tested locally or in CI (the
is_templategate inCI.yamlskips Build/Test while{{GUID}}etc. are still placeholders — theGENERATEMARKDOWN/manifest-import step can't parse them). So this is validated the way template scaffolding always is — downstream:Select-Stringexpression run against this repo'sCHANGELOG.mdreturns2026.04.29(a valid[Version]), matching the old parser's result.Module manifestchangelog tests green.No CHANGELOG entry, consistent with #35 (a prior test-internal fix that didn't add one).
🤖 Generated with Claude Code
Summary by CodeRabbit