Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set-ItResult: Return distinctive ErrorId depending on switch used #2401

Merged
merged 2 commits into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fflaten what you commented on in the Issue happens here. The error record id is translated to .Skipped = $true on the test object. So all the accounting that is done above this is correct, but you can still see the actual reason for marking the test as skipped on the ErrorRecord itself on the Result object.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks 🙂 Didn't remember that Add-RSpecTestObjectProperties would set the correct result based on Skipped = $true during teardown.

#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