Skip to content

Commit

Permalink
Add types tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rjmholt committed Apr 24, 2019
1 parent 5d53230 commit f775136
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Tests/Rules/UseCompatibleCommands.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ $script:Win10_5_profile = 'win-48_x64_10.0.17763.0_5.1.17763.316_x64_4.0.30319.4
$script:Win10_6_1_profile = 'win-48_x64_10.0.17763.0_6.1.3_x64_4.0.30319.42000_core'
$script:Ubuntu1804_6_1_profile = 'ubuntu_x64_18.04_6.1.3_x64_4.0.30319.42000_core'

$script:AzF_profile = Resolve-Path "$PSScriptRoot/../../PSCompatibilityCollector/optional_profiles/azurefunctions.json"
$script:AzA_profile = Resolve-Path "$PSScriptRoot/../../PSCompatibilityCollector/optional_profiles/azureautomation.json"
$script:AzF_profile = (Resolve-Path "$PSScriptRoot/../../PSCompatibilityCollector/optional_profiles/azurefunctions.json").Path
$script:AzA_profile = (Resolve-Path "$PSScriptRoot/../../PSCompatibilityCollector/optional_profiles/azureautomation.json").Path

$script:CompatibilityTestCases = @(
@{ Target = $script:Srv2012_3_profile; Script = 'Write-Information "Information"'; Commands = @("Write-Information"); Version = "3.0"; OS = "Windows"; ProblemCount = 1 }
Expand Down
52 changes: 52 additions & 0 deletions Tests/Rules/UseCompatibleTypes.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ $script:Win10_5_profile = 'win-48_x64_10.0.17763.0_5.1.17763.316_x64_4.0.30319.4
$script:Win10_6_1_profile = 'win-48_x64_10.0.17763.0_6.1.3_x64_4.0.30319.42000_core'
$script:Ubuntu1804_6_1_profile = 'ubuntu_x64_18.04_6.1.3_x64_4.0.30319.42000_core'

$script:AzF_profile = (Resolve-Path "$PSScriptRoot/../../PSCompatibilityCollector/optional_profiles/azurefunctions.json").Path
$script:AzA_profile = (Resolve-Path "$PSScriptRoot/../../PSCompatibilityCollector/optional_profiles/azureautomation.json").Path

$script:TypeCompatibilityTestCases = @(
@{ Target = $script:Srv2012_3_profile; Script = '[System.Management.Automation.ModuleIntrinsics]::GetModulePath("here", "there", "everywhere")'; Types = @('System.Management.Automation.ModuleIntrinsics'); Version = "3.0"; OS = 'Windows'; ProblemCount = 1 }
@{ Target = $script:Srv2012_3_profile; Script = '$ast -is [System.Management.Automation.Language.FunctionMemberAst]'; Types = @('System.Management.Automation.Language.FunctionMemberAst'); Version = "3.0"; OS = 'Windows'; ProblemCount = 1 }
Expand Down Expand Up @@ -166,4 +169,53 @@ Describe 'UseCompatibleTypes' {
$diagnostics.Count | Should -Be 0
}
}

Context 'Targeting new-form Az profiles alongside older profiles' {
BeforeAll {
$settings = @{
Rules = @{
$script:RuleName = @{
$script:TargetProfileConfigKey = @(
$script:AzF_profile
$script:AzA_profile
$script:Win10_5_profile
)
}
}
}
}

It "Finds AzF problems with a script" {
$diagnostics = Invoke-ScriptAnalyzer -IncludeRule $script:RuleName -Settings $settings -ScriptDefinition '
[System.Collections.Immutable.ImmutableList[string]]::Empty
[Microsoft.PowerShell.ToStringCodeMethods]::PropertyValueCollection($obj)
'

$diagnostics.Count | Should -Be 2
$diagnosticGroups = Group-Object $diagnostics -Property Type
foreach ($group in $diagnosticGroups)
{
switch ($group.Name)
{
'System.Collections.Immutable.ImmutableList[System.String]'
{
$group.Count | Should -Be 2
$group[0].Group.TargetPlatform.PowerShell.Version.Major | Should -Be 5
$group[1].Group.TargetPlatform.PowerShell.Version.Major | Should -Be 5
}

'Microsoft.PowerShellToStringCodeMethods'
{
$group.Count | Should -Be 1
$group[0].Group.TargetPlatform.PowerShell.Version.Major | Should -Be 6
}

default
{
$group | Should -Be $null
}
}
}
}
}
}

0 comments on commit f775136

Please sign in to comment.