Skip to content

Commit

Permalink
Move ConstrainedLanguageMode tests to separate task
Browse files Browse the repository at this point in the history
  • Loading branch information
andyleejordan committed Aug 22, 2023
1 parent 975ed6c commit f96e537
Showing 1 changed file with 25 additions and 23 deletions.
48 changes: 25 additions & 23 deletions PowerShellEditorServices.build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ Task Build FindDotNet, CreateBuildInfo, {
Invoke-BuildExec { & dotnet publish $script:dotnetBuildArgs .\src\PowerShellEditorServices.VSCode\PowerShellEditorServices.VSCode.csproj -f $script:NetRuntime.Standard }
}

Task Test TestServer, TestE2E
Task Test TestServer, TestE2E, TestConstrainedLanguageMode

Task TestServer TestServerWinPS, TestServerPS72, TestServerPS73

Expand All @@ -202,23 +202,25 @@ Task TestServerPS73 -If ($PSVersionTable.PSEdition -eq "Core") Build, SetupHelpF

Task TestE2E Build, SetupHelpForTests, {
Set-Location .\test\PowerShellEditorServices.Test.E2E\

$env:PWSH_EXE_NAME = if ($IsCoreCLR) { "pwsh" } else { "powershell" }
Invoke-BuildExec { & dotnet $script:dotnetTestArgs $script:NetRuntime.PS73 }
}

if (!$script:IsNix) {
if (-not [Security.Principal.WindowsIdentity]::GetCurrent().Owner.IsWellKnown("BuiltInAdministratorsSid")) {
Write-Warning "Skipping Constrained Language Mode tests as they must be ran in an elevated process."
return
}
Task TestConstrainedLanguageMode -If (-not $script:IsNix) Build, SetupHelpForTests, {
Set-Location .\test\PowerShellEditorServices.Test.E2E\
$env:PWSH_EXE_NAME = if ($IsCoreCLR) { "pwsh" } else { "powershell" }

try {
Write-Host "Running end-to-end tests in Constrained Language Mode."
[System.Environment]::SetEnvironmentVariable("__PSLockdownPolicy", "0x80000007", [System.EnvironmentVariableTarget]::Machine);
Invoke-BuildExec { & dotnet $script:dotnetTestArgs $script:NetRuntime.PS73 }
} finally {
[System.Environment]::SetEnvironmentVariable("__PSLockdownPolicy", $null, [System.EnvironmentVariableTarget]::Machine);
}
if (-not [Security.Principal.WindowsIdentity]::GetCurrent().Owner.IsWellKnown("BuiltInAdministratorsSid")) {
Write-Warning "Skipping Constrained Language Mode tests as they must be ran in an elevated process."
return
}

try {
Write-Host "Running end-to-end tests in Constrained Language Mode."
[System.Environment]::SetEnvironmentVariable("__PSLockdownPolicy", "0x80000007", [System.EnvironmentVariableTarget]::Machine)
Invoke-BuildExec { & dotnet $script:dotnetTestArgs $script:NetRuntime.PS73 }
} finally {
[System.Environment]::SetEnvironmentVariable("__PSLockdownPolicy", $null, [System.EnvironmentVariableTarget]::Machine)
}
}

Expand Down Expand Up @@ -290,11 +292,11 @@ task RestorePsesModules -After Build {
(Get-Content -Raw $ModulesJsonPath | ConvertFrom-Json).PSObject.Properties | ForEach-Object {
$name = $_.Name
$body = @{
Name = $name
Version = $_.Value.Version
Name = $name
Version = $_.Value.Version
AllowPrerelease = $_.Value.AllowPrerelease
Repository = if ($_.Value.Repository) { $_.Value.Repository } else { $DefaultModuleRepository }
Path = $submodulePath
Repository = if ($_.Value.Repository) { $_.Value.Repository } else { $DefaultModuleRepository }
Path = $submodulePath
}

if (-not $name) {
Expand All @@ -321,11 +323,11 @@ task RestorePsesModules -After Build {
$moduleInstallDetails = $moduleInfos[$moduleName]

$splatParameters = @{
Name = $moduleName
RequiredVersion = $moduleInstallDetails.Version
AllowPrerelease = $moduleInstallDetails.AllowPrerelease
Repository = if ($moduleInstallDetails.Repository) { $moduleInstallDetails.Repository } else { $DefaultModuleRepository }
Path = $submodulePath
Name = $moduleName
RequiredVersion = $moduleInstallDetails.Version
AllowPrerelease = $moduleInstallDetails.AllowPrerelease
Repository = if ($moduleInstallDetails.Repository) { $moduleInstallDetails.Repository } else { $DefaultModuleRepository }
Path = $submodulePath
}

Write-Host "`tInstalling module: ${moduleName} with arguments $(ConvertTo-Json $splatParameters)"
Expand Down

0 comments on commit f96e537

Please sign in to comment.