Skip to content

Commit 59ca241

Browse files
test fixes
1 parent 16388f8 commit 59ca241

File tree

11 files changed

+109
-10
lines changed

11 files changed

+109
-10
lines changed

PSFramework/bin/PSFramework.dll

512 Bytes
Binary file not shown.

PSFramework/bin/PSFramework.pdb

0 Bytes
Binary file not shown.

PSFramework/functions/data/Register-PSFPsd1Converter.psd1 renamed to PSFramework/functions/data/Register-PSFPsd1Converter.ps1

File renamed without changes.
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
function HaveParameters {
2+
[CmdletBinding()]
3+
param (
4+
$ActualValue,
5+
6+
[string[]]
7+
$Parameters,
8+
9+
[switch]
10+
$Negate,
11+
12+
$CallerSessionState
13+
)
14+
end {
15+
$commonParameters = 'Verbose', 'Debug', 'ErrorAction', 'WarningAction', 'InformationAction', 'ErrorVariable', 'WarningVariable', 'InformationVariable', 'OutVariable', 'OutBuffer', 'PipelineVariable', 'ProgressAction'
16+
if ($global:__pester_data.CommonParameters) { $commonParameters = $global:__pester_data.CommonParameters }
17+
18+
#region Resolve Command
19+
if ($null -eq $ActualValue) {
20+
return [PSCustomObject]@{
21+
Succeeded = $false
22+
FailureMessage = "Did not receive a command to test"
23+
}
24+
}
25+
26+
$command = $ActualValue
27+
if ($command -isnot [System.Management.Automation.CommandInfo]) {
28+
try { $command = Get-Command $ActualValue -ErrorAction Stop }
29+
catch {
30+
return [PSCustomObject]@{
31+
Succeeded = $false
32+
FailureMessage = "Unable to resolve command: $ActualValue"
33+
}
34+
}
35+
}
36+
#endregion Resolve Command
37+
38+
#region Negation
39+
if ($Negate) {
40+
$found = @()
41+
foreach ($parameter in $Parameters) {
42+
if ($parameter -notin $command.Parameters.Keys) { continue }
43+
$found += $parameter
44+
}
45+
46+
if ($found) {
47+
return [PSCustomObject]@{
48+
Succeeded = $false
49+
FailureMessage = "Parameters found on $($command.Name): $($found -join ', ')"
50+
}
51+
}
52+
return [PSCustomObject]@{
53+
Succeeded = $true
54+
FailureMessage = "None of the forbidden parameters found on $($command.Name) (Forbidden: $($Parameters -join ', '))"
55+
}
56+
}
57+
#endregion Negation
58+
59+
#region Regular Parameter Test
60+
$notFound = @()
61+
$excessFound = @()
62+
63+
foreach ($parameter in $command.Parameters.Keys) {
64+
if ($parameter -in $commonParameters) { continue }
65+
if ($parameter -in $Parameters) { continue }
66+
$excessFound += $parameter
67+
}
68+
69+
foreach ($parameter in $Parameters) {
70+
if ($parameter -in $command.Parameters.Keys) { continue }
71+
$notFound += $parameter
72+
}
73+
74+
if (-not $notFound -and -not $excessFound) {
75+
return [PSCustomObject]@{
76+
Succeeded = $true
77+
FailureMessage = "All expected parameters found on $($command.Name) (Expected: $($Parameters -join ', '))"
78+
}
79+
}
80+
81+
$fragments = @()
82+
if ($notFound) { $fragments += "Missing: $($notFound -join ', ')" }
83+
if ($excessFound) { $fragments += "Unexpected: $($excessFound -join ', ')" }
84+
85+
return [PSCustomObject]@{
86+
Succeeded = $false
87+
FailureMessage = "Parameters found on $($command.Name) not as desired | Expected: $($Parameters -join ', ') | $($fragments -join ' | ')"
88+
}
89+
#endregion Regular Parameter Test
90+
}
91+
}
92+
Add-ShouldOperator -Name HaveParameters -Test $function:HaveParameters

PSFramework/tests/functions/configuration/Get-PSFConfig.Tests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# Catch any signature changes to force revisiting the command
1414
It "Should have the designed for parameters & sets" {
1515
(Get-Command Get-PSFConfig).ParameterSets.Name | Should -Be 'FullName', 'Module'
16-
(Get-Command Get-PSFConfig).Parameters.Keys | Should -Be 'FullName', 'Name', 'Module', 'Persisted', 'Force', 'Verbose', 'Debug', 'ErrorAction', 'WarningAction', 'InformationAction', 'ErrorVariable', 'WarningVariable', 'InformationVariable', 'OutVariable', 'OutBuffer', 'PipelineVariable', 'ProgressAction'
16+
Get-Command Get-PSFConfig | Should -HaveParameters 'FullName', 'Name', 'Module', 'Persisted', 'Force'
1717
}
1818

