Port GetProcessorArchitecture() (#11046)

This commit is contained in:
Ilya
2020-01-14 08:41:19 +05:00
committed by GitHub
parent ac069185d6
commit 0dfeeb5203
3 changed files with 68 additions and 77 deletions
@@ -117,4 +117,69 @@ Describe "New-ModuleManifest tests" -tags "CI" {
{ New-ModuleManifest -Path $manifestPath -ProjectUri $testUri -LicenseUri $testUri -IconUri $testUri } | Should -Throw -ErrorId "System.InvalidOperationException,Microsoft.PowerShell.Commands.NewModuleManifestCommand"
}
# We skip the test on Unix-s because there Roslyn compilation works in another way.
It "New-ModuleManifest works with assembly architecture: <moduleArch>" -Skip:(!$IsWindows) -TestCases @(
# All values from [System.Reflection.ProcessorArchitecture]
@{ moduleArch = "None" },
@{ moduleArch = "MSIL" },
@{ moduleArch = "X86" },
@{ moduleArch = "IA64" },
@{ moduleArch = "Amd64" },
@{ moduleArch = "Arm" }
) {
param($moduleArch)
$roslynArch = [System.Runtime.InteropServices.RuntimeInformation]::ProcessArchitecture
switch ($moduleArch)
{
"None" { Set-ItResult -Skipped -Because "the test assembly architecture can not be tested"; return }
"MSIL" { Set-ItResult -Skipped -Because "the test assembly architecture can not be tested"; return }
"IA64" { $roslynArch = 'Itanium' }
}
$arch = [int].Assembly.GetName().ProcessorArchitecture
# Skip tests if the module architecture does not match the platform architecture
# but X86 works on Amd64/X64 and Arm works on Arm64.
if ($moduleArch -ne $arch -and -not ($moduleArch -eq "X86" -and $arch -eq "Amd64") -and -not ($moduleArch -eq "Arm" -and $arch -eq "Arm64"))
{
Set-ItResult -Skipped -Because "the $moduleArch assembly architecture is not supported on the $arch platform"
return
}
$a=@"
using System;
using System.Management.Automation;
namespace Test.Manifest {
[Cmdlet(VerbsCommon.Get, "TP")]
public class TPCommand0 : PSCmdlet
{
protected override void EndProcessing()
{
WriteObject("$arch");
}
}
}
"@
try {
# We can not unload the module assembly and so we can not use Pester TestDrive without cleanup error reporting
$testFolder = Join-Path $([System.IO.Path]::GetTempPath()) $([System.IO.Path]::GetRandomFileName())
New-Item -Type Directory -Path $testFolder -Force > $null
$assemblyPath = Join-Path $testFolder "TP_$arch.dll"
$modulePath = Join-Path $testFolder "TP_$arch.psd1"
Add-Type -TypeDefinition $a -CompilerOptions "/platform:$roslynArch" -OutputAssembly $assemblyPath
New-ModuleManifest -Path $modulePath -NestedModules "TP_$arch.dll" -RequiredAssemblies "TP_$arch.dll" -ProcessorArchitecture $arch -CmdletsToExport "Get-TP"
Import-Module $modulePath
Get-TP -ErrorAction SilentlyContinue | Should -BeExactly "$arch"
} finally {
Remove-Module "TP_$arch" -Force
Remove-Item -LiteralPath $testFolder -Recurse -Force -ErrorAction SilentlyContinue > $null
}
}
}