Support Local Code Coverage Usage
@@ -12,6 +12,9 @@ This script merges the coverage data.
.PARAMETER Tls
The TLS library test.
+.PARAMETER Local
+ Indicates local execution/usage (not Azure Pipelines) of the script.
+
#>
param (
@@ -25,7 +28,10 @@ param (
[Parameter(Mandatory = $false)]
[ValidateSet("schannel", "openssl", "stub", "mitls")]
- [string]$Tls = ""
+ [string]$Tls = "",
+
+ [Parameter(Mandatory = $false)]
+ [switch]$Local = $false
)
Set-StrictMode -Version 'Latest'
@@ -43,19 +49,37 @@ if ("" -eq $Tls) {
# Root directory of the project.
$RootDir = Split-Path $PSScriptRoot -Parent
+# Path to the coverage tool.
+$CoverageExe = 'C:\"Program Files"\OpenCppCoverage\OpenCppCoverage.exe'
+
+# The input directory to search for files. When run locally (not on Azure Pipelines)
+# the files are in a different location.
$CoverageDir = Join-Path $RootDir "artifacts\coverage\windows\$($Arch)_$($Config)_$($Tls)"
+if ($Local) {
+ $CoverageDir = Join-Path $RootDir "artifacts\coverage"
+}
+# Build up the args with the list of input files.
$CoverageMergeParams = ""
-
foreach ($file in $(Get-ChildItem -Path $CoverageDir -Filter '*.cov')) {
$CoverageMergeParams += " --input_coverage $(Join-Path $CoverageDir $file.Name)"
}
+if ($CoverageMergeParams -eq "") {
+ Write-Error "No coverage results to merge!"
+}
-if ($CoverageMergeParams -ne "") {
+if ($Local) {
+ # Locally, output the HTML report.
+ $CoverageMergeParams += " --export_type html:$(Join-Path $CoverageDir "report")"
+} else {
+ # Use cobertura format for Azure Pipelines.
$CoverageMergeParams += " --export_type cobertura:$(Join-Path $CoverageDir "msquiccoverage.xml")"
+}
- $CoverageExe = 'C:\"Program Files"\OpenCppCoverage\OpenCppCoverage.exe'
+# Call the tool to merge the files into the appropriate format.
Invoke-Expression ($CoverageExe + $CoverageMergeParams) | Out-Null
-} else {
- Write-Warning "No coverage results to merge!"
+
+if ($Local) {
+ # Open up the HTML report that was just generated.
+ start (Join-Path $CoverageDir "report\index.html")
}
