-
Notifications
You must be signed in to change notification settings - Fork 8
/
cover.ps1
70 lines (63 loc) · 2.42 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
#!/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)
)
& $cmd
if ($lastexitcode -ne 0)
{
throw $errorMessage
}
}
# 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"
$filter = '\"[*TestAdapter*]*,[*]*.Startup*,[*]*.Program,[*.Test*]*,[nunit*]*\"'
$attributeFilter = '\"Obsolete,GeneratedCode,CompilerGeneratedAttribute\"'
exec { dotnet test `
--configuration Release `
--filter=TestCategory!=ApiTests `
/p:CollectCoverage=true `
/p:Exclude=$filter `
/p:ExcludeByAttribute=$attributeFilter `
/p:CoverletOutputFormat=cobertura `
/p:CoverletOutput='../coverage/MongoDB.ApplicationInsights.coverage.cobertura.xml' `
/p:Threshold=90 `
/p:ThresholdType=branch `
"MongoDB.ApplicationInsights.Test/MongoDB.ApplicationInsights.Test.csproj"}
$filter = '\"[*TestAdapter*]*,[*]*.Startup*,[*]*.Program,[*.Test*]*,[nunit*]*,[MongoDB.ApplicationInsights]*\"'
exec { dotnet test `
--configuration Release `
--filter=TestCategory!=ApiTests `
/p:CollectCoverage=true `
/p:ExcludeByAttribute=$attributeFilter `
/p:Exclude=$filter `
/p:CoverletOutputFormat=cobertura `
/p:CoverletOutput='../coverage/MongoDB.ApplicationInsights.DependencyInjection.coverage.cobertura.xml' `
/p:Threshold=90 `
/p:ThresholdType=branch `
"MongoDB.ApplicationInsights.DependencyInjection.Test/MongoDB.ApplicationInsights.DependencyInjection.Test.csproj"}
Write-Host "Running ReportGenerator"
$reportTypes="-reporttypes:Html"
if ($cobertura)
{
$reportTypes += ";Cobertura";
}
$coberturaFiles = "-reports:coverage/MongoDB.ApplicationInsights.coverage.cobertura.xml;" + `
"coverage/MongoDB.ApplicationInsights.DependencyInjection.coverage.cobertura.xml"
exec { tools/reportgenerator $coberturaFiles "-targetdir:coverage" $reportTypes }