Skip to content

Commit 4497839

Browse files
tablackburnclaude
andcommitted
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) <noreply@anthropic.com>
1 parent 6ed0a7f commit 4497839

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

tests/Manifest.tests.ps1

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,14 @@ BeforeAll {
142142
$changelogVersionPattern = '^##\s\\?\[(?<Version>(\d+\.){1,3}\d+)\\?\]' # Matches on a line that starts with '## [Version]' or '## \[Version\]'
143143
# Select-String returns the first matching line's named capture directly — no loop and no
144144
# '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
145+
# Capture the MatchInfo first and guard for no match, so a missing or malformed changelog
146+
# heading leaves $changelogVersion as $null (failing the assertion below cleanly) instead of
147+
# throwing "Cannot index into a null array" here in BeforeAll.
148+
$changelogMatch = Select-String -Path $changelogPath -Pattern $changelogVersionPattern |
149+
Select-Object -First 1
150+
$changelogVersion = if ($changelogMatch) {
151+
$changelogMatch.Matches[0].Groups['Version'].Value
152+
}
147153
}
148154
Describe 'Module manifest' {
149155

0 commit comments

Comments
 (0)