-
Notifications
You must be signed in to change notification settings - Fork 22
/
dotnet-test-cloud.ps1
executable file
·83 lines (76 loc) · 2.77 KB
/
dotnet-test-cloud.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
#!/usr/bin/env pwsh
<#
.SYNOPSIS
Runs tests as they are run in cloud test runs.
.PARAMETER Configuration
The configuration within which to run tests
.PARAMETER Agent
The name of the agent. This is used in preparing test run titles.
.PARAMETER PublishResults
A switch to publish results to Azure Pipelines.
.PARAMETER x86
A switch to run the tests in an x86 process.
.PARAMETER dotnet32
The path to a 32-bit dotnet executable to use.
#>
[CmdletBinding()]
Param(
[string]$Configuration='Debug',
[string]$Agent='Local',
[switch]$PublishResults,
[switch]$x86,
[string]$dotnet32
)
$RepoRoot = (Resolve-Path "$PSScriptRoot/..").Path
$ArtifactStagingFolder = & "$PSScriptRoot/Get-ArtifactsStagingDirectory.ps1"
$dotnet = 'dotnet'
if ($x86) {
$x86RunTitleSuffix = ", x86"
if ($dotnet32) {
$dotnet = $dotnet32
} else {
$dotnet32Possibilities = "$PSScriptRoot\../obj/tools/x86/.dotnet/dotnet.exe", "$env:AGENT_TOOLSDIRECTORY/x86/dotnet/dotnet.exe", "${env:ProgramFiles(x86)}\dotnet\dotnet.exe"
$dotnet32Matches = $dotnet32Possibilities |? { Test-Path $_ }
if ($dotnet32Matches) {
$dotnet = Resolve-Path @($dotnet32Matches)[0]
Write-Host "Running tests using `"$dotnet`"" -ForegroundColor DarkGray
} else {
Write-Error "Unable to find 32-bit dotnet.exe"
return 1
}
}
}
& $dotnet test $RepoRoot `
--no-build `
-c $Configuration `
--filter "TestCategory!=FailsInCloudTest" `
--collect "Code Coverage;Format=cobertura" `
--settings "$PSScriptRoot/test.runsettings" `
--blame-hang-timeout 60s `
--blame-crash `
-bl:"$ArtifactStagingFolder/build_logs/test.binlog" `
--diag "$ArtifactStagingFolder/test_logs/diag.log;TraceLevel=info" `
--logger trx `
$unknownCounter = 0
Get-ChildItem -Recurse -Path $RepoRoot\test\*.trx |% {
Copy-Item $_ -Destination $ArtifactStagingFolder/test_logs/
if ($PublishResults) {
$x = [xml](Get-Content -LiteralPath $_)
$runTitle = $null
if ($x.TestRun.TestDefinitions -and $x.TestRun.TestDefinitions.GetElementsByTagName('UnitTest')) {
$storage = $x.TestRun.TestDefinitions.GetElementsByTagName('UnitTest')[0].storage -replace '\\','/'
if ($storage -match '/(?<tfm>net[^/]+)/(?:(?<rid>[^/]+)/)?(?<lib>[^/]+)\.dll$') {
if ($matches.rid) {
$runTitle = "$($matches.lib) ($($matches.tfm), $($matches.rid), $Agent)"
} else {
$runTitle = "$($matches.lib) ($($matches.tfm)$x86RunTitleSuffix, $Agent)"
}
}
}
if (!$runTitle) {
$unknownCounter += 1;
$runTitle = "unknown$unknownCounter ($Agent$x86RunTitleSuffix)";
}
Write-Host "##vso[results.publish type=VSTest;runTitle=$runTitle;publishRunAttachments=true;resultFiles=$_;failTaskOnFailedTests=true;testRunSystem=VSTS - PTR;]"
}
}