diff --git a/tests/Manifest.tests.ps1 b/tests/Manifest.tests.ps1 index d492528..dd7d7bf 100644 --- a/tests/Manifest.tests.ps1 +++ b/tests/Manifest.tests.ps1 @@ -140,11 +140,15 @@ 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). + # 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' {