-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun-coverage.ps1
More file actions
69 lines (56 loc) · 2.35 KB
/
Copy pathrun-coverage.ps1
File metadata and controls
69 lines (56 loc) · 2.35 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
#!/usr/bin/env pwsh
# Run tests with code coverage and generate reports
param(
[switch]$SkipReport = $false
)
$ErrorActionPreference = "Stop"
Write-Host "Running tests with code coverage..." -ForegroundColor Cyan
# Clean previous coverage results
$coverageDir = "TestResults"
if (Test-Path $coverageDir) {
Remove-Item $coverageDir -Recurse -Force
Write-Host "Cleaned previous coverage results" -ForegroundColor Yellow
}
# Run tests with coverage
dotnet test src/Cocoar.Reflectensions.Tests/Cocoar.Reflectensions.Tests.csproj `
--configuration Release `
--collect:"XPlat Code Coverage" `
--results-directory $coverageDir `
--settings coverlet.runsettings `
-- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=opencover
if ($LASTEXITCODE -ne 0) {
Write-Host "Tests failed!" -ForegroundColor Red
exit $LASTEXITCODE
}
Write-Host "Tests completed successfully!" -ForegroundColor Green
if (-not $SkipReport) {
# Check if reportgenerator is installed
$reportGenerator = Get-Command reportgenerator -ErrorAction SilentlyContinue
if (-not $reportGenerator) {
Write-Host "Installing ReportGenerator tool..." -ForegroundColor Yellow
dotnet tool install --global dotnet-reportgenerator-globaltool
}
# Find coverage file
$coverageFile = Get-ChildItem -Path $coverageDir -Filter "coverage.opencover.xml" -Recurse | Select-Object -First 1
if ($coverageFile) {
Write-Host "Generating coverage report..." -ForegroundColor Cyan
$reportDir = "TestResults/CoverageReport"
reportgenerator `
-reports:"$($coverageFile.FullName)" `
-targetdir:"$reportDir" `
-reporttypes:"Html;TextSummary" `
-assemblyfilters:"+Cocoar.Reflectensions*"
Write-Host "`nCoverage Report Generated!" -ForegroundColor Green
Write-Host "Open: $reportDir/index.html" -ForegroundColor Cyan
# Display summary
$summaryFile = "$reportDir/Summary.txt"
if (Test-Path $summaryFile) {
Write-Host "`n=== Coverage Summary ===" -ForegroundColor Cyan
Get-Content $summaryFile
}
} else {
Write-Host "Warning: Coverage file not found!" -ForegroundColor Yellow
}
} else {
Write-Host "Skipping report generation (use without -SkipReport to generate)" -ForegroundColor Yellow
}