Closed plastikfan closed 3 years ago
add this test to rules.tests.ps1:
Describe 'MustNotBeInAllParameterSetsByAccident' {
BeforeAll {
InModuleScope Elizium.Loopz {
function script:test-ParamInAllParameterSetsByAccident {
param(
[Parameter(ValueFromPipeline = $true)]
[object]$Chaff,
[Parameter(ParameterSetName = 'Alpha', Mandatory, Position = 1)]
[object]$paramA,
[Parameter()]
[Parameter(ParameterSetName = 'Alpha', Position = 2)]
[object]$paramB,
[Parameter(ParameterSetName = 'Alpha', Position = 3)]
[object]$paramC,
[Parameter(ParameterSetName = 'Beta', Position = 1)]
[object]$paramD,
[Parameter()]
[Parameter(ParameterSetName = 'Beta', Position = 2)]
[object]$paramE
)
}
}
}
Context 'given: functions with violations' {
It 'should: report violations' -Tag 'Current' {
InModuleScope Elizium.Loopz {
[string]$commandName = 'test-ParamInAllParameterSetsByAccident';
[CommandInfo]$commandInfo = Get-Command $commandName;
[RuleController]$controller = [RuleController]::new($commandInfo);
[syntax]$syntax = New-Syntax -CommandName $commandName -Signals $_signals -Scribbler $_scribbler;
$controller.Test($syntax).Result | Should -Be $false;
$commandInfo | Show-ParameterSetReport;
}
}
} # given: functions with violations
}
The 'Other Parameter Sets' statement can sometime show an empty parameter set name. This is clearly not correct.
The display for this rules violation needs to be checked. Currently the stragtegy is to take each parameter set, and for each one of its parameters check to see if it in multiple parameter sets and if so, is one of them the '__AllParameterSets'. If it is then the rule is violated. However, the logic behind the so called 'other' parameter sets is not clear and should probably be replaced.
All we need to show is the violating parameter set and the parameter that is causing the violation. So in this example, we have 2 violations: 'ClaimB' and 'ClaimE', so all we need to show is:
and
(Note: the example was copied from another test case, so the variable names dont make sense; make sure the rename the parameters so they make sense for this test)