|
1 |
| -Describe "PowerShell Standard 5" { |
| 1 | +Describe 'PowerShell Standard 5' { |
| 2 | + |
2 | 3 | BeforeAll {
|
3 |
| - $cmdletAssembly = "bin/Debug/netstandard2.0/Demo.Cmdlet.dll" |
4 |
| - $assemblyPath = Join-Path "$PSScriptRoot" $cmdletAssembly |
5 |
| - $PSBin = (Get-Process -id $PID).MainModule.FileName |
| 4 | + $repoRoot = git rev-parse --show-toplevel |
| 5 | + $libraryPath = "${repoRoot}/src/5/bin/Release/netstandard2.0/System.Management.Automation.dll" |
| 6 | + $assemblyExists = test-path $libraryPath |
| 7 | + if ( $assemblyExists ) { |
| 8 | + $standardAssembly = [System.Reflection.Assembly]::LoadFile($libraryPath) |
| 9 | + } |
6 | 10 | }
|
7 |
| - It "Can build a reference assembly" { |
8 |
| - try { |
9 |
| - Push-Location $PSScriptRoot |
10 |
| - dotnet restore |
11 |
| - dotnet build |
12 |
| - $assemblyPath | Should Exist |
| 11 | + |
| 12 | + Context 'Creating a cmdlet' { |
| 13 | + BeforeAll { |
| 14 | + $cmdletAssembly = 'bin/Release/netstandard2.0/Demo.Cmdlet.dll' |
| 15 | + $assemblyPath = Join-Path "$PSScriptRoot" $cmdletAssembly |
| 16 | + $PSBin = (Get-Process -id $PID).MainModule.FileName |
| 17 | + } |
| 18 | + It 'Can build a reference assembly' { |
| 19 | + try { |
| 20 | + Push-Location $PSScriptRoot |
| 21 | + dotnet restore |
| 22 | + dotnet build --configuration Release |
| 23 | + $assemblyPath | Should -Exist |
| 24 | + } |
| 25 | + finally { |
| 26 | + Pop-Location |
| 27 | + } |
13 | 28 | }
|
14 |
| - finally { |
15 |
| - Pop-Location |
| 29 | + It 'Can execute the compiled cmdlet' { |
| 30 | + $result = & $PSBin -c "import-module $assemblyPath; Get-Thing" |
| 31 | + $result | Should -Be 'success!' |
16 | 32 | }
|
17 | 33 | }
|
18 |
| - It "Can execute the compiled cmdlet" { |
19 |
| - $result = & $PSBin -c "import-module $assemblyPath; Get-Thing" |
20 |
| - $result | Should Be "success!" |
| 34 | + |
| 35 | + Context 'Reflection tests' { |
| 36 | + |
| 37 | + $testCases = @{ |
| 38 | + Name = "Issue 52: ValidateArgumentsAttribute.Validate method is not abstract" |
| 39 | + ScriptBlock = { |
| 40 | + $t = $standardAssembly.GetType('System.Management.Automation.ValidateArgumentsAttribute') |
| 41 | + $m = $t.GetMember('Validate','Public,NonPublic,Instance,Static,DeclaredOnly') |
| 42 | + $m.IsAbstract |Should -Be $true |
| 43 | + } |
| 44 | + }, |
| 45 | + @{ |
| 46 | + Name = "Issue 50: PSEventUnsubscribedEventHander argument type should be PSEventUnsubscribedEventArgs" |
| 47 | + ScriptBlock = { |
| 48 | + $t = $standardAssembly.GetType('System.Management.Automation.PSEventUnsubscribedEventHandler') |
| 49 | + $m = $t.GetMethod('Invoke') |
| 50 | + $parameters = $m.GetParameters() |
| 51 | + $parameters[1].ParameterType.FullName | Should -Be 'System.Management.Automation.PSEventUnsubscribedEventArgs' |
| 52 | + } |
| 53 | + }, |
| 54 | + @{ |
| 55 | + Name = "Issue 44: FunctionMemberAst.Parameters should be accessible" |
| 56 | + ScriptBlock = { |
| 57 | + $t = $standardAssembly.GetType('System.Management.Automation.Language.FunctionMemberAst') |
| 58 | + $p = $t.GetProperty('Parameters') |
| 59 | + $p.GetMethod.IsPublic | Should -Be $true |
| 60 | + } |
| 61 | + }, |
| 62 | + @{ |
| 63 | + Name = "Issue 42: Runspace.Default should not contain public CreateNestedPipeline" |
| 64 | + ScriptBlock = { |
| 65 | + $t = $standardAssembly.GetType('System.Management.Automation.Runspaces.Runspace') |
| 66 | + $t.GetMembers('Public,NonPublic,Instance,Static')|?{$_.Name -match 'CreatedNestedPipeline'}|Should -BeNullOrEmpty |
| 67 | + } |
| 68 | + }, |
| 69 | + @{ |
| 70 | + Name = "Issue 36: PSMemberInfo.Copy is marked 'virtual' but should be 'abstract'" |
| 71 | + ScriptBlock = { |
| 72 | + $t = $standardAssembly.GetType('System.Management.Automation.PSMemberInfo') |
| 73 | + $m = $t.GetMethod('Copy') |
| 74 | + $m.IsAbstract | Should -Be $true |
| 75 | + } |
| 76 | + }, |
| 77 | + @{ |
| 78 | + Name = "Issue 26: Several properties missing from CmdletProvider (also issue 14)" |
| 79 | + ScriptBlock = { |
| 80 | + $t = $standardAssembly.GetType('System.Management.Automation.Provider.CmdletProvider') |
| 81 | + $t.GetProperty('CurrentPSTransaction') | Should -Not -BeNullOrEmpty |
| 82 | + $t.GetProperty('DynamicParameters',[Reflection.BindingFlags]'NonPublic,Instance') | Should -Not -BeNullOrEmpty |
| 83 | + $t.GetProperty('PSDriveInfo',[Reflection.BindingFlags]'NonPublic,Instance') | Should -Not -BeNullOrEmpty |
| 84 | + $t.GetProperty('ProviderInfo',[Reflection.BindingFlags]'NonPublic,Instance') | Should -Not -BeNullOrEmpty |
| 85 | + } |
| 86 | + }, |
| 87 | + @{ |
| 88 | + Name = "Issue 19: SetJobState missing from Job class" |
| 89 | + ScriptBlock = { |
| 90 | + $t = $standardAssembly.GetType('System.Management.Automation.Job') |
| 91 | + $t.GetMethod('SetJobState',[System.Reflection.BindingFlags]'NonPublic,Instance') | Should -Not -BeNullOrEmpty |
| 92 | + } |
| 93 | + }, |
| 94 | + @{ |
| 95 | + Name = "Issue 18: Debugger does not contain protected parameterless constructor" |
| 96 | + ScriptBlock = { |
| 97 | + $t = $standardAssembly.GetType('System.Management.Automation.Debugger') |
| 98 | + # no public constructors |
| 99 | + $t.GetConstructors().Count | Should -Be 0 |
| 100 | + # one protected, parameterless constructor |
| 101 | + $constructor = $t.GetConstructors('NonPublic,Instance') |
| 102 | + @($constructor).Count | Should -Be 1 |
| 103 | + $constructor.IsFamily | Should -Be $true |
| 104 | + $constructor.GetParameters().Count | Should -Be 0 |
| 105 | + } |
| 106 | + }, |
| 107 | + @{ |
| 108 | + Name = "Issue 17: ScriptExtent does not inherit IScriptExtent" |
| 109 | + ScriptBlock = { |
| 110 | + $t = $standardAssembly.GetType('System.Management.Automation.Language.ScriptExtent') |
| 111 | + $t.GetInterface('System.Management.Automation.Language.IScriptExtent')|Should -Not -BeNullOrEmpty |
| 112 | + } |
| 113 | + }, |
| 114 | + @{ |
| 115 | + Name = "Issue 16: ICustomAstVistor2 does not inherit ICustomAstVistor" |
| 116 | + ScriptBlock = { |
| 117 | + $t = $standardAssembly.GetType('System.Management.Automation.Language.ICustomAstVisitor2') |
| 118 | + $t.GetInterface('System.Management.Automation.Language.ICustomAstVisitor')|Should -Not -BeNullOrEmpty |
| 119 | + } |
| 120 | + }, |
| 121 | + @{ |
| 122 | + Name = "Issue 11: Missing cmdletization types" |
| 123 | + ScriptBlock = { |
| 124 | + $typeList = 'Microsoft.PowerShell.Cmdletization.BehaviorOnNoMatch', |
| 125 | + 'Microsoft.PowerShell.Cmdletization.CmdletAdapter`1', |
| 126 | + 'Microsoft.PowerShell.Cmdletization.MethodInvocationInfo', 'Microsoft.PowerShell.Cmdletization.MethodParameter', |
| 127 | + 'Microsoft.PowerShell.Cmdletization.MethodParameterBindings', |
| 128 | + 'Microsoft.PowerShell.Cmdletization.QueryBuilder', |
| 129 | + 'Microsoft.PowerShell.Cmdletization.Xml.ConfirmImpact', 'Microsoft.PowerShell.Cmdletization.Xml.ItemsChoiceType' |
| 130 | + foreach ( $t in $typeList ) { |
| 131 | + $standardAssembly.GetType($t) | Should -Not -BeNullOrEmpty |
| 132 | + } |
| 133 | + } |
| 134 | + }, |
| 135 | + @{ |
| 136 | + Name = "Issue 8: DefaultRunspace should be a static property" |
| 137 | + ScriptBlock = { |
| 138 | + $t = $standardAssembly.GetType('System.Management.Automation.Runspaces.Runspace') |
| 139 | + $p = $t.GetProperty('DefaultRunspace',[System.Reflection.BindingFlags]'Public,Static') |
| 140 | + $p | Should -Not -BeNullOrEmpty |
| 141 | + } |
| 142 | + }, |
| 143 | + @{ |
| 144 | + Name = "Issue 7: params keyword is left out for array type parameters" |
| 145 | + ScriptBlock = { |
| 146 | + $t = $standardAssembly.GetType('System.Management.Automation.OutputTypeAttribute') |
| 147 | + foreach ($c in $t.GetConstructors()) { |
| 148 | + $c.GetParameters()[-1].CustomAttributes.AttributeType.FullName | Should -Be System.ParamArrayAttribute |
| 149 | + } |
| 150 | + } |
| 151 | + }, |
| 152 | + @{ |
| 153 | + Name = "Issue 6: PSObject.Properties is using int instead of string" |
| 154 | + ScriptBlock = { |
| 155 | + $t = $standardAssembly.GetType('System.Management.Automation.PSObject') |
| 156 | + $p = $t.GetProperty('Properties') |
| 157 | + $p.PropertyType.GetMember('Item').GetIndexParameters().ParameterType.FullName | Should -Be 'System.String' |
| 158 | + } |
| 159 | + }, |
| 160 | + @{ |
| 161 | + Name = "Issue 4: CreatePipeline should not be available" |
| 162 | + ScriptBlock = { |
| 163 | + $t = $standardAssembly.GetType('System.Management.Automation.Runspaces.Runspace') |
| 164 | + $t.GetMembers('Public,NonPublic,Instance,Static')|?{$_.Name -match 'CreatePipeline'} | Should -BeNullOrEmpty |
| 165 | + } |
| 166 | + } |
| 167 | + |
| 168 | + It '<Name>' -testcases $testCases -skip:(! $assemblyExists) { |
| 169 | + param ( [string]$name, [scriptblock]$ScriptBlock ) |
| 170 | + & ${ScriptBlock} |
| 171 | + } |
| 172 | + } |
| 173 | + |
| 174 | + Context 'The type list is expected' { |
| 175 | + BeforeAll { |
| 176 | + $smaT = [psobject].assembly.GetTypes()|?{$_.IsPublic}|Sort-Object FullName |
| 177 | + $asmT = $standardAssembly.GetTypes()|?{$_.IsPublic}|Sort-Object FullName |
| 178 | + # These are the types which we expect to not be in the standard library |
| 179 | + $expectedMissingTypes = @{ Name = 'Microsoft.PowerShell.ProcessCodeMethods' }, |
| 180 | + @{ Name = 'Microsoft.PowerShell.DesiredStateConfiguration.ArgumentToConfigurationDataTransformationAttribute' }, |
| 181 | + @{ Name = 'Microsoft.PowerShell.DesiredStateConfiguration.Internal.DscRemoteOperationsClass' }, |
| 182 | + @{ Name = 'Microsoft.PowerShell.DesiredStateConfiguration.Internal.DscClassCache' }, |
| 183 | + @{ Name = 'Microsoft.PowerShell.Commands.GetExperimentalFeatureCommand' }, |
| 184 | + @{ Name = 'Microsoft.PowerShell.Commands.PSPropertyExpressionResult' }, |
| 185 | + @{ Name = 'Microsoft.PowerShell.Commands.PSPropertyExpression' }, |
| 186 | + @{ Name = 'Microsoft.PowerShell.Commands.UpdateHelpScope' }, |
| 187 | + @{ Name = 'Microsoft.PowerShell.CoreClr.Stubs.AuthenticationLevel' }, |
| 188 | + @{ Name = 'Microsoft.PowerShell.CoreClr.Stubs.ImpersonationLevel' }, |
| 189 | + @{ Name = 'System.Management.Automation.PowerShellAssemblyLoadContextInitializer' }, |
| 190 | + @{ Name = 'System.Management.Automation.Platform' }, |
| 191 | + @{ Name = 'System.Management.Automation.ValidateRangeKind' }, |
| 192 | + @{ Name = 'System.Management.Automation.CachedValidValuesGeneratorBase' }, |
| 193 | + @{ Name = 'System.Management.Automation.IValidateSetValuesGenerator' }, |
| 194 | + @{ Name = 'System.Management.Automation.ArgumentCompletionsAttribute' }, |
| 195 | + @{ Name = 'System.Management.Automation.GetSymmetricEncryptionKey' }, |
| 196 | + @{ Name = 'System.Management.Automation.StartRunspaceDebugProcessingEventArgs' }, |
| 197 | + @{ Name = 'System.Management.Automation.ProcessRunspaceDebugEndEventArgs' }, |
| 198 | + @{ Name = 'System.Management.Automation.ExperimentalFeature' }, |
| 199 | + @{ Name = 'System.Management.Automation.ExperimentAction' }, |
| 200 | + @{ Name = 'System.Management.Automation.ExperimentalAttribute' }, |
| 201 | + @{ Name = 'System.Management.Automation.PSSnapInSpecification' }, |
| 202 | + @{ Name = 'System.Management.Automation.PSParseError' }, |
| 203 | + @{ Name = 'System.Management.Automation.PSParser' }, |
| 204 | + @{ Name = 'System.Management.Automation.PSToken' }, |
| 205 | + @{ Name = 'System.Management.Automation.PSTokenType' }, |
| 206 | + @{ Name = 'System.Management.Automation.TypeInferenceRuntimePermissions' }, |
| 207 | + @{ Name = 'System.Management.Automation.PSVersionHashTable' }, |
| 208 | + @{ Name = 'System.Management.Automation.SemanticVersion' }, |
| 209 | + @{ Name = 'System.Management.Automation.LocationChangedEventArgs' }, |
| 210 | + @{ Name = 'System.Management.Automation.WorkflowInfo' }, |
| 211 | + @{ Name = 'System.Management.Automation.PSSnapInInfo' }, |
| 212 | + @{ Name = 'System.Management.Automation.VerbInfo' }, |
| 213 | + @{ Name = 'System.Management.Automation.Remoting.WSMan.WSManServerChannelEvents' }, |
| 214 | + @{ Name = 'System.Management.Automation.Remoting.WSMan.ActiveSessionsChangedEventArgs' }, |
| 215 | + @{ Name = 'System.Management.Automation.Runspaces.PipelineStateInfo' }, |
| 216 | + @{ Name = 'System.Management.Automation.Runspaces.PipelineStateEventArgs' }, |
| 217 | + @{ Name = 'System.Management.Automation.Runspaces.Pipeline' }, |
| 218 | + @{ Name = 'System.Management.Automation.Runspaces.PowerShellProcessInstance' }, |
| 219 | + @{ Name = 'System.Management.Automation.Runspaces.SSHConnectionInfo' }, |
| 220 | + @{ Name = 'System.Management.Automation.Runspaces.VMConnectionInfo' }, |
| 221 | + @{ Name = 'System.Management.Automation.Runspaces.PSSnapInException' }, |
| 222 | + @{ Name = 'System.Management.Automation.Runspaces.PipelineReader`1' }, |
| 223 | + @{ Name = 'System.Management.Automation.Runspaces.PipelineWriter' }, |
| 224 | + @{ Name = 'System.Management.Automation.Tracing.EtwActivity' }, |
| 225 | + @{ Name = 'System.Management.Automation.Tracing.PowerShellTraceTask' }, |
| 226 | + @{ Name = 'System.Management.Automation.Tracing.PowerShellTraceKeywords' }, |
| 227 | + @{ Name = 'System.Management.Automation.Tracing.Tracer' }, |
| 228 | + @{ Name = 'System.Management.Automation.Tracing.PowerShellTraceSource' }, |
| 229 | + @{ Name = 'System.Management.Automation.Tracing.PowerShellTraceSourceFactory' }, |
| 230 | + @{ Name = 'System.Management.Automation.Internal.TransactionParameters' } |
| 231 | + } |
| 232 | + |
| 233 | + It "There should be no types in standard which are not in the product" -skip:(! $assemblyExists) { |
| 234 | + Compare-Object -reference $smaT -difference $asmT | ?{$_.SideIndicator -eq '=>' } | Should -BeNullOrEmpty |
| 235 | + } |
| 236 | + |
| 237 | + It "<Name> should not be in the standard library" -skip:(! $assemblyExists) -testcase $expectedMissingTypes { |
| 238 | + param ( $Name ) |
| 239 | + $Name | Should -BeIn @($expectedMissingTypes.Values) |
| 240 | + } |
21 | 241 | }
|
22 | 242 | }
|
0 commit comments