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

Add OutputType to improve tab-completion/intellisense #2519

Merged
merged 2 commits into from
Jul 1, 2024
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
1 change: 1 addition & 0 deletions src/Main.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,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 @@ -481,6 +481,7 @@ function New-PesterConfiguration {
https://pester.dev/docs/commands/Invoke-Pester
#>
[CmdletBinding()]
[OutputType([PesterConfiguration])]
param(
[System.Collections.IDictionary] $Hashtable
)
Expand Down Expand Up @@ -683,6 +684,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