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,32 +29,121 @@ $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 = " ..\StyleCop.Analyzers\StyleCop.Analyzers.Test\bin\$Configuration \StyleCop.Analyzers.Test.dll"
40+ $symbols_folder = ' .\OpenCover.Symbols'
41+ $target_dll = " ..\StyleCop.Analyzers\StyleCop.Analyzers.Test\bin\$Configuration \net452\StyleCop.Analyzers.Test.dll"
42+ $target_dll_csharp7 = " ..\StyleCop.Analyzers\StyleCop.Analyzers.Test.CSharp7\bin\$Configuration \net46\StyleCop.Analyzers.Test.CSharp7.dll"
43+
44+ If (Test-Path $symbols_folder ) {
45+ Remove-Item - Recurse - Force $symbols_folder
46+ }
47+
48+ $symbols_folder_csharp6 = Join-Path $symbols_folder ' CSharp6'
49+ $symbols_folder_csharp7 = Join-Path $symbols_folder ' CSharp7'
50+ mkdir $symbols_folder | Out-Null
51+ mkdir $symbols_folder_csharp6 | Out-Null
52+ mkdir $symbols_folder_csharp7 | Out-Null
53+
54+ function Convert-Coverage-Pdb () {
55+ param (
56+ [string ]$assembly ,
57+ [string ]$outputDir
58+ )
59+ $sourceDir = [IO.Path ]::GetDirectoryName($assembly )
60+ $outputName = [IO.Path ]::ChangeExtension([IO.Path ]::GetFileName($assembly ), ' pdb' )
61+ $sourcePdb = Join-Path $sourceDir $outputName
62+ $output = Join-Path $outputDir $outputName
63+ if (Test-Path $sourcePdb ) {
64+ & $pdb2pdb $assembly / out $output
65+
66+ # Workaround for https://github.com/OpenCover/opencover/issues/800
67+ Remove-Item $sourcePdb
68+ Copy-Item $assembly $outputDir
69+ }
70+ }
71+
72+ function Extract-Coverage-Pdb () {
73+ param (
74+ [string ]$assembly ,
75+ [string ]$outputDir
76+ )
77+ $sourceDir = [IO.Path ]::GetDirectoryName($assembly )
78+ $outputName = [IO.Path ]::ChangeExtension([IO.Path ]::GetFileName($assembly ), ' pdb' )
79+ $intermediatePdb = Join-Path $sourceDir $outputName
80+ $output = Join-Path $outputDir $outputName
81+ if (-not (Test-Path $output )) {
82+ & $pdb2pdb $assembly / out $intermediatePdb / extract
83+ if (Test-Path $intermediatePdb ) {
84+ & $pdb2pdb $assembly / pdb $intermediatePdb / out $output
85+ Remove-Item $intermediatePdb
86+
87+ # Workaround for https://github.com/OpenCover/opencover/issues/800
88+ Copy-Item $assembly $outputDir
89+ }
90+ }
91+ }
92+
93+ $target_dir = [IO.Path ]::GetDirectoryName($target_dll )
94+ Get-ChildItem $target_dir - Filter * .dll | Foreach-Object { Convert-Coverage - Pdb - assembly $_.FullName - outputDir $symbols_folder_csharp6 }
95+ Get-ChildItem $target_dir - Filter * .dll | Foreach-Object { Extract- Coverage- Pdb - assembly $_.FullName - outputDir $symbols_folder_csharp6 }
96+
97+ $target_dir = [IO.Path ]::GetDirectoryName($target_dll_csharp7 )
98+ Get-ChildItem $target_dir - Filter * .dll | Foreach-Object { Convert-Coverage - Pdb - assembly $_.FullName - outputDir $symbols_folder_csharp7 }
99+ Get-ChildItem $target_dir - Filter * .dll | Foreach-Object { Extract- Coverage- Pdb - assembly $_.FullName - outputDir $symbols_folder_csharp7 }
34100
35101If (Test-Path $report_folder ) {
36102 Remove-Item - Recurse - Force $report_folder
37103}
38104
39105mkdir $report_folder | Out-Null
40106
107+ If ($AppVeyor ) {
108+ $AppVeyorArg = ' -appveyor'
109+ }
110+
41111& $opencover_console `
42112 - register:user `
43- - threshold:1 `
44113 - returntargetcode `
45114 - hideskipped:All `
46115 - filter:" +[StyleCop*]*" `
47116 - excludebyattribute:* .ExcludeFromCodeCoverage* `
48117 - excludebyfile:* \* Designer.cs `
118+ - searchdirs:" $symbols_folder_csharp6 " `
49119 - output:" $report_folder \OpenCover.StyleCopAnalyzers.xml" `
50120 - target:" $xunit_runner_console " `
51- - targetargs:" $target_dll -noshadow"
121+ - targetargs:" $target_dll -noshadow $AppVeyorArg "
52122
53- & $report_generator - targetdir:$report_folder - reports:$report_folder \OpenCover.* .xml
123+ If ($AppVeyor -and -not $? ) {
124+ $host.UI.WriteErrorLine (' Build failed; coverage analysis aborted.' )
125+ Exit $LASTEXITCODE
126+ }
127+
128+ & $opencover_console `
129+ - register:user `
130+ - returntargetcode `
131+ - hideskipped:All `
132+ - filter:" +[StyleCop*]*" `
133+ - excludebyattribute:* .ExcludeFromCodeCoverage* `
134+ - excludebyfile:* \* Designer.cs `
135+ - searchdirs:" $symbols_folder_csharp7 " `
136+ - output:" $report_folder \OpenCover.StyleCopAnalyzers.xml" `
137+ - mergebyhash - mergeoutput `
138+ - target:" $xunit_runner_console " `
139+ - targetargs:" $target_dll_csharp7 -noshadow $AppVeyorArg "
54140
55- $host.UI.WriteLine (" Open $report_folder \index.htm to see code coverage results." )
141+ If ($AppVeyor -and -not $? ) {
142+ $host.UI.WriteErrorLine (' Build failed; coverage analysis aborted.' )
143+ Exit $LASTEXITCODE
144+ }
145+
146+ If (-not $NoReport ) {
147+ & $report_generator - targetdir:$report_folder - reports:$report_folder \OpenCover.* .xml
148+ $host.UI.WriteLine (" Open $report_folder \index.htm to see code coverage results." )
149+ }
0 commit comments