File tree 2 files changed +16
-4
lines changed 2 files changed +16
-4
lines changed Original file line number Diff line number Diff line change @@ -43,6 +43,7 @@ private struct RuleParameters
43
43
private bool hasInitializationError ;
44
44
private string reference ;
45
45
private readonly string defaultReference = "desktop-5.1.14393.206-windows" ;
46
+ private readonly string alternativeDefaultReference = "core-6.0.2-windows" ;
46
47
private RuleParameters ruleParameters ;
47
48
48
49
public UseCompatibleCmdlets ( )
@@ -274,6 +275,10 @@ private void SetupCmdletsDictionary()
274
275
275
276
ruleParameters . compatibility = compatibilityList . ToArray ( ) ;
276
277
reference = defaultReference ;
278
+ if ( compatibilityList . Count == 1 && compatibilityList [ 0 ] == defaultReference )
279
+ {
280
+ reference = alternativeDefaultReference ;
281
+ }
277
282
#if DEBUG
278
283
// Setup reference file
279
284
object referenceObject ;
@@ -326,7 +331,7 @@ private void SetupCmdletsDictionary()
326
331
return ;
327
332
}
328
333
329
- var extentedCompatibilityList = compatibilityList . Concat ( Enumerable . Repeat ( reference , 1 ) ) ;
334
+ var extentedCompatibilityList = compatibilityList . Union ( Enumerable . Repeat ( reference , 1 ) ) ;
330
335
foreach ( var compat in extentedCompatibilityList )
331
336
{
332
337
string psedition , psversion , os ;
Original file line number Diff line number Diff line change @@ -26,9 +26,11 @@ Describe "UseCompatibleCmdlets" {
26
26
process
27
27
{
28
28
It (" found {0} violations for '{1}'" -f $expectedViolations , $command ) {
29
- Invoke-ScriptAnalyzer - ScriptDefinition $command - IncludeRule $ruleName - Settings $settings | `
30
- Get-Count | `
31
- Should - Be $expectedViolations
29
+ $warnings = Invoke-ScriptAnalyzer - ScriptDefinition $command - IncludeRule $ruleName - Settings $settings
30
+ $warnings.Count | Should - Be $expectedViolations
31
+ $warnings | ForEach-Object {
32
+ $_.RuleName | Should - Be ' PSUseCompatibleCmdlets'
33
+ }
32
34
}
33
35
}
34
36
}
@@ -54,4 +56,9 @@ Describe "UseCompatibleCmdlets" {
54
56
@ (" Start-VM" , " New-SmbShare" , " Get-Disk" ) | `
55
57
Test-Command - Settings $settings - ExpectedViolations 1
56
58
}
59
+
60
+ Context " Default reference can also be used as target platform" {
61
+ $settings = @ {rules = @ {PSUseCompatibleCmdlets = @ {compatibility = @ (" desktop-5.1.14393.206-windows" )}}}
62
+ @ (" Remove-Service" ) | Test-Command - Settings $settings - ExpectedViolations 1
63
+ }
57
64
}
You can’t perform that action at this time.
0 commit comments