Skip to content

Move ConstrainedLanguageMode tests to separate task #2055

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 22, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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