-
-
Notifications
You must be signed in to change notification settings - Fork 230
Expand file tree
/
Copy pathcoverage-windows.ps1
More file actions
70 lines (62 loc) · 2.6 KB
/
Copy pathcoverage-windows.ps1
File metadata and controls
70 lines (62 loc) · 2.6 KB
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
[CmdletBinding()]
param(
[string]$BuildDirectory = "build",
[string]$Configuration = "RelWithDebInfo",
[double]$MinimumLineCoverage = 80
)
$ErrorActionPreference = "Stop"
$repoRoot = $PSScriptRoot
$buildPath = if ([IO.Path]::IsPathRooted($BuildDirectory)) {
[IO.Path]::GetFullPath($BuildDirectory)
} else {
[IO.Path]::GetFullPath((Join-Path $repoRoot $BuildDirectory))
}
$testExecutable = Join-Path $buildPath "$Configuration\et-test.exe"
$outputDirectory = Join-Path $buildPath "coverage-windows"
$coverageFile = Join-Path $outputDirectory "coverage.cobertura.xml"
$coverageLog = Join-Path $outputDirectory "coverage.log"
$collector = Get-ChildItem "C:\Program Files\Microsoft Visual Studio" `
-Recurse -Filter "Microsoft.CodeCoverage.Console.exe" -ErrorAction SilentlyContinue |
Sort-Object FullName -Descending |
Select-Object -First 1 -ExpandProperty FullName
if (-not $collector) {
throw "Microsoft.CodeCoverage.Console.exe was not found. Install Visual Studio Code Coverage tools."
}
cmake --build $buildPath --config $Configuration --target et-test --parallel
if ($LASTEXITCODE -ne 0) {
throw "The Windows unit-test build failed."
}
New-Item -ItemType Directory -Force $outputDirectory | Out-Null
& $collector collect $testExecutable --reporter compact `
--output $coverageFile --output-format cobertura `
--log-file $coverageLog --nologo
if ($LASTEXITCODE -ne 0) {
throw "The Windows unit tests or coverage collection failed."
}
[xml]$report = Get-Content $coverageFile
$sourceRoot = [IO.Path]::GetFullPath((Join-Path $repoRoot "src")) + [IO.Path]::DirectorySeparatorChar
$lines = @{}
foreach ($class in $report.coverage.packages.package.classes.class) {
$filename = [string]$class.filename
if (-not $filename.StartsWith($sourceRoot, [StringComparison]::OrdinalIgnoreCase) -or
-not $filename.EndsWith(".cpp", [StringComparison]::OrdinalIgnoreCase)) {
continue
}
foreach ($line in @($class.lines.line)) {
$key = "${filename}:$($line.number)"
$hits = [int]$line.hits
if (-not $lines.ContainsKey($key) -or $hits -gt $lines[$key]) {
$lines[$key] = $hits
}
}
}
if ($lines.Count -eq 0) {
throw "The coverage report contains no Eternal Terminal source lines."
}
$covered = @($lines.Values | Where-Object { $_ -gt 0 }).Count
$rate = 100.0 * $covered / $lines.Count
Write-Host ("Windows C++ implementation line coverage: {0:N2}% ({1}/{2})" -f $rate, $covered, $lines.Count)
Write-Host "Cobertura report: $coverageFile"
if ($rate -lt $MinimumLineCoverage) {
throw ("Windows C++ implementation line coverage {0:N2}% is below the required {1:N2}%." -f $rate, $MinimumLineCoverage)
}