Skip to content

Commit

Permalink
Set-ItResult: Return distinctive ErrorId depending on switch used (#2401
Browse files Browse the repository at this point in the history
)
  • Loading branch information
csandfeld authored Nov 9, 2023
1 parent a50354e commit 3fe6e60
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/Pester.Runtime.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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 '.'
Expand Down
2 changes: 1 addition & 1 deletion src/functions/Output.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
14 changes: 13 additions & 1 deletion src/functions/Set-ItResult.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 0 additions & 5 deletions tst/functions/Set-ItResult.Tests.ps1
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down

0 comments on commit 3fe6e60

Please sign in to comment.