-
Notifications
You must be signed in to change notification settings - Fork 401
/
runTests.ps1
109 lines (92 loc) · 3.51 KB
/
runTests.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
103
104
105
106
107
108
109
param(
[string]$buildType="Debug",
[string]$dotnetDir="c:\Program Files\dotnet",
[string]$root=$PSScriptRoot,
[string]$failBuildOnTest="YES",
[bool]$runningInCI=$false)
################################################# Functions ############################################################
function WriteSectionHeader($sectionName)
{
$startTime = Get-Date -DisplayHint Time
Write-Host ""
Write-Host "============================"
Write-Host $sectionName
Write-Host "Start Time: " $startTime
Write-Host ""
}
function WriteSectionFooter($sectionName)
{
$startTime = Get-Date -DisplayHint Time
Write-Host ""
Write-Host "End Time: " $startTime
Write-Host $sectionName
Write-Host "============================"
Write-Host ""
}
################################################# Functions ############################################################
WriteSectionHeader("runTests.ps1");
Write-Host "buildType: " $buildType;
Write-Host "dotnetDir: " $dotnetDir
Write-Host "root: " $root;
Write-Host "failBuildOnTest: " $failBuildOnTest;
Write-Host "slnFile: " $slnFile;
Write-Host "runningInCI: " $runningInCI;
$runSettingsPath = $PSScriptRoot + "\build\CodeCoverage.runsettings"
[xml]$buildConfiguration = Get-Content $PSScriptRoot\buildConfiguration.xml
$dotnetexe = "$dotnetDir\dotnet.exe";
$startTime = Get-Date
Write-Host "Start Time: " $startTime
Write-Host "PSScriptRoot: " $PSScriptRoot;
Write-Host "dotnetexe: " $dotnetexe;
$ErrorActionPreference = "Stop"
$tempToUse = $env:TEMP;
if ($runningInCI) {
# Temp dir used in ADO
$tempToUse = "C:\__w\_temp";
}
$testProjects = $buildConfiguration.SelectNodes("root/projects/test/project")
foreach ($testProject in $testProjects)
{
if ($testProject.test -eq "YES")
{
WriteSectionHeader("Test");
$name = $testProject.name;
Write-Host ">>> Set-Location $root\test\$name"
Push-Location
Set-Location $root\test\$name
Write-Host ">>> Start-Process -Wait -PassThru -NoNewWindow $dotnetexe 'test $name.csproj' --filter category!=nonwindowstests --no-build --no-restore -nodereuse:false -v n -c $buildType --collect ""Code Coverage"" --settings ""$runSettingsPath"" --logger trx --results-directory ""$tempToUse"""
$p = Start-Process -Wait -PassThru -NoNewWindow $dotnetexe "test $name.csproj --filter category!=nonwindowstests --no-build --no-restore -nodereuse:false -v n -c $buildType --collect ""Code Coverage"" --settings ""$runSettingsPath"" --logger trx --results-directory ""$tempToUse"""
if($p.ExitCode -ne 0)
{
if (!$testExitCode)
{
$failedTestProjects = "$name"
}
else
{
$failedTestProjects = "$failedTestProjects, $name"
}
}
$testExitCode = $p.ExitCode + $testExitCode
Pop-Location
WriteSectionFooter("End Test");
}
}
if($testExitCode -ne 0)
{
WriteSectionHeader("==== Test Failures ====");
Write-Host "Failed test projects: $failedTestProjects" -foregroundcolor "DarkRed"
WriteSectionFooter("==== End Test Failures ====");
if($failBuildOnTest -ne "NO")
{
throw "Exiting test run."
}
}
Write-Host "============================"
Write-Host ""
$time = Get-Date
Write-Host "Start Time: " ($startTime);
Write-Host "End Time: " ($time);
Write-Host "Time to runtests: " ($time - $startTime);
Write-Host ""
Write-Host "============================";