diff --git a/CHANGELOG.md b/CHANGELOG.md index d8b98f5..f3baa9b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed +- `Fail_Build_If_HQRM_Tests_Failed` now fails the build when the Pester run + reports failed blocks or failed containers (for example a discovery failure + such as an empty `-ForEach`), not only when `FailedCount` is greater than zero. + Such container/discovery failures leave `FailedCount` at `0`, so the previous + gate let them pass as a green build. The task now gates on the Pester `Result` + property, matching the check already used in `Invoke_HQRM_Tests`. - Added tag `AllowSuppressMessageAttribute` to test `Should not suppress the required rule` to allow usage of `SuppressMessageAttribute` [#135](https://github.com/dsccommunity/DscResource.Test/issues/135). ## [0.19.0] - 2026-01-23 diff --git a/source/tasks/Fail_Build_If_HQRM_Tests_Failed.build.ps1 b/source/tasks/Fail_Build_If_HQRM_Tests_Failed.build.ps1 index bae6b1a..ccd508a 100644 --- a/source/tasks/Fail_Build_If_HQRM_Tests_Failed.build.ps1 +++ b/source/tasks/Fail_Build_If_HQRM_Tests_Failed.build.ps1 @@ -97,6 +97,18 @@ task Fail_Build_If_HQRM_Tests_Failed { { $DscTestObject = Import-Clixml -Path $DscTestResultObjectClixml -ErrorAction 'Stop' - Assert-Build -Condition ($DscTestObject.FailedCount -eq 0) -Message ('Failed {0} tests. Aborting Build.' -f $DscTestObject.FailedCount) + <# + A discovery/container failure (for example an empty -ForEach, or a + parse error in a test file) does not increase FailedCount. It is + reported through FailedContainersCount/FailedBlocksCount and the + overall Result. Gating on FailedCount alone therefore lets such + failures slip through as a green build. Gate on Result instead, which + already accounts for failed tests, blocks and containers. This mirrors + the check already used in the Invoke_HQRM_Tests task. + #> + $assertMessage = "Pester result was '{0}'. Failed {1} test(s), {2} block(s) and {3} container(s). Aborting Build." -f + $DscTestObject.Result, $DscTestObject.FailedCount, $DscTestObject.FailedBlocksCount, $DscTestObject.FailedContainersCount + + Assert-Build -Condition ($DscTestObject.Result -eq 'Passed') -Message $assertMessage } }