1
1
param (
2
- [switch ]$Debug
2
+ [switch ]$Debug ,
3
+ [switch ]$NoBuild ,
4
+ [switch ]$NoReport ,
5
+ [switch ]$AppVeyor
3
6
)
4
7
5
- # Run a build to ensure everything is up-to-date
6
- If ($Debug ) {
7
- .\build.ps1 - Debug - Incremental
8
- } Else {
9
- .\build.ps1 - Incremental
10
- }
8
+ If (-not $NoBuild ) {
9
+ # Run a build to ensure everything is up-to-date
10
+ If ($Debug ) {
11
+ .\build.ps1 - Debug - Incremental
12
+ } Else {
13
+ .\build.ps1 - Incremental
14
+ }
11
15
12
- If (-not $? ) {
13
- $host.UI.WriteErrorLine (' Build failed; coverage analysis aborted.' )
14
- Exit $LASTEXITCODE
16
+ If (-not $? ) {
17
+ $host.UI.WriteErrorLine (' Build failed; coverage analysis aborted.' )
18
+ Exit $LASTEXITCODE
19
+ }
15
20
}
16
21
17
22
If ($Debug ) {
@@ -24,31 +29,93 @@ $packageConfig = [xml](Get-Content ..\.nuget\packages.config)
24
29
$opencover_version = $packageConfig.SelectSingleNode (' /packages/package[@id="OpenCover"]' ).version
25
30
$reportgenerator_version = $packageConfig.SelectSingleNode (' /packages/package[@id="ReportGenerator"]' ).version
26
31
$xunitrunner_version = $packageConfig.SelectSingleNode (' /packages/package[@id="xunit.runner.console"]' ).version
32
+ $pdb2pdb_version = $packageConfig.SelectSingleNode (' /packages/package[@id="Microsoft.DiaSymReader.Pdb2Pdb"]' ).version
27
33
28
34
$packages_folder = ' ..\packages'
29
35
$opencover_console = " $packages_folder \OpenCover.$opencover_version \tools\OpenCover.Console.exe"
30
36
$xunit_runner_console = " $packages_folder \xunit.runner.console.$xunitrunner_version \tools\xunit.console.x86.exe"
31
37
$report_generator = " $packages_folder \ReportGenerator.$reportgenerator_version \tools\ReportGenerator.exe"
38
+ $pdb2pdb = " $packages_folder \Microsoft.DiaSymReader.Pdb2Pdb.$pdb2pdb_version \tools\Pdb2Pdb.exe"
32
39
$report_folder = ' .\OpenCover.Reports'
33
- $target_dll = " ..\PublicApiAnalyzer\PublicApiAnalyzer.Test\bin\$Configuration \PublicApiAnalyzer.Test.dll"
40
+ $symbols_folder = ' .\OpenCover.Symbols'
41
+ $target_dll = " ..\PublicApiAnalyzer\PublicApiAnalyzer.Test\bin\$Configuration \net452\PublicApiAnalyzer.Test.dll"
42
+
43
+ If (Test-Path $symbols_folder ) {
44
+ Remove-Item - Recurse - Force $symbols_folder
45
+ }
46
+
47
+ mkdir $symbols_folder | Out-Null
48
+
49
+ function Convert-Coverage-Pdb () {
50
+ param (
51
+ [string ]$assembly ,
52
+ [string ]$outputDir
53
+ )
54
+ $sourceDir = [IO.Path ]::GetDirectoryName($assembly )
55
+ $outputName = [IO.Path ]::ChangeExtension([IO.Path ]::GetFileName($assembly ), ' pdb' )
56
+ $sourcePdb = Join-Path $sourceDir $outputName
57
+ $output = Join-Path $outputDir $outputName
58
+ if (Test-Path $sourcePdb ) {
59
+ & $pdb2pdb $assembly / out $output
60
+
61
+ # Workaround for https://github.com/OpenCover/opencover/issues/800
62
+ Remove-Item $sourcePdb
63
+ Copy-Item $assembly $outputDir
64
+ }
65
+ }
66
+
67
+ function Extract-Coverage-Pdb () {
68
+ param (
69
+ [string ]$assembly ,
70
+ [string ]$outputDir
71
+ )
72
+ $sourceDir = [IO.Path ]::GetDirectoryName($assembly )
73
+ $outputName = [IO.Path ]::ChangeExtension([IO.Path ]::GetFileName($assembly ), ' pdb' )
74
+ $intermediatePdb = Join-Path $sourceDir $outputName
75
+ $output = Join-Path $outputDir $outputName
76
+ if (-not (Test-Path $output )) {
77
+ & $pdb2pdb $assembly / out $intermediatePdb / extract
78
+ if (Test-Path $intermediatePdb ) {
79
+ & $pdb2pdb $assembly / pdb $intermediatePdb / out $output
80
+ Remove-Item $intermediatePdb
81
+
82
+ # Workaround for https://github.com/OpenCover/opencover/issues/800
83
+ Copy-Item $assembly $outputDir
84
+ }
85
+ }
86
+ }
87
+
88
+ $target_dir = [IO.Path ]::GetDirectoryName($target_dll )
89
+ Get-ChildItem $target_dir - Filter * .dll | Foreach-Object { Convert-Coverage - Pdb - assembly $_.FullName - outputDir $symbols_folder }
34
90
35
91
If (Test-Path $report_folder ) {
36
92
Remove-Item - Recurse - Force $report_folder
37
93
}
38
94
39
95
mkdir $report_folder | Out-Null
40
96
97
+ If ($AppVeyor ) {
98
+ $AppVeyorArg = ' -appveyor'
99
+ }
100
+
41
101
& $opencover_console `
42
102
- register:user `
43
- - threshold:1 `
44
103
- returntargetcode `
45
104
- hideskipped:All `
46
105
- filter:" +[PublicApi*]*" `
47
106
- excludebyattribute:* .ExcludeFromCodeCoverage* `
107
+ - excludebyfile:* \* Designer.cs `
108
+ - searchdirs:" $symbols_folder " `
48
109
- output:" $report_folder \OpenCover.PublicApiAnalyzer.xml" `
49
110
- target:" $xunit_runner_console " `
50
- - targetargs:" $target_dll -noshadow"
111
+ - targetargs:" $target_dll -noshadow $AppVeyorArg "
51
112
52
- & $report_generator - targetdir:$report_folder - reports:$report_folder \OpenCover.* .xml
113
+ If ($AppVeyor -and -not $? ) {
114
+ $host.UI.WriteErrorLine (' Build failed; coverage analysis aborted.' )
115
+ Exit $LASTEXITCODE
116
+ }
53
117
54
- $host.UI.WriteLine (" Open $report_folder \index.htm to see code coverage results." )
118
+ If (-not $NoReport ) {
119
+ & $report_generator - targetdir:$report_folder - reports:$report_folder \OpenCover.* .xml
120
+ $host.UI.WriteLine (" Open $report_folder \index.htm to see code coverage results." )
121
+ }
0 commit comments