11param (
2- [switch ]$Debug
2+ [switch ]$Debug ,
3+ [switch ]$NoBuild ,
4+ [switch ]$NoReport ,
5+ [switch ]$AppVeyor
36)
47
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+ }
1115
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+ }
1520}
1621
1722If ($Debug ) {
@@ -24,31 +29,93 @@ $packageConfig = [xml](Get-Content ..\.nuget\packages.config)
2429$opencover_version = $packageConfig.SelectSingleNode (' /packages/package[@id="OpenCover"]' ).version
2530$reportgenerator_version = $packageConfig.SelectSingleNode (' /packages/package[@id="ReportGenerator"]' ).version
2631$xunitrunner_version = $packageConfig.SelectSingleNode (' /packages/package[@id="xunit.runner.console"]' ).version
32+ $pdb2pdb_version = $packageConfig.SelectSingleNode (' /packages/package[@id="Microsoft.DiaSymReader.Pdb2Pdb"]' ).version
2733
2834$packages_folder = ' ..\packages'
2935$opencover_console = " $packages_folder \OpenCover.$opencover_version \tools\OpenCover.Console.exe"
3036$xunit_runner_console = " $packages_folder \xunit.runner.console.$xunitrunner_version \tools\xunit.console.x86.exe"
3137$report_generator = " $packages_folder \ReportGenerator.$reportgenerator_version \tools\ReportGenerator.exe"
38+ $pdb2pdb = " $packages_folder \Microsoft.DiaSymReader.Pdb2Pdb.$pdb2pdb_version \tools\Pdb2Pdb.exe"
3239$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 }
3490
3591If (Test-Path $report_folder ) {
3692 Remove-Item - Recurse - Force $report_folder
3793}
3894
3995mkdir $report_folder | Out-Null
4096
97+ If ($AppVeyor ) {
98+ $AppVeyorArg = ' -appveyor'
99+ }
100+
41101& $opencover_console `
42102 - register:user `
43- - threshold:1 `
44103 - returntargetcode `
45104 - hideskipped:All `
46105 - filter:" +[PublicApi*]*" `
47106 - excludebyattribute:* .ExcludeFromCodeCoverage* `
107+ - excludebyfile:* \* Designer.cs `
108+ - searchdirs:" $symbols_folder " `
48109 - output:" $report_folder \OpenCover.PublicApiAnalyzer.xml" `
49110 - target:" $xunit_runner_console " `
50- - targetargs:" $target_dll -noshadow"
111+ - targetargs:" $target_dll -noshadow $AppVeyorArg "
51112
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+ }
53117
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