35 lines
1.2 KiB
PowerShell
35 lines
1.2 KiB
PowerShell
param(
|
|
[switch]$Race
|
|
)
|
|
|
|
$ErrorActionPreference = "Stop"
|
|
$Root = Resolve-Path (Join-Path $PSScriptRoot "..")
|
|
$env:GOPROXY = if ($env:YMHUT_GOPROXY) { $env:YMHUT_GOPROXY } elseif ($env:GOPROXY) { $env:GOPROXY } else { "https://goproxy.io,https://mirrors.aliyun.com/goproxy,direct" }
|
|
$previousCgo = $env:CGO_ENABLED
|
|
if ($Race) {
|
|
$compiler = (& go env CC).Trim()
|
|
if (-not (Get-Command $compiler -ErrorAction SilentlyContinue)) {
|
|
throw "-Race requires a working C compiler. Go is configured for '$compiler', but that executable is not available."
|
|
}
|
|
$env:CGO_ENABLED = "1"
|
|
}
|
|
|
|
Push-Location $Root
|
|
try {
|
|
& go mod download all
|
|
if ($LASTEXITCODE -ne 0) { throw "go mod download failed with exit code $LASTEXITCODE" }
|
|
& go mod verify
|
|
if ($LASTEXITCODE -ne 0) { throw "go mod verify failed with exit code $LASTEXITCODE" }
|
|
$arguments = @("test")
|
|
if ($Race) { $arguments += "-race" }
|
|
$arguments += "./..."
|
|
& go @arguments
|
|
if ($LASTEXITCODE -ne 0) { throw "go test failed with exit code $LASTEXITCODE" }
|
|
} finally {
|
|
Pop-Location
|
|
if ($Race) {
|
|
if ($null -eq $previousCgo) { Remove-Item Env:\CGO_ENABLED -ErrorAction SilentlyContinue }
|
|
else { $env:CGO_ENABLED = $previousCgo }
|
|
}
|
|
}
|