forked from DotNetAnalyzers/StyleCopAnalyzers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathopencover-report.ps1
151 lines (130 loc) · 5.2 KB
/
opencover-report.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
param (
[switch]$Debug,
[switch]$NoBuild,
[switch]$NoReport,
[switch]$AppVeyor
)
If (-not $NoBuild) {
# Run a build to ensure everything is up-to-date
If ($Debug) {
.\build.ps1 -Debug -Incremental
} Else {
.\build.ps1 -Incremental
}
If (-not $?) {
$host.UI.WriteErrorLine('Build failed; coverage analysis aborted.')
Exit $LASTEXITCODE
}
}
If ($Debug) {
$Configuration = 'Debug'
} Else {
$Configuration = 'Release'
}
$packageConfig = [xml](Get-Content ..\.nuget\packages.config)
$opencover_version = $packageConfig.SelectSingleNode('/packages/package[@id="OpenCover"]').version
$reportgenerator_version = $packageConfig.SelectSingleNode('/packages/package[@id="ReportGenerator"]').version
$xunitrunner_version = $packageConfig.SelectSingleNode('/packages/package[@id="xunit.runner.console"]').version
$pdb2pdb_version = $packageConfig.SelectSingleNode('/packages/package[@id="Microsoft.DiaSymReader.Pdb2Pdb"]').version
$packages_folder = '..\packages'
$opencover_console = "$packages_folder\OpenCover.$opencover_version\tools\OpenCover.Console.exe"
$xunit_runner_console = "$packages_folder\xunit.runner.console.$xunitrunner_version\tools\xunit.console.x86.exe"
$report_generator = "$packages_folder\ReportGenerator.$reportgenerator_version\tools\ReportGenerator.exe"
$pdb2pdb = "$packages_folder\Microsoft.DiaSymReader.Pdb2Pdb.$pdb2pdb_version\tools\Pdb2Pdb.exe"
$report_folder = '.\OpenCover.Reports'
$symbols_folder = '.\OpenCover.Symbols'
$target_dll = "..\StyleCop.Analyzers\StyleCop.Analyzers.Test\bin\$Configuration\net452\StyleCop.Analyzers.Test.dll"
$target_dll_csharp7 = "..\StyleCop.Analyzers\StyleCop.Analyzers.Test.CSharp7\bin\$Configuration\net46\StyleCop.Analyzers.Test.CSharp7.dll"
If (Test-Path $symbols_folder) {
Remove-Item -Recurse -Force $symbols_folder
}
$symbols_folder_csharp6 = Join-Path $symbols_folder 'CSharp6'
$symbols_folder_csharp7 = Join-Path $symbols_folder 'CSharp7'
mkdir $symbols_folder | Out-Null
mkdir $symbols_folder_csharp6 | Out-Null
mkdir $symbols_folder_csharp7 | Out-Null
function Convert-Coverage-Pdb() {
param (
[string]$assembly,
[string]$outputDir
)
$sourceDir = [IO.Path]::GetDirectoryName($assembly)
$outputName = [IO.Path]::ChangeExtension([IO.Path]::GetFileName($assembly), 'pdb')
$sourcePdb = Join-Path $sourceDir $outputName
$output = Join-Path $outputDir $outputName
if (Test-Path $sourcePdb) {
&$pdb2pdb $assembly /out $output
# Workaround for https://github.com/OpenCover/opencover/issues/800
Remove-Item $sourcePdb
Copy-Item $assembly $outputDir
}
}
function Extract-Coverage-Pdb() {
param (
[string]$assembly,
[string]$outputDir
)
$sourceDir = [IO.Path]::GetDirectoryName($assembly)
$outputName = [IO.Path]::ChangeExtension([IO.Path]::GetFileName($assembly), 'pdb')
$intermediatePdb = Join-Path $sourceDir $outputName
$output = Join-Path $outputDir $outputName
if (-not (Test-Path $output)) {
&$pdb2pdb $assembly /out $intermediatePdb /extract
if (Test-Path $intermediatePdb) {
&$pdb2pdb $assembly /pdb $intermediatePdb /out $output
Remove-Item $intermediatePdb
# Workaround for https://github.com/OpenCover/opencover/issues/800
Copy-Item $assembly $outputDir
}
}
}
$target_dir = [IO.Path]::GetDirectoryName($target_dll)
Get-ChildItem $target_dir -Filter *.dll | Foreach-Object { Convert-Coverage-Pdb -assembly $_.FullName -outputDir $symbols_folder_csharp6 }
Get-ChildItem $target_dir -Filter *.dll | Foreach-Object { Extract-Coverage-Pdb -assembly $_.FullName -outputDir $symbols_folder_csharp6 }
$target_dir = [IO.Path]::GetDirectoryName($target_dll_csharp7)
Get-ChildItem $target_dir -Filter *.dll | Foreach-Object { Convert-Coverage-Pdb -assembly $_.FullName -outputDir $symbols_folder_csharp7 }
Get-ChildItem $target_dir -Filter *.dll | Foreach-Object { Extract-Coverage-Pdb -assembly $_.FullName -outputDir $symbols_folder_csharp7 }
If (Test-Path $report_folder) {
Remove-Item -Recurse -Force $report_folder
}
mkdir $report_folder | Out-Null
If ($AppVeyor) {
$AppVeyorArg = '-appveyor'
}
&$opencover_console `
-register:user `
-threshold:1 -oldStyle `
-returntargetcode `
-hideskipped:All `
-filter:"+[StyleCop*]*" `
-excludebyattribute:*.ExcludeFromCodeCoverage* `
-excludebyfile:*\*Designer.cs `
-searchdirs:"$symbols_folder_csharp6" `
-output:"$report_folder\OpenCover.StyleCopAnalyzers.xml" `
-target:"$xunit_runner_console" `
-targetargs:"$target_dll -noshadow $AppVeyorArg"
If ($AppVeyor -and -not $?) {
$host.UI.WriteErrorLine('Build failed; coverage analysis aborted.')
Exit $LASTEXITCODE
}
&$opencover_console `
-register:user `
-threshold:1 -oldStyle `
-returntargetcode `
-hideskipped:All `
-filter:"+[StyleCop*]*" `
-excludebyattribute:*.ExcludeFromCodeCoverage* `
-excludebyfile:*\*Designer.cs `
-searchdirs:"$symbols_folder_csharp7" `
-output:"$report_folder\OpenCover.StyleCopAnalyzers.xml" `
-mergebyhash -mergeoutput `
-target:"$xunit_runner_console" `
-targetargs:"$target_dll_csharp7 -noshadow $AppVeyorArg"
If ($AppVeyor -and -not $?) {
$host.UI.WriteErrorLine('Build failed; coverage analysis aborted.')
Exit $LASTEXITCODE
}
If (-not $NoReport) {
&$report_generator -targetdir:$report_folder -reports:$report_folder\OpenCover.*.xml
$host.UI.WriteLine("Open $report_folder\index.htm to see code coverage results.")
}