diff --git a/Tests/Rules/AvoidUsingAlias.tests.ps1 b/Tests/Rules/AvoidUsingAlias.tests.ps1 index 6552bb1ac..478646c27 100644 --- a/Tests/Rules/AvoidUsingAlias.tests.ps1 +++ b/Tests/Rules/AvoidUsingAlias.tests.ps1 @@ -101,8 +101,18 @@ Configuration MyDscConfiguration { } It "do not warn when about Get-* completed cmdlets when the command exists natively on Unix platforms" -skip:(-not ($IsLinux -or $IsMacOS)) { - $violations = Invoke-ScriptAnalyzer -IncludeRule PSAvoidUsingCmdletAliases -ExcludeRule PSUseCompatibleCommands -ScriptDefinition 'date' | Where-Object { $_.RuleName -eq $violationName } - $violations[0].Message | Should -Be '' + $nativeLinuxCommand = 'date' + $dateCommand = Get-Command $nativeLinuxCommand -CommandType Application -ErrorAction Ignore + + $violations = Invoke-ScriptAnalyzer -IncludeRule PSAvoidUsingCmdletAliases -ExcludeRule PSUseCompatibleCommands -ScriptDefinition $nativeLinuxCommand | Where-Object { $_.RuleName -eq $violationName } + + $expectedViolations = 1 + if ($dateCommand) + { + $expectedViolations = 0 + } + + $violations.Count | Should -Be $expectedViolations } } }