From e7207aa2a3b3f0250600c65db107d2993b0821f3 Mon Sep 17 00:00:00 2001 From: dchristian3188 Date: Tue, 11 Jul 2017 22:42:14 -0700 Subject: [PATCH 1/5] Added tests for builtin type accelerators --- .../Language/Parser/TypeAccelerator.Tests.ps1 | 414 +++++++++++++++++- 1 file changed, 409 insertions(+), 5 deletions(-) diff --git a/test/powershell/Language/Parser/TypeAccelerator.Tests.ps1 b/test/powershell/Language/Parser/TypeAccelerator.Tests.ps1 index 8e8c5744d77..398d7caf752 100644 --- a/test/powershell/Language/Parser/TypeAccelerator.Tests.ps1 +++ b/test/powershell/Language/Parser/TypeAccelerator.Tests.ps1 @@ -1,17 +1,411 @@ Describe "Type accelerators" -Tags "CI" { - $TypeAcceleratorsType = [psobject].Assembly.GetType("System.Management.Automation.TypeAccelerators") + BeforeAll { + + $TypeAcceleratorsType = [psobject].Assembly.GetType("System.Management.Automation.TypeAccelerators") + + $TypeAccelerators = $TypeAcceleratorsType::Get + $TypeAcceleratorsType::Add('msft_2174855', [int]) + $TypeAcceleratorsType::Add('msft_2174855_rm', [int]) - $TypeAccelerators = $TypeAcceleratorsType::Get - $TypeAcceleratorsType::Add('msft_2174855', [int]) - $TypeAcceleratorsType::Add('msft_2174855_rm', [int]) + $TypeAcceleratorTestCases = @( + @{ + Accelerator = 'Alias' + Type = [System.Management.Automation.AliasAttribute] + } + @{ + Accelerator = 'AllowEmptyCollection' + Type = [System.Management.Automation.AllowEmptyCollectionAttribute] + } + @{ + Accelerator = 'AllowEmptyString' + Type = [System.Management.Automation.AllowEmptyStringAttribute] + } + @{ + Accelerator = 'AllowNull' + Type = [System.Management.Automation.AllowNullAttribute] + } + @{ + Accelerator = 'ArgumentCompleter' + Type = [System.Management.Automation.ArgumentCompleterAttribute] + } + @{ + Accelerator = 'array' + Type = [System.Array] + } + @{ + Accelerator = 'bool' + Type = [System.Boolean] + } + @{ + Accelerator = 'byte' + Type = [System.Byte] + } + @{ + Accelerator = 'char' + Type = [System.Char] + } + @{ + Accelerator = 'CmdletBinding' + Type = [System.Management.Automation.CmdletBindingAttribute] + } + @{ + Accelerator = 'datetime' + Type = [System.DateTime] + } + @{ + Accelerator = 'decimal' + Type = [System.Decimal] + } + @{ + Accelerator = 'double' + Type = [System.Double] + } + @{ + Accelerator = 'DscResource' + Type = [System.Management.Automation.DscResourceAttribute] + } + @{ + Accelerator = 'float' + Type = [System.Single] + } + @{ + Accelerator = 'single' + Type = [System.Single] + } + @{ + Accelerator = 'guid' + Type = [System.Guid] + } + @{ + Accelerator = 'hashtable' + Type = [System.Collections.Hashtable] + } + @{ + Accelerator = 'int' + Type = [System.Int32] + } + @{ + Accelerator = 'int32' + Type = [System.Int32] + } + @{ + Accelerator = 'int16' + Type = [System.Int16] + } + @{ + Accelerator = 'long' + Type = [System.Int64] + } + @{ + Accelerator = 'int64' + Type = [System.Int64] + } + @{ + Accelerator = 'ciminstance' + Type = [Microsoft.Management.Infrastructure.CimInstance] + } + @{ + Accelerator = 'cimclass' + Type = [Microsoft.Management.Infrastructure.CimClass] + } + @{ + Accelerator = 'cimtype' + Type = [Microsoft.Management.Infrastructure.CimType] + } + @{ + Accelerator = 'cimconverter' + Type = [Microsoft.Management.Infrastructure.CimConverter] + } + @{ + Accelerator = 'IPEndpoint' + Type = [System.Net.IPEndPoint] + } + @{ + Accelerator = 'NullString' + Type = [System.Management.Automation.Language.NullString] + } + @{ + Accelerator = 'OutputType' + Type = [System.Management.Automation.OutputTypeAttribute] + } + @{ + Accelerator = 'ObjectSecurity' + Type = [System.Security.AccessControl.ObjectSecurity] + } + @{ + Accelerator = 'Parameter' + Type = [System.Management.Automation.ParameterAttribute] + } + @{ + Accelerator = 'PhysicalAddress' + Type = [System.Net.NetworkInformation.PhysicalAddress] + } + @{ + Accelerator = 'pscredential' + Type = [System.Management.Automation.PSCredential] + } + @{ + Accelerator = 'PSDefaultValue' + Type = [System.Management.Automation.PSDefaultValueAttribute] + } + @{ + Accelerator = 'pslistmodifier' + Type = [System.Management.Automation.PSListModifier] + } + @{ + Accelerator = 'psobject' + Type = [System.Management.Automation.PSObject] + } + @{ + Accelerator = 'pscustomobject' + Type = [System.Management.Automation.PSObject] + } + @{ + Accelerator = 'psprimitivedictionary' + Type = [System.Management.Automation.PSPrimitiveDictionary] + } + @{ + Accelerator = 'ref' + Type = [System.Management.Automation.PSReference] + } + @{ + Accelerator = 'PSTypeNameAttribute' + Type = [System.Management.Automation.PSTypeNameAttribute] + } + @{ + Accelerator = 'regex' + Type = [System.Text.RegularExpressions.Regex] + } + @{ + Accelerator = 'DscProperty' + Type = [System.Management.Automation.DscPropertyAttribute] + } + @{ + Accelerator = 'sbyte' + Type = [System.SByte] + } + @{ + Accelerator = 'string' + Type = [System.String] + } + @{ + Accelerator = 'SupportsWildcards' + Type = [System.Management.Automation.SupportsWildcardsAttribute] + } + @{ + Accelerator = 'switch' + Type = [System.Management.Automation.SwitchParameter] + } + @{ + Accelerator = 'cultureinfo' + Type = [System.Globalization.CultureInfo] + } + @{ + Accelerator = 'bigint' + Type = [System.Numerics.BigInteger] + } + @{ + Accelerator = 'securestring' + Type = [System.Security.SecureString] + } + @{ + Accelerator = 'timespan' + Type = [System.TimeSpan] + } + @{ + Accelerator = 'uint16' + Type = [System.UInt16] + } + @{ + Accelerator = 'uint32' + Type = [System.UInt32] + } + @{ + Accelerator = 'uint64' + Type = [System.UInt64] + } + @{ + Accelerator = 'uri' + Type = [System.Uri] + } + @{ + Accelerator = 'ValidateCount' + Type = [System.Management.Automation.ValidateCountAttribute] + } + @{ + Accelerator = 'ValidateDrive' + Type = [System.Management.Automation.ValidateDriveAttribute] + } + @{ + Accelerator = 'ValidateLength' + Type = [System.Management.Automation.ValidateLengthAttribute] + } + @{ + Accelerator = 'ValidateNotNull' + Type = [System.Management.Automation.ValidateNotNullAttribute] + } + @{ + Accelerator = 'ValidateNotNullOrEmpty' + Type = [System.Management.Automation.ValidateNotNullOrEmptyAttribute] + } + @{ + Accelerator = 'ValidatePattern' + Type = [System.Management.Automation.ValidatePatternAttribute] + } + @{ + Accelerator = 'ValidateRange' + Type = [System.Management.Automation.ValidateRangeAttribute] + } + @{ + Accelerator = 'ValidateScript' + Type = [System.Management.Automation.ValidateScriptAttribute] + } + @{ + Accelerator = 'ValidateSet' + Type = [System.Management.Automation.ValidateSetAttribute] + } + @{ + Accelerator = 'ValidateUserDrive' + Type = [System.Management.Automation.ValidateUserDriveAttribute] + } + @{ + Accelerator = 'version' + Type = [System.Version] + } + @{ + Accelerator = 'void' + Type = [System.Void] + } + @{ + Accelerator = 'ipaddress' + Type = [System.Net.IPAddress] + } + @{ + Accelerator = 'DscLocalConfigurationManager' + Type = [System.Management.Automation.DscLocalConfigurationManagerAttribute] + } + @{ + Accelerator = 'WildcardPattern' + Type = [System.Management.Automation.WildcardPattern] + } + @{ + Accelerator = 'X509Certificate' + Type = [System.Security.Cryptography.X509Certificates.X509Certificate] + } + @{ + Accelerator = 'X500DistinguishedName' + Type = [System.Security.Cryptography.X509Certificates.X500DistinguishedName] + } + @{ + Accelerator = 'xml' + Type = [System.Xml.XmlDocument] + } + @{ + Accelerator = 'CimSession' + Type = [Microsoft.Management.Infrastructure.CimSession] + } + @{ + Accelerator = 'mailaddress' + Type = [System.Net.Mail.MailAddress] + } + @{ + Accelerator = 'semver' + Type = [System.Management.Automation.SemanticVersion] + } + @{ + Accelerator = 'scriptblock' + Type = [System.Management.Automation.ScriptBlock] + } + @{ + Accelerator = 'psvariable' + Type = [System.Management.Automation.PSVariable] + } + @{ + Accelerator = 'type' + Type = [System.Type] + } + @{ + Accelerator = 'psmoduleinfo' + Type = [System.Management.Automation.PSModuleInfo] + } + @{ + Accelerator = 'powershell' + Type = [System.Management.Automation.Powershell] + } + @{ + Accelerator = 'runspacefactory' + Type = [System.Management.Automation.Runspaces.RunspaceFactory] + } + @{ + Accelerator = 'runspace' + Type = [System.Management.Automation.Runspaces.Runspace] + } + @{ + Accelerator = 'initialsessionstate' + Type = [System.Management.Automation.Runspaces.InitialSessionState] + } + @{ + Accelerator = 'psscriptmethod' + Type = [System.Management.Automation.PSScriptMethod] + } + @{ + Accelerator = 'psscriptproperty' + Type = [System.Management.Automation.PSScriptProperty] + } + @{ + Accelerator = 'psnoteproperty' + Type = [System.Management.Automation.PSNoteProperty] + } + @{ + Accelerator = 'psaliasproperty' + Type = [System.Management.Automation.PSAliasProperty] + } + @{ + Accelerator = 'psvariableproperty' + Type = [System.Management.Automation.PSVariableProperty] + } + ) + + if (!$IsCoreCLR) + { + $nonCoreTypeAcceleratorTestCases = @( + @{ + Accelerator = 'adsi' + Type = [System.DirectoryServices.DirectoryEntry] + } + @{ + Accelerator = 'adsisearcher' + Type = [System.DirectoryServices.DirectorySearcher] + } + @{ + Accelerator = 'wmiclass' + Type = [System.Management.ManagementClass] + } + @{ + Accelerator = 'wmi' + Type = [System.Management.ManagementObject] + } + @{ + Accelerator = 'wmisearcher' + Type = [System.Management.ManagementObjectSearcher] + } + ) + } + } It "Basic type accelerator usage" { [msft_2174855] | Should Be ([int]) } It "Can query type accelerators" { - if ( $IsCoreCLR ) { $count = 80 } else { $count = 82 } + if ( $IsCoreCLR ) + { + $count = 80 + } else + { + $count = 82 + } $TypeAccelerators.Count -gt $count | Should Be $true $TypeAccelerators['xml'] | Should Be ([System.Xml.XmlDocument]) $TypeAccelerators['AllowNull'] | Should Be ([System.Management.Automation.AllowNullAttribute]) @@ -22,4 +416,14 @@ Describe "Type accelerators" -Tags "CI" { $TypeAcceleratorsType::Remove('msft_2174855_rm') $TypeAcceleratorsType::Get['msft_2174855_rm'] | Should Be $null } + + It 'Should have a type acclerator for: ' -TestCases $TypeAcceleratorTestCases { + param($Accelerator, $Type) + $TypeAcceleratorsType::Get[$Accelerator] | Should be ($Type) + } + + It 'Should have a type acclerator for non core type: ' -Skip:$IsCoreCLR -TestCases $nonCoreTypeAcceleratorTestCases { + param($Accelerator, $Type) + $TypeAcceleratorsType::Get[$Accelerator] | Should be ($Type) + } } From a457b39d6bace29d2648c2378bbc011e36917900 Mon Sep 17 00:00:00 2001 From: dchristian3188 Date: Wed, 12 Jul 2017 08:15:27 -0700 Subject: [PATCH 2/5] Moved variables to before all --- .../Language/Parser/TypeAccelerator.Tests.ps1 | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/test/powershell/Language/Parser/TypeAccelerator.Tests.ps1 b/test/powershell/Language/Parser/TypeAccelerator.Tests.ps1 index 398d7caf752..4117f6a40ee 100644 --- a/test/powershell/Language/Parser/TypeAccelerator.Tests.ps1 +++ b/test/powershell/Language/Parser/TypeAccelerator.Tests.ps1 @@ -366,9 +366,15 @@ Describe "Type accelerators" -Tags "CI" { Type = [System.Management.Automation.PSVariableProperty] } ) - - if (!$IsCoreCLR) + + if ( $IsCoreCLR ) { + $totalAccelerators = 80 + } + else + { + $totalAccelerators = 82 + $nonCoreTypeAcceleratorTestCases = @( @{ Accelerator = 'adsi' @@ -399,14 +405,7 @@ Describe "Type accelerators" -Tags "CI" { } It "Can query type accelerators" { - if ( $IsCoreCLR ) - { - $count = 80 - } else - { - $count = 82 - } - $TypeAccelerators.Count -gt $count | Should Be $true + $TypeAccelerators.Count -gt $totalAccelerators | Should Be $true $TypeAccelerators['xml'] | Should Be ([System.Xml.XmlDocument]) $TypeAccelerators['AllowNull'] | Should Be ([System.Management.Automation.AllowNullAttribute]) } From b406cacfa6baadfe6b2c4be9a1b5a55a04f10eb9 Mon Sep 17 00:00:00 2001 From: dchristian3188 Date: Wed, 12 Jul 2017 08:19:53 -0700 Subject: [PATCH 3/5] Cleaned up user type accelerator names --- .../Language/Parser/TypeAccelerator.Tests.ps1 | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/powershell/Language/Parser/TypeAccelerator.Tests.ps1 b/test/powershell/Language/Parser/TypeAccelerator.Tests.ps1 index 4117f6a40ee..caf1ca10769 100644 --- a/test/powershell/Language/Parser/TypeAccelerator.Tests.ps1 +++ b/test/powershell/Language/Parser/TypeAccelerator.Tests.ps1 @@ -5,8 +5,8 @@ Describe "Type accelerators" -Tags "CI" { $TypeAcceleratorsType = [psobject].Assembly.GetType("System.Management.Automation.TypeAccelerators") $TypeAccelerators = $TypeAcceleratorsType::Get - $TypeAcceleratorsType::Add('msft_2174855', [int]) - $TypeAcceleratorsType::Add('msft_2174855_rm', [int]) + $TypeAcceleratorsType::Add('userDefinedAcceleratorType', [int]) + $TypeAcceleratorsType::Add('userDefinedAcceleratorTypeToRemove', [int]) $TypeAcceleratorTestCases = @( @{ @@ -401,7 +401,7 @@ Describe "Type accelerators" -Tags "CI" { } It "Basic type accelerator usage" { - [msft_2174855] | Should Be ([int]) + [userDefinedAcceleratorType] | Should Be ([int]) } It "Can query type accelerators" { @@ -411,9 +411,9 @@ Describe "Type accelerators" -Tags "CI" { } It "Can remove type accelerator" { - $TypeAcceleratorsType::Get['msft_2174855_rm'] | Should Be ([int]) - $TypeAcceleratorsType::Remove('msft_2174855_rm') - $TypeAcceleratorsType::Get['msft_2174855_rm'] | Should Be $null + $TypeAcceleratorsType::Get['userDefinedAcceleratorTypeToRemove'] | Should Be ([int]) + $TypeAcceleratorsType::Remove('userDefinedAcceleratorTypeToRemove') + $TypeAcceleratorsType::Get['userDefinedAcceleratorTypeToRemove'] | Should Be $null } It 'Should have a type acclerator for: ' -TestCases $TypeAcceleratorTestCases { From f406a1c2577bdce03bbb84452800579a2dc7ec73 Mon Sep 17 00:00:00 2001 From: dchristian3188 Date: Wed, 12 Jul 2017 19:55:46 -0700 Subject: [PATCH 4/5] Updated Tests --- .../Language/Parser/TypeAccelerator.Tests.ps1 | 815 +++++++++--------- 1 file changed, 412 insertions(+), 403 deletions(-) diff --git a/test/powershell/Language/Parser/TypeAccelerator.Tests.ps1 b/test/powershell/Language/Parser/TypeAccelerator.Tests.ps1 index caf1ca10769..9b215b6166f 100644 --- a/test/powershell/Language/Parser/TypeAccelerator.Tests.ps1 +++ b/test/powershell/Language/Parser/TypeAccelerator.Tests.ps1 @@ -1,428 +1,437 @@ Describe "Type accelerators" -Tags "CI" { BeforeAll { - $TypeAcceleratorsType = [psobject].Assembly.GetType("System.Management.Automation.TypeAccelerators") - $TypeAccelerators = $TypeAcceleratorsType::Get - $TypeAcceleratorsType::Add('userDefinedAcceleratorType', [int]) - $TypeAcceleratorsType::Add('userDefinedAcceleratorTypeToRemove', [int]) - - $TypeAcceleratorTestCases = @( - @{ - Accelerator = 'Alias' - Type = [System.Management.Automation.AliasAttribute] - } - @{ - Accelerator = 'AllowEmptyCollection' - Type = [System.Management.Automation.AllowEmptyCollectionAttribute] - } - @{ - Accelerator = 'AllowEmptyString' - Type = [System.Management.Automation.AllowEmptyStringAttribute] - } - @{ - Accelerator = 'AllowNull' - Type = [System.Management.Automation.AllowNullAttribute] - } - @{ - Accelerator = 'ArgumentCompleter' - Type = [System.Management.Automation.ArgumentCompleterAttribute] - } - @{ - Accelerator = 'array' - Type = [System.Array] - } - @{ - Accelerator = 'bool' - Type = [System.Boolean] - } - @{ - Accelerator = 'byte' - Type = [System.Byte] - } - @{ - Accelerator = 'char' - Type = [System.Char] - } - @{ - Accelerator = 'CmdletBinding' - Type = [System.Management.Automation.CmdletBindingAttribute] - } - @{ - Accelerator = 'datetime' - Type = [System.DateTime] - } - @{ - Accelerator = 'decimal' - Type = [System.Decimal] - } - @{ - Accelerator = 'double' - Type = [System.Double] - } - @{ - Accelerator = 'DscResource' - Type = [System.Management.Automation.DscResourceAttribute] - } - @{ - Accelerator = 'float' - Type = [System.Single] - } - @{ - Accelerator = 'single' - Type = [System.Single] - } - @{ - Accelerator = 'guid' - Type = [System.Guid] - } - @{ - Accelerator = 'hashtable' - Type = [System.Collections.Hashtable] - } - @{ - Accelerator = 'int' - Type = [System.Int32] - } - @{ - Accelerator = 'int32' - Type = [System.Int32] - } - @{ - Accelerator = 'int16' - Type = [System.Int16] - } - @{ - Accelerator = 'long' - Type = [System.Int64] - } - @{ - Accelerator = 'int64' - Type = [System.Int64] - } - @{ - Accelerator = 'ciminstance' - Type = [Microsoft.Management.Infrastructure.CimInstance] - } - @{ - Accelerator = 'cimclass' - Type = [Microsoft.Management.Infrastructure.CimClass] - } - @{ - Accelerator = 'cimtype' - Type = [Microsoft.Management.Infrastructure.CimType] - } - @{ - Accelerator = 'cimconverter' - Type = [Microsoft.Management.Infrastructure.CimConverter] - } - @{ - Accelerator = 'IPEndpoint' - Type = [System.Net.IPEndPoint] - } - @{ - Accelerator = 'NullString' - Type = [System.Management.Automation.Language.NullString] - } - @{ - Accelerator = 'OutputType' - Type = [System.Management.Automation.OutputTypeAttribute] - } - @{ - Accelerator = 'ObjectSecurity' - Type = [System.Security.AccessControl.ObjectSecurity] - } - @{ - Accelerator = 'Parameter' - Type = [System.Management.Automation.ParameterAttribute] - } - @{ - Accelerator = 'PhysicalAddress' - Type = [System.Net.NetworkInformation.PhysicalAddress] - } - @{ - Accelerator = 'pscredential' - Type = [System.Management.Automation.PSCredential] - } - @{ - Accelerator = 'PSDefaultValue' - Type = [System.Management.Automation.PSDefaultValueAttribute] - } - @{ - Accelerator = 'pslistmodifier' - Type = [System.Management.Automation.PSListModifier] - } - @{ - Accelerator = 'psobject' - Type = [System.Management.Automation.PSObject] - } - @{ - Accelerator = 'pscustomobject' - Type = [System.Management.Automation.PSObject] - } - @{ - Accelerator = 'psprimitivedictionary' - Type = [System.Management.Automation.PSPrimitiveDictionary] - } - @{ - Accelerator = 'ref' - Type = [System.Management.Automation.PSReference] - } - @{ - Accelerator = 'PSTypeNameAttribute' - Type = [System.Management.Automation.PSTypeNameAttribute] - } - @{ - Accelerator = 'regex' - Type = [System.Text.RegularExpressions.Regex] - } - @{ - Accelerator = 'DscProperty' - Type = [System.Management.Automation.DscPropertyAttribute] - } - @{ - Accelerator = 'sbyte' - Type = [System.SByte] - } - @{ - Accelerator = 'string' - Type = [System.String] - } - @{ - Accelerator = 'SupportsWildcards' - Type = [System.Management.Automation.SupportsWildcardsAttribute] - } - @{ - Accelerator = 'switch' - Type = [System.Management.Automation.SwitchParameter] - } - @{ - Accelerator = 'cultureinfo' - Type = [System.Globalization.CultureInfo] - } - @{ - Accelerator = 'bigint' - Type = [System.Numerics.BigInteger] - } - @{ - Accelerator = 'securestring' - Type = [System.Security.SecureString] - } - @{ - Accelerator = 'timespan' - Type = [System.TimeSpan] - } - @{ - Accelerator = 'uint16' - Type = [System.UInt16] - } - @{ - Accelerator = 'uint32' - Type = [System.UInt32] - } - @{ - Accelerator = 'uint64' - Type = [System.UInt64] - } - @{ - Accelerator = 'uri' - Type = [System.Uri] - } - @{ - Accelerator = 'ValidateCount' - Type = [System.Management.Automation.ValidateCountAttribute] - } - @{ - Accelerator = 'ValidateDrive' - Type = [System.Management.Automation.ValidateDriveAttribute] - } - @{ - Accelerator = 'ValidateLength' - Type = [System.Management.Automation.ValidateLengthAttribute] - } - @{ - Accelerator = 'ValidateNotNull' - Type = [System.Management.Automation.ValidateNotNullAttribute] - } - @{ - Accelerator = 'ValidateNotNullOrEmpty' - Type = [System.Management.Automation.ValidateNotNullOrEmptyAttribute] - } - @{ - Accelerator = 'ValidatePattern' - Type = [System.Management.Automation.ValidatePatternAttribute] - } - @{ - Accelerator = 'ValidateRange' - Type = [System.Management.Automation.ValidateRangeAttribute] - } - @{ - Accelerator = 'ValidateScript' - Type = [System.Management.Automation.ValidateScriptAttribute] - } - @{ - Accelerator = 'ValidateSet' - Type = [System.Management.Automation.ValidateSetAttribute] - } - @{ - Accelerator = 'ValidateUserDrive' - Type = [System.Management.Automation.ValidateUserDriveAttribute] - } - @{ - Accelerator = 'version' - Type = [System.Version] - } - @{ - Accelerator = 'void' - Type = [System.Void] - } - @{ - Accelerator = 'ipaddress' - Type = [System.Net.IPAddress] - } - @{ - Accelerator = 'DscLocalConfigurationManager' - Type = [System.Management.Automation.DscLocalConfigurationManagerAttribute] - } - @{ - Accelerator = 'WildcardPattern' - Type = [System.Management.Automation.WildcardPattern] - } - @{ - Accelerator = 'X509Certificate' - Type = [System.Security.Cryptography.X509Certificates.X509Certificate] - } - @{ - Accelerator = 'X500DistinguishedName' - Type = [System.Security.Cryptography.X509Certificates.X500DistinguishedName] - } - @{ - Accelerator = 'xml' - Type = [System.Xml.XmlDocument] - } - @{ - Accelerator = 'CimSession' - Type = [Microsoft.Management.Infrastructure.CimSession] - } - @{ - Accelerator = 'mailaddress' - Type = [System.Net.Mail.MailAddress] - } - @{ - Accelerator = 'semver' - Type = [System.Management.Automation.SemanticVersion] - } - @{ - Accelerator = 'scriptblock' - Type = [System.Management.Automation.ScriptBlock] - } - @{ - Accelerator = 'psvariable' - Type = [System.Management.Automation.PSVariable] - } - @{ - Accelerator = 'type' - Type = [System.Type] - } - @{ - Accelerator = 'psmoduleinfo' - Type = [System.Management.Automation.PSModuleInfo] - } - @{ - Accelerator = 'powershell' - Type = [System.Management.Automation.Powershell] - } - @{ - Accelerator = 'runspacefactory' - Type = [System.Management.Automation.Runspaces.RunspaceFactory] - } - @{ - Accelerator = 'runspace' - Type = [System.Management.Automation.Runspaces.Runspace] - } - @{ - Accelerator = 'initialsessionstate' - Type = [System.Management.Automation.Runspaces.InitialSessionState] - } - @{ - Accelerator = 'psscriptmethod' - Type = [System.Management.Automation.PSScriptMethod] - } - @{ - Accelerator = 'psscriptproperty' - Type = [System.Management.Automation.PSScriptProperty] - } - @{ - Accelerator = 'psnoteproperty' - Type = [System.Management.Automation.PSNoteProperty] - } - @{ - Accelerator = 'psaliasproperty' - Type = [System.Management.Automation.PSAliasProperty] - } - @{ - Accelerator = 'psvariableproperty' - Type = [System.Management.Automation.PSVariableProperty] - } - ) - - if ( $IsCoreCLR ) - { - $totalAccelerators = 80 - } - else - { - $totalAccelerators = 82 + } + Context 'BuiltIn Accelerators' { + BeforeAll { - $nonCoreTypeAcceleratorTestCases = @( + $TypeAcceleratorTestCases = @( + @{ + Accelerator = 'Alias' + Type = [System.Management.Automation.AliasAttribute] + } + @{ + Accelerator = 'AllowEmptyCollection' + Type = [System.Management.Automation.AllowEmptyCollectionAttribute] + } + @{ + Accelerator = 'AllowEmptyString' + Type = [System.Management.Automation.AllowEmptyStringAttribute] + } + @{ + Accelerator = 'AllowNull' + Type = [System.Management.Automation.AllowNullAttribute] + } + @{ + Accelerator = 'ArgumentCompleter' + Type = [System.Management.Automation.ArgumentCompleterAttribute] + } + @{ + Accelerator = 'array' + Type = [System.Array] + } + @{ + Accelerator = 'bool' + Type = [System.Boolean] + } + @{ + Accelerator = 'byte' + Type = [System.Byte] + } + @{ + Accelerator = 'char' + Type = [System.Char] + } + @{ + Accelerator = 'CmdletBinding' + Type = [System.Management.Automation.CmdletBindingAttribute] + } + @{ + Accelerator = 'datetime' + Type = [System.DateTime] + } + @{ + Accelerator = 'decimal' + Type = [System.Decimal] + } + @{ + Accelerator = 'double' + Type = [System.Double] + } + @{ + Accelerator = 'DscResource' + Type = [System.Management.Automation.DscResourceAttribute] + } + @{ + Accelerator = 'float' + Type = [System.Single] + } + @{ + Accelerator = 'single' + Type = [System.Single] + } + @{ + Accelerator = 'guid' + Type = [System.Guid] + } + @{ + Accelerator = 'hashtable' + Type = [System.Collections.Hashtable] + } + @{ + Accelerator = 'int' + Type = [System.Int32] + } + @{ + Accelerator = 'int32' + Type = [System.Int32] + } + @{ + Accelerator = 'int16' + Type = [System.Int16] + } + @{ + Accelerator = 'long' + Type = [System.Int64] + } + @{ + Accelerator = 'int64' + Type = [System.Int64] + } @{ - Accelerator = 'adsi' - Type = [System.DirectoryServices.DirectoryEntry] + Accelerator = 'ciminstance' + Type = [Microsoft.Management.Infrastructure.CimInstance] } @{ - Accelerator = 'adsisearcher' - Type = [System.DirectoryServices.DirectorySearcher] + Accelerator = 'cimclass' + Type = [Microsoft.Management.Infrastructure.CimClass] } @{ - Accelerator = 'wmiclass' - Type = [System.Management.ManagementClass] + Accelerator = 'cimtype' + Type = [Microsoft.Management.Infrastructure.CimType] + } + @{ + Accelerator = 'cimconverter' + Type = [Microsoft.Management.Infrastructure.CimConverter] + } + @{ + Accelerator = 'IPEndpoint' + Type = [System.Net.IPEndPoint] + } + @{ + Accelerator = 'NullString' + Type = [System.Management.Automation.Language.NullString] + } + @{ + Accelerator = 'OutputType' + Type = [System.Management.Automation.OutputTypeAttribute] + } + @{ + Accelerator = 'ObjectSecurity' + Type = [System.Security.AccessControl.ObjectSecurity] } @{ - Accelerator = 'wmi' - Type = [System.Management.ManagementObject] + Accelerator = 'Parameter' + Type = [System.Management.Automation.ParameterAttribute] } @{ - Accelerator = 'wmisearcher' - Type = [System.Management.ManagementObjectSearcher] + Accelerator = 'PhysicalAddress' + Type = [System.Net.NetworkInformation.PhysicalAddress] + } + @{ + Accelerator = 'pscredential' + Type = [System.Management.Automation.PSCredential] + } + @{ + Accelerator = 'PSDefaultValue' + Type = [System.Management.Automation.PSDefaultValueAttribute] + } + @{ + Accelerator = 'pslistmodifier' + Type = [System.Management.Automation.PSListModifier] + } + @{ + Accelerator = 'psobject' + Type = [System.Management.Automation.PSObject] + } + @{ + Accelerator = 'pscustomobject' + Type = [System.Management.Automation.PSObject] + } + @{ + Accelerator = 'psprimitivedictionary' + Type = [System.Management.Automation.PSPrimitiveDictionary] + } + @{ + Accelerator = 'ref' + Type = [System.Management.Automation.PSReference] + } + @{ + Accelerator = 'PSTypeNameAttribute' + Type = [System.Management.Automation.PSTypeNameAttribute] + } + @{ + Accelerator = 'regex' + Type = [System.Text.RegularExpressions.Regex] + } + @{ + Accelerator = 'DscProperty' + Type = [System.Management.Automation.DscPropertyAttribute] + } + @{ + Accelerator = 'sbyte' + Type = [System.SByte] + } + @{ + Accelerator = 'string' + Type = [System.String] + } + @{ + Accelerator = 'SupportsWildcards' + Type = [System.Management.Automation.SupportsWildcardsAttribute] + } + @{ + Accelerator = 'switch' + Type = [System.Management.Automation.SwitchParameter] + } + @{ + Accelerator = 'cultureinfo' + Type = [System.Globalization.CultureInfo] + } + @{ + Accelerator = 'bigint' + Type = [System.Numerics.BigInteger] + } + @{ + Accelerator = 'securestring' + Type = [System.Security.SecureString] + } + @{ + Accelerator = 'timespan' + Type = [System.TimeSpan] + } + @{ + Accelerator = 'uint16' + Type = [System.UInt16] + } + @{ + Accelerator = 'uint32' + Type = [System.UInt32] + } + @{ + Accelerator = 'uint64' + Type = [System.UInt64] + } + @{ + Accelerator = 'uri' + Type = [System.Uri] + } + @{ + Accelerator = 'ValidateCount' + Type = [System.Management.Automation.ValidateCountAttribute] + } + @{ + Accelerator = 'ValidateDrive' + Type = [System.Management.Automation.ValidateDriveAttribute] + } + @{ + Accelerator = 'ValidateLength' + Type = [System.Management.Automation.ValidateLengthAttribute] + } + @{ + Accelerator = 'ValidateNotNull' + Type = [System.Management.Automation.ValidateNotNullAttribute] + } + @{ + Accelerator = 'ValidateNotNullOrEmpty' + Type = [System.Management.Automation.ValidateNotNullOrEmptyAttribute] + } + @{ + Accelerator = 'ValidatePattern' + Type = [System.Management.Automation.ValidatePatternAttribute] + } + @{ + Accelerator = 'ValidateRange' + Type = [System.Management.Automation.ValidateRangeAttribute] + } + @{ + Accelerator = 'ValidateScript' + Type = [System.Management.Automation.ValidateScriptAttribute] + } + @{ + Accelerator = 'ValidateSet' + Type = [System.Management.Automation.ValidateSetAttribute] + } + @{ + Accelerator = 'ValidateUserDrive' + Type = [System.Management.Automation.ValidateUserDriveAttribute] + } + @{ + Accelerator = 'version' + Type = [System.Version] + } + @{ + Accelerator = 'void' + Type = [System.Void] + } + @{ + Accelerator = 'ipaddress' + Type = [System.Net.IPAddress] + } + @{ + Accelerator = 'DscLocalConfigurationManager' + Type = [System.Management.Automation.DscLocalConfigurationManagerAttribute] + } + @{ + Accelerator = 'WildcardPattern' + Type = [System.Management.Automation.WildcardPattern] + } + @{ + Accelerator = 'X509Certificate' + Type = [System.Security.Cryptography.X509Certificates.X509Certificate] + } + @{ + Accelerator = 'X500DistinguishedName' + Type = [System.Security.Cryptography.X509Certificates.X500DistinguishedName] + } + @{ + Accelerator = 'xml' + Type = [System.Xml.XmlDocument] + } + @{ + Accelerator = 'CimSession' + Type = [Microsoft.Management.Infrastructure.CimSession] + } + @{ + Accelerator = 'mailaddress' + Type = [System.Net.Mail.MailAddress] + } + @{ + Accelerator = 'semver' + Type = [System.Management.Automation.SemanticVersion] + } + @{ + Accelerator = 'scriptblock' + Type = [System.Management.Automation.ScriptBlock] + } + @{ + Accelerator = 'psvariable' + Type = [System.Management.Automation.PSVariable] + } + @{ + Accelerator = 'type' + Type = [System.Type] + } + @{ + Accelerator = 'psmoduleinfo' + Type = [System.Management.Automation.PSModuleInfo] + } + @{ + Accelerator = 'powershell' + Type = [System.Management.Automation.Powershell] + } + @{ + Accelerator = 'runspacefactory' + Type = [System.Management.Automation.Runspaces.RunspaceFactory] + } + @{ + Accelerator = 'runspace' + Type = [System.Management.Automation.Runspaces.Runspace] + } + @{ + Accelerator = 'initialsessionstate' + Type = [System.Management.Automation.Runspaces.InitialSessionState] + } + @{ + Accelerator = 'psscriptmethod' + Type = [System.Management.Automation.PSScriptMethod] + } + @{ + Accelerator = 'psscriptproperty' + Type = [System.Management.Automation.PSScriptProperty] + } + @{ + Accelerator = 'psnoteproperty' + Type = [System.Management.Automation.PSNoteProperty] + } + @{ + Accelerator = 'psaliasproperty' + Type = [System.Management.Automation.PSAliasProperty] + } + @{ + Accelerator = 'psvariableproperty' + Type = [System.Management.Automation.PSVariableProperty] } ) + + if ( $IsCoreCLR ) + { + $totalAccelerators = 89 + } else + { + $totalAccelerators = 94 + + $nonCoreTypeAcceleratorTestCases = @( + @{ + Accelerator = 'adsi' + Type = [System.DirectoryServices.DirectoryEntry] + } + @{ + Accelerator = 'adsisearcher' + Type = [System.DirectoryServices.DirectorySearcher] + } + @{ + Accelerator = 'wmiclass' + Type = [System.Management.ManagementClass] + } + @{ + Accelerator = 'wmi' + Type = [System.Management.ManagementObject] + } + @{ + Accelerator = 'wmisearcher' + Type = [System.Management.ManagementObjectSearcher] + } + ) + } } - } - It "Basic type accelerator usage" { - [userDefinedAcceleratorType] | Should Be ([int]) - } + It 'Should have all the type accelerators' { + $TypeAccelerators.Count | Should be $totalAccelerators + } - It "Can query type accelerators" { - $TypeAccelerators.Count -gt $totalAccelerators | Should Be $true - $TypeAccelerators['xml'] | Should Be ([System.Xml.XmlDocument]) - $TypeAccelerators['AllowNull'] | Should Be ([System.Management.Automation.AllowNullAttribute]) + It 'Should have a type accelerator for: ' -TestCases $TypeAcceleratorTestCases { + param($Accelerator, $Type) + $TypeAcceleratorsType::Get[$Accelerator] | Should be ($Type) + } + + It 'Should have a type accelerator for non core type: ' -Skip:$IsCoreCLR -TestCases $nonCoreTypeAcceleratorTestCases { + param($Accelerator, $Type) + $TypeAcceleratorsType::Get[$Accelerator] | Should be ($Type) + } } + + Context 'User Defined Accelerators' { + BeforeAll { + $TypeAcceleratorsType::Add('userDefinedAcceleratorType', [int]) + $TypeAcceleratorsType::Add('userDefinedAcceleratorTypeToRemove', [int]) + } - It "Can remove type accelerator" { - $TypeAcceleratorsType::Get['userDefinedAcceleratorTypeToRemove'] | Should Be ([int]) - $TypeAcceleratorsType::Remove('userDefinedAcceleratorTypeToRemove') - $TypeAcceleratorsType::Get['userDefinedAcceleratorTypeToRemove'] | Should Be $null - } + AfterAll { + $TypeAcceleratorsType::Remove('userDefinedAcceleratorType') + $TypeAcceleratorsType::Remove('userDefinedAcceleratorTypeToRemove') + } - It 'Should have a type acclerator for: ' -TestCases $TypeAcceleratorTestCases { - param($Accelerator, $Type) - $TypeAcceleratorsType::Get[$Accelerator] | Should be ($Type) - } - - It 'Should have a type acclerator for non core type: ' -Skip:$IsCoreCLR -TestCases $nonCoreTypeAcceleratorTestCases { - param($Accelerator, $Type) - $TypeAcceleratorsType::Get[$Accelerator] | Should be ($Type) + It "Basic type accelerator usage" { + [userDefinedAcceleratorType] | Should Be ([int]) + } + + It "Can remove type accelerator" { + $TypeAcceleratorsType::Get['userDefinedAcceleratorTypeToRemove'] | Should Be ([int]) + $TypeAcceleratorsType::Remove('userDefinedAcceleratorTypeToRemove') + $TypeAcceleratorsType::Get['userDefinedAcceleratorTypeToRemove'] | Should Be $null + } } } From 307a843212b0d468a02499e121962eda14730c08 Mon Sep 17 00:00:00 2001 From: Dongbo Wang Date: Fri, 14 Jul 2017 08:36:13 -0700 Subject: [PATCH 5/5] Change '$nonCoreTypeAcceleratorTestCases' to '$extraFullPSAcceleratorTestCases' --- test/powershell/Language/Parser/TypeAccelerator.Tests.ps1 | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/test/powershell/Language/Parser/TypeAccelerator.Tests.ps1 b/test/powershell/Language/Parser/TypeAccelerator.Tests.ps1 index 9b215b6166f..479e7b4cec9 100644 --- a/test/powershell/Language/Parser/TypeAccelerator.Tests.ps1 +++ b/test/powershell/Language/Parser/TypeAccelerator.Tests.ps1 @@ -369,11 +369,12 @@ Describe "Type accelerators" -Tags "CI" { if ( $IsCoreCLR ) { $totalAccelerators = 89 - } else + } + else { $totalAccelerators = 94 - $nonCoreTypeAcceleratorTestCases = @( + $extraFullPSAcceleratorTestCases = @( @{ Accelerator = 'adsi' Type = [System.DirectoryServices.DirectoryEntry] @@ -407,7 +408,7 @@ Describe "Type accelerators" -Tags "CI" { $TypeAcceleratorsType::Get[$Accelerator] | Should be ($Type) } - It 'Should have a type accelerator for non core type: ' -Skip:$IsCoreCLR -TestCases $nonCoreTypeAcceleratorTestCases { + It 'Should have a type accelerator for non-dotnet-core type: ' -Skip:$IsCoreCLR -TestCases $extraFullPSAcceleratorTestCases { param($Accelerator, $Type) $TypeAcceleratorsType::Get[$Accelerator] | Should be ($Type) }