From 046cd5e13442e668244c65be5ca18332985e1abb Mon Sep 17 00:00:00 2001 From: alx9r Date: Tue, 30 May 2017 11:56:38 -0700 Subject: [PATCH 1/6] fix comment-based help so that synopsis is published for Setup command --- Functions/TestDrive.ps1 | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Functions/TestDrive.ps1 b/Functions/TestDrive.ps1 index 21dbdfac2..9a02e8876 100644 --- a/Functions/TestDrive.ps1 +++ b/Functions/TestDrive.ps1 @@ -130,7 +130,10 @@ function Remove-TestDrive { } function Setup { - #included for backwards compatibility + <# + .SYNOPSIS + This command is included in the Pester Mocking framework for backwards compatibility. You do not need to call it directly. + #> param( [switch]$Dir, [switch]$File, From 6df936e2482c0a1f84d34b09539ba2242c6370ab Mon Sep 17 00:00:00 2001 From: alx9r Date: Tue, 30 May 2017 12:06:50 -0700 Subject: [PATCH 2/6] test public commands for CmdletBinding --- Pester.Tests.ps1 | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Pester.Tests.ps1 b/Pester.Tests.ps1 index 9b34f98dd..d97130417 100644 --- a/Pester.Tests.ps1 +++ b/Pester.Tests.ps1 @@ -115,6 +115,22 @@ if ($PSVersionTable.PSVersion.Major -ge 3) } } +Describe 'Public API' { + It 'all non-deprecated public commands use CmdletBinding' { + $r = Get-Command -Module Pester | + ? { -not $_.CmdletBinding } | + % Name | + ? { + $_ -notin @( + 'Get-TestDriveItem' # deprecated in 4.0 + 'SafeGetCommand' # Pester internal + 'Setup' # deprecated + ) + } + $r | Should beNullOrEmpty + } +} + Describe 'Style rules' { $pesterRoot = (Get-Module Pester).ModuleBase From d2bac9cc56c2e99957fd3b4bb3a9e795b8e2ed3c Mon Sep 17 00:00:00 2001 From: alx9r Date: Tue, 30 May 2017 12:18:36 -0700 Subject: [PATCH 3/6] add [CmdletBinding()] to Set-TestInconclusive, In, Mock, and Assert-VerifiableMocks --- Functions/Assertions/Set-TestInconclusive.ps1 | 1 + Functions/In.ps1 | 10 +++++----- Functions/Mock.ps1 | 3 ++- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/Functions/Assertions/Set-TestInconclusive.ps1 b/Functions/Assertions/Set-TestInconclusive.ps1 index e01380e7a..a6ab8cfa1 100644 --- a/Functions/Assertions/Set-TestInconclusive.ps1 +++ b/Functions/Assertions/Set-TestInconclusive.ps1 @@ -51,6 +51,7 @@ function Set-TestInconclusive { .LINK https://github.com/pester/Pester/wiki/Set%E2%80%90TestInconclusive #> + [CmdletBinding()] param ( [string] $Message ) diff --git a/Functions/In.ps1 b/Functions/In.ps1 index b7552a1ad..177997c8b 100644 --- a/Functions/In.ps1 +++ b/Functions/In.ps1 @@ -16,11 +16,11 @@ The path that the execute block will be executed in. The script to be executed in the path provided. #> - -param( - $path, - [ScriptBlock] $execute -) + [CmdletBinding()] + param( + $path, + [ScriptBlock] $execute + ) Assert-DescribeInProgress -CommandName In $old_pwd = $pwd diff --git a/Functions/Mock.ps1 b/Functions/Mock.ps1 index 713724032..32d30245d 100644 --- a/Functions/Mock.ps1 +++ b/Functions/Mock.ps1 @@ -154,7 +154,7 @@ It about_Should about_Mocking #> - + [CmdletBinding()] param( [string]$CommandName, [ScriptBlock]$MockWith={}, @@ -405,6 +405,7 @@ Assert-VerifiableMocks This will not throw an exception because the mock was invoked. #> + [CmdletBinding()]param() Assert-DescribeInProgress -CommandName Assert-VerifiableMocks $unVerified=@{} From 24e1f5e036c2e2615386683dd6cde31d061bc1b0 Mon Sep 17 00:00:00 2001 From: alx9r Date: Tue, 30 May 2017 12:29:50 -0700 Subject: [PATCH 4/6] add [CmdletBinding()] to BeforeAll, BeforeEach, AfterAll, AfterEach --- Functions/SetupTeardown.ps1 | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/Functions/SetupTeardown.ps1 b/Functions/SetupTeardown.ps1 index 1e2314fbc..f3a95ca17 100644 --- a/Functions/SetupTeardown.ps1 +++ b/Functions/SetupTeardown.ps1 @@ -15,6 +15,15 @@ function BeforeEach .LINK about_BeforeEach_AfterEach #> + [CmdletBinding()] + param + ( + # the scriptblock to execute + [Parameter(Mandatory = $true, + Position = 1)] + [Scriptblock] + $Scriptblock + ) Assert-DescribeInProgress -CommandName BeforeEach } @@ -35,6 +44,15 @@ function AfterEach .LINK about_BeforeEach_AfterEach #> + [CmdletBinding()] + param + ( + # the scriptblock to execute + [Parameter(Mandatory = $true, + Position = 1)] + [Scriptblock] + $Scriptblock + ) Assert-DescribeInProgress -CommandName AfterEach } @@ -53,6 +71,15 @@ function BeforeAll .LINK about_BeforeEach_AfterEach #> + [CmdletBinding()] + param + ( + # the scriptblock to execute + [Parameter(Mandatory = $true, + Position = 1)] + [Scriptblock] + $Scriptblock + ) Assert-DescribeInProgress -CommandName BeforeAll } @@ -71,6 +98,15 @@ function AfterAll .LINK about_BeforeEach_AfterEach #> + [CmdletBinding()] + param + ( + # the scriptblock to execute + [Parameter(Mandatory = $true, + Position = 1)] + [Scriptblock] + $Scriptblock + ) Assert-DescribeInProgress -CommandName AfterAll } From c2bfac98cd11c9d2fd13b199c263e44c5f526181 Mon Sep 17 00:00:00 2001 From: alx9r Date: Sun, 4 Jun 2017 12:54:43 -0700 Subject: [PATCH 5/6] make test for CmdletBinding work for PowerShell 2 --- Pester.Tests.ps1 | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Pester.Tests.ps1 b/Pester.Tests.ps1 index d97130417..3fb04bf3a 100644 --- a/Pester.Tests.ps1 +++ b/Pester.Tests.ps1 @@ -116,16 +116,17 @@ if ($PSVersionTable.PSVersion.Major -ge 3) } Describe 'Public API' { - It 'all non-deprecated public commands use CmdletBinding' { + It 'all non-deprecated, non-internal public commands use CmdletBinding' { $r = Get-Command -Module Pester | ? { -not $_.CmdletBinding } | - % Name | + ? { $_.CommandType -ne 'Alias' } | # Get-Command outputs aliases in PowerShell 2 + % { $_.Name } | ? { - $_ -notin @( + @( 'Get-TestDriveItem' # deprecated in 4.0 'SafeGetCommand' # Pester internal 'Setup' # deprecated - ) + ) -notcontains $_ } $r | Should beNullOrEmpty } From 0f69d99080e646af12b3db943d02228785458718 Mon Sep 17 00:00:00 2001 From: alx9r Date: Sun, 4 Jun 2017 13:06:22 -0700 Subject: [PATCH 6/6] change order of filters to avoid "Property cannot be found" in PowerShell 2 --- Pester.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Pester.Tests.ps1 b/Pester.Tests.ps1 index 3fb04bf3a..ef95a213c 100644 --- a/Pester.Tests.ps1 +++ b/Pester.Tests.ps1 @@ -118,8 +118,8 @@ if ($PSVersionTable.PSVersion.Major -ge 3) Describe 'Public API' { It 'all non-deprecated, non-internal public commands use CmdletBinding' { $r = Get-Command -Module Pester | - ? { -not $_.CmdletBinding } | ? { $_.CommandType -ne 'Alias' } | # Get-Command outputs aliases in PowerShell 2 + ? { -not $_.CmdletBinding } | % { $_.Name } | ? { @(