Skip to content

Commit

Permalink
Make dotnet test arguments configurable (#1545)
Browse files Browse the repository at this point in the history
  • Loading branch information
andyleejordan authored Aug 16, 2021
1 parent d63100c commit f6cf330
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions PowerShellEditorServices.build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,23 @@ param(

[string]$DefaultModuleRepository = "PSGallery",

[string]$TestFilter = ''
# See: https://docs.microsoft.com/en-us/dotnet/core/testing/selective-unit-tests
[string]$TestFilter = '',

# See: https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-test
# E.g. use @("--logger", "console;verbosity=detailed") for detailed console output instead
[string[]]$TestArgs = @("--logger", "trx")
)

#Requires -Modules @{ModuleName="InvokeBuild";ModuleVersion="3.2.1"}

$script:dotnetTestArgs = @(
"test"
$TestArgs
if ($TestFilter) { "--filter", $TestFilter }
"--framework"
)

$script:IsNix = $IsLinux -or $IsMacOS
$script:IsRosetta = $IsMacOS -and (sysctl -n sysctl.proc_translated) -eq 1 # Mac M1
$script:BuildInfoPath = [System.IO.Path]::Combine($PSScriptRoot, "src", "PowerShellEditorServices.Hosting", "BuildInfo.cs")
Expand Down Expand Up @@ -223,31 +235,26 @@ task Build BinClean,{
exec { & $script:dotnetExe publish -c $Configuration .\src\PowerShellEditorServices.VSCode\PowerShellEditorServices.VSCode.csproj -f $script:NetRuntime.Standard }
}

function DotNetTestFilter {
# Reference https://docs.microsoft.com/en-us/dotnet/core/testing/selective-unit-tests
if ($TestFilter) { @("--filter",$TestFilter) } else { "" }
}

task Test SetupHelpForTests,TestServer,TestE2E

task TestServer TestServerWinPS,TestServerPS7,TestServerPS72

task TestServerWinPS -If (-not $script:IsNix) {
Set-Location .\test\PowerShellEditorServices.Test\
exec { & $script:dotnetExe test --logger trx -f $script:NetRuntime.Desktop (DotNetTestFilter) }
exec { & $script:dotnetExe $script:dotnetTestArgs $script:NetRuntime.Desktop }
}

task TestServerPS7 -If (-not $script:IsRosetta) {
Set-Location .\test\PowerShellEditorServices.Test\
Invoke-WithCreateDefaultHook -NewModulePath $script:PSCoreModulePath {
exec { & $script:dotnetExe test --logger trx -f $script:NetRuntime.PS7 (DotNetTestFilter) }
exec { & $script:dotnetExe $script:dotnetTestArgs $script:NetRuntime.PS7 }
}
}

task TestServerPS72 {
Set-Location .\test\PowerShellEditorServices.Test\
Invoke-WithCreateDefaultHook -NewModulePath $script:PSCoreModulePath {
exec { & $script:dotnetExe test --logger trx -f $script:NetRuntime.PS72 (DotNetTestFilter) }
exec { & $script:dotnetExe $script:dotnetTestArgs $script:NetRuntime.PS72 }
}
}

Expand All @@ -256,13 +263,13 @@ task TestE2E {

$env:PWSH_EXE_NAME = if ($IsCoreCLR) { "pwsh" } else { "powershell" }
$NetRuntime = if ($IsRosetta) { $script:NetRuntime.PS72 } else { $script:NetRuntime.PS7 }
exec { & $script:dotnetExe test --logger trx -f $NetRuntime (DotNetTestFilter) }
exec { & $script:dotnetExe $script:dotnetTestArgs $NetRuntime }

# Run E2E tests in ConstrainedLanguage mode.
if (!$script:IsNix) {
try {
[System.Environment]::SetEnvironmentVariable("__PSLockdownPolicy", "0x80000007", [System.EnvironmentVariableTarget]::Machine);
exec { & $script:dotnetExe test --logger trx -f $script:NetRuntime.PS7 (DotNetTestFilter) }
exec { & $script:dotnetExe $script:dotnetTestArgs $script:NetRuntime.PS7 }
} finally {
[System.Environment]::SetEnvironmentVariable("__PSLockdownPolicy", $null, [System.EnvironmentVariableTarget]::Machine);
}
Expand Down

0 comments on commit f6cf330

Please sign in to comment.