-
Notifications
You must be signed in to change notification settings - Fork 3
/
cover.ps1
81 lines (72 loc) · 1.96 KB
/
cover.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
#!/usr/bin/pwsh
Param(
[switch]
[Parameter(
Mandatory = $false,
HelpMessage = "Enable generation of a cobertura report")]
$cobertura
)
$ErrorActionPreference="Stop"
Set-StrictMode -Version Latest
function script:exec {
[CmdletBinding()]
param(
[Parameter(Position=0,Mandatory=1)][scriptblock]$cmd,
[Parameter(Position=1,Mandatory=0)][string]$errorMessage = ("Error executing command: {0}" -f $cmd)
)
# write-host $cmd
& $cmd
if ($lastexitcode -ne 0)
{
throw $errorMessage
}
}
function dotnetTest([string[]] $asmAndIgnores)
{
$filter = '\"[*TestAdapter*]*\"'
for ($i = 1; $i -lt $asmAndIgnores.Length; ++$i)
{
$filter += ",[" + $asmAndIgnores[$i] + "]*";
}
$filter += '\"';
$asm = $asmAndIgnores[0];
exec { dotnet test `
--configuration Release `
/p:CollectCoverage=true `
/p:Exclude=$filter `
/p:CoverletOutputFormat=cobertura `
/p:CoverletOutput="../coverage/${asm}.coverage.xml" `
/p:CopyLocalLockFileAssemblies=true `
/p:Threshold=0 `
/p:ThresholdType=line `
"${asm}/${asm}.csproj" }
}
# Install ReportGenerator
if (!(Test-Path "tools/reportgenerator") -and !(Test-Path "tools/reportgenerator.exe"))
{
#Using alternate nuget.config due to https://github.com/dotnet/cli/issues/9586
exec { dotnet tool install --configfile nuget.tool.config --tool-path tools dotnet-reportgenerator-globaltool }
}
Write-Host "Running dotnet test"
$asms = @( `
, @("BlushingPenguin.JsonPath.Test")
)
foreach ($asm in $asms) {
dotnetTest $asm
}
Write-Host "Running ReportGenerator"
$reportTypes="-reporttypes:Html"
if ($cobertura)
{
$reportTypes += ";Cobertura"
}
$reports = ""
foreach ($asm in $asms) {
if ($reports) {
$reports += ";"
}
$reports += "coverage/" + $asm[0] + ".coverage.xml"
}
$reports = "-reports:" + $reports
write-host $reports
exec { tools/reportgenerator $reports "-targetdir:coverage" $reportTypes }