1919
It "Should find the correct Configuration item" {

PSFramework/tests/functions/configuration/Register-PSFConfig.Tests.ps1

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313
# Catch any signature changes to force revisiting the command
1414
It "Should have the designed for parameters & sets" {
1515
(Get-Command Register-PSFConfig).ParameterSets.Name | Should -Be 'Default', 'Name'
16-
$properties = 'Config', 'FullName', 'Module', 'Name', 'Scope', 'EnableException', 'Verbose', 'Debug', 'ErrorAction', 'WarningAction', 'InformationAction', 'ErrorVariable', 'WarningVariable', 'InformationVariable', 'OutVariable', 'OutBuffer', 'PipelineVariable', 'ProgressAction'
17-
Compare-Object $properties ((Get-Command Register-PSFConfig).Parameters.Keys | Remove-PSFNull -Enumerate) | Should -BeNullOrEmpty
16+
Get-Command Register-PSFConfig | Should -HaveParameters 'Config', 'FullName', 'Module', 'Name', 'Scope', 'EnableException'
1817
}
1918

2019
Context "Validating registry persistence" {

PSFramework/tests/functions/configuration/Register-PSFConfigValidation.Tests.ps1

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313
# Catch any signature changes to force revisiting the command
1414
It "Should have the designed for parameters & sets" {
1515
(Get-Command Register-PSFConfigValidation).ParameterSets.Name | Should -Be '__AllParameterSets'
16-
$properties = 'Name', 'ScriptBlock', 'Verbose', 'Debug', 'ErrorAction', 'WarningAction', 'InformationAction', 'ErrorVariable', 'WarningVariable', 'InformationVariable', 'OutVariable', 'OutBuffer', 'PipelineVariable', 'ProgressAction'
17-
Compare-Object $properties ((Get-Command Register-PSFConfigValidation).Parameters.Keys | Remove-PSFNull -Enumerate) | Should -BeNullOrEmpty
16+
Get-Command Register-PSFConfigValidation | Should -HaveParameters 'Name', 'ScriptBlock'
1817
}
1918

2019
Context "Ensuring validation can be created, assigned and used" {

PSFramework/tests/functions/configuration/Set-PSFConfig.Tests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
# Catch any signature changes to force revisiting the command
1717
It "Should have the designed for parameters & sets" {
1818
(Get-Command Set-PSFConfig).ParameterSets.Name | Should -Be 'FullName', 'Persisted', 'Module'
19-
(Get-Command Set-PSFConfig).Parameters.Keys | Should -Be 'FullName', 'Module', 'Name', 'Value', 'PersistedValue', 'PersistedType', 'Description', 'Validation', 'Handler', 'Hidden', 'Default', 'Initialize', 'SimpleExport', 'ModuleExport', 'AllowDelete', 'DisableValidation', 'DisableHandler', 'PassThru', 'EnableException', 'Verbose', 'Debug', 'ErrorAction', 'WarningAction', 'InformationAction', 'ErrorVariable', 'WarningVariable', 'InformationVariable', 'OutVariable', 'OutBuffer', 'PipelineVariable', 'ProgressAction'
19+
Get-Command Set-PSFConfig | Should -HaveParameters 'FullName', 'Module', 'Name', 'Value', 'PersistedValue', 'PersistedType', 'Description', 'Validation', 'Handler', 'Hidden', 'Default', 'Initialize', 'SimpleExport', 'ModuleExport', 'AllowDelete', 'DisableValidation', 'DisableHandler', 'PassThru', 'EnableException'
2020
}
2121

2222
Describe "Basic functionality tests" {

PSFramework/tests/functions/configuration/Unregister-PSFConfig.Tests.ps1

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313
# Catch any signature changes to force revisiting the command
1414
It "Should have the designed for parameters & sets" {
1515
(Get-Command Unregister-PSFConfig).ParameterSets.Name | Should -Be 'Pipeline', 'Module'
16-
$properties = 'ConfigurationItem', 'PersistedItem', 'FullName', 'Module', 'Name', 'Scope', 'Verbose', 'Debug', 'ErrorAction', 'WarningAction', 'InformationAction', 'ErrorVariable', 'WarningVariable', 'InformationVariable', 'OutVariable', 'OutBuffer', 'PipelineVariable', 'ProgressAction'
17-
Compare-Object $properties ((Get-Command Unregister-PSFConfig).Parameters.Keys | Remove-PSFNull -Enumerate) | Should -BeNullOrEmpty
16+
Get-Command Unregister-PSFConfig | Should -HaveParameters 'ConfigurationItem', 'PersistedItem', 'FullName', 'Module', 'Name', 'Scope'
1817
}
1918

2019
function New-Location

PSFramework/tests/pester.ps1

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ Write-Host "Starting Tests"
2323
Write-Host "Importing Module"
2424

2525
$global:testroot = $PSScriptRoot
26-
$global:__pester_data = @{ }
26+
$global:__pester_data = @{
27+
CommonParameters = 'Verbose', 'Debug', 'ErrorAction', 'WarningAction', 'InformationAction', 'ErrorVariable', 'WarningVariable', 'InformationVariable', 'OutVariable', 'OutBuffer', 'PipelineVariable', 'ProgressAction'
28+
}
2729

2830
if (-not $NoImport) {
2931
Remove-Module PSFramework -ErrorAction Ignore

0 commit comments

Comments
 (0)