Skip to content

Commit 7317423

Browse files
committed
Add script test for compatible commands
1 parent 1e07967 commit 7317423

File tree

2 files changed

+71
-1
lines changed

2 files changed

+71
-1
lines changed

Tests/Rules/CompatibilityRuleAssets/IncompatibleScript.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ while ($stack.Count -gt 0)
3333
Write-Information $t.GetString()
3434
}
3535

36-
Get-EventLog -Name System | ogv
36+
Get-EventLog -LogName System | ogv
3737

3838
Invoke-WebRequest -Uri 'https://aka.ms/everyonebehappy/' -NoProxy -SkipHeaderValidation
3939

Tests/Rules/UseCompatibleCommands.Tests.ps1

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,77 @@ Describe 'UseCompatibleCommands' {
198198
$diagnostics[$i].TargetPlatform.PowerShell.Version.Minor | Should -Be $Version.Minor
199199
}
200200
}
201+
}
202+
203+
Context "Checking a file against many targets" {
204+
It "Finds all command problems" {
205+
$settings = @{
206+
Rules = @{
207+
$script:RuleName = @{
208+
Enable = $true
209+
$script:TargetProfileConfigKey = @(
210+
$script:Srv2012_3_profile
211+
$script:Srv2012r2_4_profile
212+
$script:Srv2012r2_6_1_profile
213+
$script:Srv2016_5_profile
214+
$script:Srv2016_6_1_profile
215+
$script:Srv2019_5_profile
216+
$script:Srv2019_6_1_profile
217+
$script:Win10_5_profile
218+
$script:Win10_6_1_profile
219+
$script:Ubuntu1804_6_1_profile
220+
$script:Debian8_6_1_profile
221+
$script:Rhel76_6_1_profile
222+
)
223+
}
224+
}
225+
}
226+
227+
$diagnostics = Invoke-ScriptAnalyzer -Path "$PSScriptRoot/CompatibilityRuleAssets/IncompatibleScript.ps1" -IncludeRule $script:RuleName -Settings $settings
228+
229+
$diagnostics.Count | Should -Be 28
230+
231+
$diagnosticGroups = Group-Object -InputObject $diagnostics -Property Command
232+
233+
foreach ($group in $diagnosticGroups)
234+
{
235+
switch ($group.Name)
236+
{
237+
'Get-EventLog'
238+
{
239+
$group.Count | Should -Be 7
240+
break
241+
}
242+
243+
'Import-Module'
244+
{
245+
$group.Count | Should -Be 2
246+
break
247+
}
248+
249+
'Invoke-WebRequest'
250+
{
251+
$group.Count | Should -Be 10
252+
break
253+
}
254+
255+
'ogv'
256+
{
257+
$group.Count | Should -Be 7
258+
break
259+
}
260+
261+
'Write-Information'
262+
{
263+
$group.Count | Should -Be 2
264+
break
265+
}
266+
}
267+
}
268+
}
269+
}
201270

271+
Context "Checking PSSA repository scripts" {
202272
It "Ensures that PSSA build scripts are cross compatible with everything" {
203273
$settings = @{
204274
Rules = @{

0 commit comments

Comments
 (0)