Skip to content

Commit

Permalink
Add OutputType to improve tab-completion/intellisense (#2519)
Browse files Browse the repository at this point in the history
* Add OutputType to public functions for tab completion

* Add OutputType to a few internal methods
  • Loading branch information
fflaten committed Jul 1, 2024
1 parent 6754b26 commit e6b2c8c
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/Main.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,7 @@ function Invoke-Pester {
# Currently doesn't work. $IgnoreUnsafeCommands filter used in rule as workaround
# [Diagnostics.CodeAnalysis.SuppressMessageAttribute('Pester.BuildAnalyzerRules\Measure-SafeCommands', 'Remove-Variable', Justification = 'Remove-Variable can't remove "optimized variables" when using "alias" for Remove-Variable.')]
[CmdletBinding(DefaultParameterSetName = 'Simple')]
[OutputType([Pester.Run])]
param(
[Parameter(Position = 0, Mandatory = 0, ParameterSetName = "Simple")]
[Parameter(Position = 0, Mandatory = 0, ParameterSetName = "Legacy")] # Legacy set for v4 compatibility during migration - deprecated
Expand Down
2 changes: 2 additions & 0 deletions src/Pester.RSpec.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ function New-PesterConfiguration {
about_PesterConfiguration
#>
[CmdletBinding()]
[OutputType([PesterConfiguration])]
param(
[System.Collections.IDictionary] $Hashtable
)
Expand Down Expand Up @@ -543,6 +544,7 @@ function New-PesterContainer {
https://pester.dev/docs/usage/data-driven-tests
#>
[CmdletBinding(DefaultParameterSetName = "Path")]
[OutputType([Pester.ContainerInfo])]
param(
[Parameter(Mandatory, ParameterSetName = "Path")]
[String[]] $Path,
Expand Down
6 changes: 4 additions & 2 deletions src/Pester.Runtime.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ function Reset-PerContainerState {
}

function Find-Test {
[OutputType([Pester.Container])]
[CmdletBinding()]
param (
[Parameter(Mandatory = $true)]
Expand Down Expand Up @@ -138,6 +139,7 @@ function Find-Test {
}

function ConvertTo-DiscoveredBlockContainer {
[OutputType([Pester.Container])]
param (
[Parameter(Mandatory = $true)]
$Block
Expand All @@ -148,6 +150,7 @@ function ConvertTo-DiscoveredBlockContainer {
}

function ConvertTo-ExecutedBlockContainer {
[OutputType([Pester.Container])]
param (
[Parameter(Mandatory = $true)]
$Block
Expand All @@ -156,8 +159,6 @@ function ConvertTo-ExecutedBlockContainer {
foreach ($b in $Block) {
[Pester.Container]::CreateFromBlock($b)
}


}

function New-ParametrizedBlock {
Expand Down Expand Up @@ -2479,6 +2480,7 @@ function Invoke-BlockContainer {
}

function New-BlockContainerObject {
[OutputType([Pester.ContainerInfo])]
[CmdletBinding()]
param (
[Parameter(Mandatory, ParameterSetName = 'ScriptBlock')]
Expand Down
6 changes: 4 additions & 2 deletions src/functions/New-Fixture.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
.LINK
https://pester.dev/docs/commands/Should
#>
[OutputType([System.IO.FileInfo])]
param (
[Parameter(Mandatory = $true)]
[String]$Name,
Expand All @@ -78,7 +79,7 @@
$Name = $Name -replace '.ps(m?)1', ''

if ($Name -notmatch '^\S+$') {
throw "Name is not valid. Whitespace are not allowed in a function name."
throw 'Name is not valid. Whitespace are not allowed in a function name.'
}

#keep this formatted as is. the format is output to the file as is, including indentation
Expand All @@ -94,7 +95,7 @@ Describe "#name#" {
It "Returns expected output" {
#name# | Should -Be "YOUR_EXPECTED_VALUE"
}
}' -replace "#name#", $Name
}' -replace '#name#', $Name

$Path = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($Path)

Expand All @@ -104,6 +105,7 @@ Describe "#name#" {

function Create-File {
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('Pester.BuildAnalyzerRules\Measure-SafeCommands', 'Write-Warning', Justification = 'Mocked in unit test for New-Fixture.')]
[OutputType([System.IO.FileInfo])]
param($Path, $Name, $Content)
if (-not (& $SafeCommands['Test-Path'] -Path $Path)) {
& $SafeCommands['New-Item'] -ItemType Directory -Path $Path | & $SafeCommands['Out-Null']
Expand Down
6 changes: 4 additions & 2 deletions src/functions/TestResults.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,9 @@ function ConvertTo-NUnitReport {
.LINK
https://pester.dev/docs/commands/Invoke-Pester
#>
[OutputType([xml], [string])]
param (
[parameter(Mandatory = $true, ValueFromPipeline = $true)]
[Parameter(Mandatory = $true, ValueFromPipeline = $true)]
[Pester.Run] $Result,
[Switch] $AsString,

Expand Down Expand Up @@ -360,8 +361,9 @@ function ConvertTo-JUnitReport {
.LINK
https://pester.dev/docs/commands/Invoke-Pester
#>
[OutputType([xml], [string])]
param (
[parameter(Mandatory = $true, ValueFromPipeline = $true)]
[Parameter(Mandatory = $true, ValueFromPipeline = $true)]
[Pester.Run] $Result,
[Switch] $AsString
)
Expand Down

0 comments on commit e6b2c8c

Please sign in to comment.