test.ps1 2.51 KB
Newer Older
1 2 3 4 5 6 7
Set-StrictMode -Version Latest

$ErrorActionPreference = "Stop"
$PSDefaultParameterValues['*:ErrorAction'] = 'Stop'

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

8 9
$SourceDir = Split-Path (Split-Path (Get-Variable MyInvocation).Value.MyCommand.Path)
$BuildDir = Get-Location
10
$global:Success = $true
11

12 13
if ($Env:SKIP_TESTS) { exit }

14 15 16 17 18 19 20 21
# Ask ctest what it would run if we were to invoke it directly.  This lets
# us manage the test configuration in a single place (tests/CMakeLists.txt)
# instead of running clar here as well.  But it allows us to wrap our test
# harness with a leak checker like valgrind.  Append the option to write
# JUnit-style XML files.
function run_test {
	$TestName = $args[0]

22 23 24 25 26 27 28
	$TestCommand = (ctest -N -V -R "^$TestName$") -join "`n"

	if (-Not ($TestCommand -match "(?ms).*\n^[0-9]*: Test command: ")) {
		echo "Could not find tests: $TestName"
		exit
	}

29 30 31 32
	$TestCommand = (ctest -N -V -R "^$TestName$") -join "`n" -replace "(?ms).*\n^[0-9]*: Test command: ","" -replace "\n.*",""
	$TestCommand += " -r${BuildDir}\results_${TestName}.xml"

	Invoke-Expression $TestCommand
33
	if ($LastExitCode -ne 0) { $global:Success = $false }
34 35
}

36 37 38 39
Write-Host "##############################################################################"
Write-Host "## Configuring test environment"
Write-Host "##############################################################################"

40 41 42 43 44 45
if (-not $Env:SKIP_PROXY_TESTS) {
	Write-Host ""
	Write-Host "Starting HTTP proxy..."
	Invoke-WebRequest -Method GET -Uri https://github.com/ethomson/poxyproxy/releases/download/v0.1.0/poxyproxy-0.1.0.jar -OutFile poxyproxy.jar
	javaw -jar poxyproxy.jar -d --port 8080 --credentials foo:bar
}
46 47 48 49 50 51

Write-Host ""
Write-Host "##############################################################################"
Write-Host "## Running (offline) tests"
Write-Host "##############################################################################"

52
run_test offline
53

54 55 56 57 58
if (-not $Env:SKIP_ONLINE_TESTS) {
	Write-Host ""
	Write-Host "##############################################################################"
	Write-Host "## Running (online) tests"
	Write-Host "##############################################################################"
59

60
	run_test online
61
}
62

63 64 65 66
if (-not $Env:SKIP_PROXY_TESTS) {
	Write-Host ""
	Write-Host "Running proxy tests"
	Write-Host ""
67

68
	$Env:GITTEST_REMOTE_PROXY_HOST="localhost:8080"
69 70
	$Env:GITTEST_REMOTE_PROXY_USER="foo"
	$Env:GITTEST_REMOTE_PROXY_PASS="bar"
71 72

	run_test proxy
73 74 75

	taskkill /F /IM javaw.exe
}
76

77
if (-Not $global:Success) { exit 1 }