From 6ed0a7fc585ee200100da6c5b97819c989272957 Mon Sep 17 00:00:00 2001 From: Trent Blackburn Date: Wed, 27 May 2026 01:19:07 -0400 Subject: [PATCH 1/2] fix(tests): parse changelog version with Select-String instead of break in ForEach-Object MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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) --- tests/Manifest.tests.ps1 | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/tests/Manifest.tests.ps1 b/tests/Manifest.tests.ps1 index d492528..90a5e9f 100644 --- a/tests/Manifest.tests.ps1 +++ b/tests/Manifest.tests.ps1 @@ -140,12 +140,10 @@ BeforeAll { # Parse the version from the changelog $changelogPath = Join-Path -Path $Env:BHProjectPath -ChildPath 'CHANGELOG.md' $changelogVersionPattern = '^##\s\\?\[(?(\d+\.){1,3}\d+)\\?\]' # Matches on a line that starts with '## [Version]' or '## \[Version\]' - $changelogVersion = Get-Content $changelogPath | ForEach-Object { - if ($_ -match $changelogVersionPattern) { - $changelogVersion = $matches.Version - break - } - } + # Select-String returns the first matching line's named capture directly — no loop and no + # 'break' (which is unreliable inside ForEach-Object, since a pipeline is not a loop). + $changelogVersion = (Select-String -Path $changelogPath -Pattern $changelogVersionPattern | + Select-Object -First 1).Matches[0].Groups['Version'].Value } Describe 'Module manifest' { From 4497839aaa3e6dd9cf7ec72e200c60391ea3bfa9 Mon Sep 17 00:00:00 2001 From: Trent Blackburn Date: Wed, 27 May 2026 20:23:27 -0400 Subject: [PATCH 2/2] fix(tests): guard changelog version parse against no match 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) --- tests/Manifest.tests.ps1 | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tests/Manifest.tests.ps1 b/tests/Manifest.tests.ps1 index 90a5e9f..dd7d7bf 100644 --- a/tests/Manifest.tests.ps1 +++ b/tests/Manifest.tests.ps1 @@ -142,8 +142,14 @@ BeforeAll { $changelogVersionPattern = '^##\s\\?\[(?(\d+\.){1,3}\d+)\\?\]' # Matches on a line that starts with '## [Version]' or '## \[Version\]' # Select-String returns the first matching line's named capture directly — no loop and no # 'break' (which is unreliable inside ForEach-Object, since a pipeline is not a loop). - $changelogVersion = (Select-String -Path $changelogPath -Pattern $changelogVersionPattern | - Select-Object -First 1).Matches[0].Groups['Version'].Value + # Capture the MatchInfo first and guard for no match, so a missing or malformed changelog + # heading leaves $changelogVersion as $null (failing the assertion below cleanly) instead of + # throwing "Cannot index into a null array" here in BeforeAll. + $changelogMatch = Select-String -Path $changelogPath -Pattern $changelogVersionPattern | + Select-Object -First 1 + $changelogVersion = if ($changelogMatch) { + $changelogMatch.Matches[0].Groups['Version'].Value + } } Describe 'Module manifest' {