From 3fe6e6001975ad06ed9f4a7ba002aef0d1a56f4c Mon Sep 17 00:00:00 2001 From: Christian Sandfeld Date: Thu, 9 Nov 2023 10:19:57 +0100 Subject: [PATCH] Set-ItResult: Return distinctive ErrorId depending on switch used (#2401) --- src/Pester.Runtime.ps1 | 2 +- src/functions/Output.ps1 | 2 +- src/functions/Set-ItResult.ps1 | 14 +++++++++++++- tst/functions/Set-ItResult.Tests.ps1 | 5 ----- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/Pester.Runtime.ps1 b/src/Pester.Runtime.ps1 index c5fdae7c7..72b4914d6 100644 --- a/src/Pester.Runtime.ps1 +++ b/src/Pester.Runtime.ps1 @@ -680,7 +680,7 @@ function Invoke-TestItem { $Test.FrameworkData.Runtime.ExecutionStep = 'Finished' - if ($Result.ErrorRecord.FullyQualifiedErrorId -eq 'PesterTestSkipped') { + if (@('PesterTestSkipped', 'PesterTestInconclusive', 'PesterTestPending') -contains $Result.ErrorRecord.FullyQualifiedErrorId) { #Same logic as when setting a test block to skip if ($PesterPreference.Debug.WriteDebugMessages.Value) { $path = $Test.Path -join '.' diff --git a/src/functions/Output.ps1 b/src/functions/Output.ps1 index ccdd8ac9b..264d5ea0b 100644 --- a/src/functions/Output.ps1 +++ b/src/functions/Output.ps1 @@ -753,7 +753,7 @@ function Get-WriteScreenPlugin ($Verbosity) { $margin = $ReportStrings.Margin * ($level) $error_margin = $margin + $ReportStrings.Margin $out = $_test.ExpandedName - if (-not $_test.Skip -and $_test.ErrorRecord.FullyQualifiedErrorId -eq 'PesterTestSkipped') { + if (-not $_test.Skip -and @('PesterTestSkipped', 'PesterTestInconclusive', 'PesterTestPending') -contains $Result.ErrorRecord.FullyQualifiedErrorId) { $skippedMessage = [String]$_Test.ErrorRecord [String]$out += " $skippedMessage" } diff --git a/src/functions/Set-ItResult.ps1 b/src/functions/Set-ItResult.ps1 index c805507c7..8698e1eac 100644 --- a/src/functions/Set-ItResult.ps1 +++ b/src/functions/Set-ItResult.ps1 @@ -78,8 +78,20 @@ } } + switch ($result) { + 'Inconclusive' { + [String]$errorId = 'PesterTestInconclusive' + } + 'Pending' { + [String]$errorId = 'PesterTestPending' + } + 'Skipped' { + [String]$errorId = 'PesterTestSkipped' + } + } + throw [Pester.Factory]::CreateErrorRecord( - 'PesterTestSkipped', #string errorId + $errorId, #string errorId $Message, #string message $File, #string file $Line, #string line diff --git a/tst/functions/Set-ItResult.Tests.ps1 b/tst/functions/Set-ItResult.Tests.ps1 index 4040c5e46..d6ce83bf8 100644 --- a/tst/functions/Set-ItResult.Tests.ps1 +++ b/tst/functions/Set-ItResult.Tests.ps1 @@ -1,10 +1,5 @@ Set-StrictMode -Version Latest -#TODO: skipped pending and inconclusive test results are not implemented yet -return - - - Describe "Testing Set-ItResult" { It "This test should be inconclusive" { try {