-
Notifications
You must be signed in to change notification settings - Fork 5
/
test.ps1
102 lines (76 loc) · 2.92 KB
/
test.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
[CmdletBinding(DefaultParameterSetName='RegularBuild')]
param (
[ValidateSet("debug", "release")]
[string]$Configuration = 'debug',
[int]$BuildNumber,
[switch]$OnlyUnitTests,
[string]$SignedPackageDirectory = ''
)
# For TeamCity - If any issue occurs, this script fails the build. - By default, TeamCity returns an exit code of 0 for all powershell scripts, even if they fail
trap {
Write-Host "BUILD FAILED: $_" -ForegroundColor Red
Write-Host "ERROR DETAILS:" -ForegroundColor Red
Write-Host $_.Exception -ForegroundColor Red
Write-Host ("`r`n" * 3)
exit 1
}
$CLIRoot= Join-Path $PSScriptRoot 'cli'
$env:DOTNET_INSTALL_DIR=$CLIRoot
. "$PSScriptRoot\build\common.ps1"
if ([string]::IsNullOrEmpty($SignedPackageDirectory)) {
$env:SignedPackagePath = ""
}
else {
$signedPackages = (Join-Path $SignedPackageDirectory "*.nupkg" | Get-ChildItem -Recurse)
if ($signedPackages.Length -lt 1) {
throw "Could not find any packages at path $($SignedPackageDirectory)"
}
$env:SignedPackagePath = $signedPackages[0].FullName
}
Trace-Log "Set signed package path to: $($env:SignedPackagePath)"
Trace-Log "DotNet CLI directory: $($env:DOTNET_INSTALL_DIR)"
# Try to use the Azure DevOps temp directory, which is cleaned up by the agent and has a short path.
if ($env:AGENT_TEMPDIRECTORY) {
$env:TMP = $env:AGENT_TEMPDIRECTORY
$env:TEMP = $env:AGENT_TEMPDIRECTORY
}
Trace-Log "Using TMP directory: $($env:TMP)"
Trace-Log "Using TEMP directory: $($env:TEMP)"
Function Run-Tests {
[CmdletBinding()]
param()
Trace-Log 'Running tests'
$xUnitExe = (Join-Path $PSScriptRoot "packages\xunit.runner.console.2.2.0\tools\xunit.console.exe")
$UnitTestAssemblies = @("test\NuGet.Services.EndToEnd.Test\bin\$Configuration\NuGet.Services.EndToEnd.Test.dll")
$AllTestAssemblies = $UnitTestAssemblies + `
@("src\NuGet.Services.EndToEnd\bin\$Configuration\NuGet.Services.EndToEnd.dll")
if ($OnlyUnitTests) {
$AllTestAssemblies = $UnitTestAssemblies
}
$TestCount = 0
foreach ($TestAssembly in $AllTestAssemblies) {
& $xUnitExe (Join-Path $PSScriptRoot $TestAssembly) -xml "TestResults.$TestCount.xml" -Verbose
$TestCount++
}
}
Write-Host ("`r`n" * 3)
Trace-Log ('=' * 60)
$startTime = [DateTime]::UtcNow
if (-not $BuildNumber) {
$BuildNumber = Get-BuildNumber
}
Trace-Log "Build #$BuildNumber started at $startTime"
$TestErrors = @()
Invoke-BuildStep 'Running tests' { Run-Tests } `
-ev +TestErrors
Trace-Log ('-' * 60)
## Calculating Build time
$endTime = [DateTime]::UtcNow
Trace-Log "Build #$BuildNumber ended at $endTime"
Trace-Log "Time elapsed $(Format-ElapsedTime ($endTime - $startTime))"
Trace-Log ('=' * 60)
if ($TestErrors) {
$ErrorLines = $TestErrors | %{ ">>> $($_.Exception.Message)" }
Error-Log "Tests completed with $($TestErrors.Count) error(s):`r`n$($ErrorLines -join "`r`n")" -Fatal
}
Write-Host ("`r`n" * 3)