From 9d80eb5f9e1faec7cbba6cffb921b273b229304f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Jare=C5=A1?= Date: Wed, 10 Apr 2024 23:09:12 +0200 Subject: [PATCH] Add cheaper check for deprecation, and a test, remove INCONCLUSIVE from message --- src/Pester.Runtime.ps1 | 6 ++++++ src/functions/Output.ps1 | 5 ++--- src/functions/Set-ItResult.ps1 | 8 ++------ tst/Pester.RSpec.Output.ts.ps1 | 21 +++++++++++++++++++++ 4 files changed, 31 insertions(+), 9 deletions(-) diff --git a/src/Pester.Runtime.ps1 b/src/Pester.Runtime.ps1 index d682e9d32..07c23d57b 100644 --- a/src/Pester.Runtime.ps1 +++ b/src/Pester.Runtime.ps1 @@ -692,6 +692,12 @@ function Invoke-TestItem { } else { $Test.Skipped = $true + + # Pending test is still considered a skipped, we don't have a special category for it. + # Mark the run to show deprecation message. + if ('PesterTestPending' -eq $Result.ErrorRecord.FullyQualifiedErrorId) { + $test.Block.Root.FrameworkData['ShowPendingDeprecation'] = $true + } } } else { diff --git a/src/functions/Output.ps1 b/src/functions/Output.ps1 index 6e09d0357..027e4abb2 100644 --- a/src/functions/Output.ps1 +++ b/src/functions/Output.ps1 @@ -405,9 +405,8 @@ function Write-PesterReport { # & $SafeCommands['Write-Host'] ($ReportStrings.TestsInconclusive -f $RunResult.InconclusiveCount) -Foreground $Inconclusive # } - if ($RunResult.Tests.ErrorRecord.FullyQualifiedErrorID -contains 'PesterTestPending') { - Write-PesterHostMessage '' - Write-PesterHostMessage '**DEPRECATED**: The Set-ItResult -Pending parameter is deprecated. It will be removed in a future version of Pester.' -ForegroundColor $ReportTheme.Warning + if ($RunResult.Containers.Blocks.Root.FrameworkData['ShowPendingDeprecation'] -eq $true) { + Write-PesterHostMessage '**DEPRECATED**: The -Pending parameter of Set-ItResult is deprecated. The parameter will be removed in a future version of Pester.' -ForegroundColor $ReportTheme.Warning } } diff --git a/src/functions/Set-ItResult.ps1 b/src/functions/Set-ItResult.ps1 index 06c025673..6371eebc1 100644 --- a/src/functions/Set-ItResult.ps1 +++ b/src/functions/Set-ItResult.ps1 @@ -30,7 +30,7 @@ ```powershell Describe "Example" { It "Inconclusive test" { - Set-ItResult -Inconclusive -Because "we want it to be inconclusice" + Set-ItResult -Inconclusive -Because "we want it to be inconclusive" } It "Skipped test" { Set-ItResult -Skipped -Because "we want it to be skipped" @@ -42,7 +42,7 @@ ``` Describing Example - [?] Inconclusive test is inconclusive, because INCONCLUSIVE: we want it to be inconclusice 35ms (32ms|3ms) + [?] Inconclusive test is inconclusive, because we want it to be inconclusive 35ms (32ms|3ms) [!] Skipped test is skipped, because we want it to be skipped 3ms (2ms|1ms) Tests completed in 78ms Tests Passed: 0, Failed: 0, Skipped: 1, Inconclusive: 1, NotRun: 0 @@ -63,10 +63,6 @@ $result = $PSCmdlet.ParameterSetName - if ($Result -ne 'Skipped') { - [String]$Because = if ($Because) { $Result.ToUpper(), $Because -join ': ' } else { $Result.ToUpper() } - } - switch ($null) { $File { [String]$File = $MyInvocation.ScriptName diff --git a/tst/Pester.RSpec.Output.ts.ps1 b/tst/Pester.RSpec.Output.ts.ps1 index f900f8d3a..92a72c106 100644 --- a/tst/Pester.RSpec.Output.ts.ps1 +++ b/tst/Pester.RSpec.Output.ts.ps1 @@ -295,4 +295,25 @@ i -PassThru:$PassThru { $normalOutput | Verify-Equal $writehostOutput } } + + b 'Pending is deprecated' { + t 'Shows deprecated message when -pending is used' { + $sb = { + $container = New-PesterContainer -ScriptBlock { + Describe 'd' { + It 'i' { + Set-ItResult -Pending + } + } + } + + Invoke-Pester -Container $container + } + + $output = Invoke-InNewProcess -ScriptBlock $sb + + $deprecated = $output | Select-String -Pattern '\*DEPRECATED\*' + @($deprecated).Count | Verify-Equal 1 + } + } }