Integrate test coverage reporting into the psake build script (#66)

* Integrate coverage reporting into psake script
* Fix versioning bug in build script
This commit is contained in:
Bevan Arps 2017-09-28 07:56:54 +13:00 коммит произвёл Bevan Arps
Родитель b9efa88925
Коммит 1d58b9f75f
2 изменённых файлов: 62 добавлений и 44 удалений

Просмотреть файл

@ -50,8 +50,8 @@ Task Clean.PublishFolder {
Task Generate.Version {
$script:versionBase = get-content $baseDir\version.txt -ErrorAction SilentlyContinue
if ($version -eq $null) {
throw "Unable to load .\version.txt"
if ($versionBase -eq $null) {
throw "Unable to load $baseDir\version.txt"
}
$versionLastUpdated = git rev-list -1 HEAD $baseDir\version.txt
$script:patchVersion = git rev-list "$versionLastUpdated..HEAD" --count
@ -92,6 +92,24 @@ Task Unit.Tests -Depends Requires.DotNetExe, Build.SesTest {
}
}
Task Cover.Tests -Depends Requires.Opencover, Requires.ReportGenerator, Requires.OutDir, Build.SesTest {
$filter = "+[*]* -[xunit.*]* -[Fluent*]* -[*.Tests]*"
$logLevel = "info"
foreach ($project in (resolve-path $testsDir\*\*.csproj)){
$projectName = split-path $project -Leaf
Write-SubtaskName $projectName
exec {
& $openCoverExe -oldStyle "-target:$dotnetExe" "-targetargs:test $project" -register:user "-filter:$filter" -log:$loglevel -output:$outDir\$projectName.cover.xml
}
}
Write-SubtaskName "Generating Coverage Report"
& $reportGeneratorExe "-reports:$outDir\*.cover.xml" "-targetdir:$outDir\cover\"
}
Task Publish.SesTest.Win64 -Depends Requires.DotNetExe, Restore.NuGetPackages {
exec {
& $dotnetExe publish $srcDir\sestest\sestest.csproj --self-contained --output $publishDir\sestest\win10-x64 --runtime win10-x64 /p:Version=$semanticVersion
@ -156,13 +174,11 @@ Task Requires.Configuration {
Task Requires.DotNetExe {
$script:dotnetExe = (get-command dotnet).Path
if ($dotnetExe -eq $null)
{
if ($dotnetExe -eq $null) {
$script:dotnetExe = resolve-path $env:ProgramFiles\dotnet\dotnet.exe -ErrorAction SilentlyContinue
}
if ($dotnetExe -eq $null)
{
if ($dotnetExe -eq $null) {
throw "Failed to find dotnet.exe"
}
@ -173,19 +189,40 @@ Task Requires.MsBuild {
# prefer MSBuild from VS2017 if its there
$script:msbuildExe = resolve-path "${env:ProgramFiles(x86)}\Microsoft Visual Studio\2017\*\MSBuild\*\Bin\MSBuild.exe" -ErrorAction SilentlyContinue
if ($msbuildExe -eq $null)
{
if ($msbuildExe -eq $null) {
$script:msbuildExe = (get-command msbuild).Path
}
if ($msbuildExe -eq $null)
{
if ($msbuildExe -eq $null) {
throw "Failed to find msbuild.exe"
}
Write-Host "MSBuild executable: $msbuildExe"
}
Task Requires.OpenCover {
$script:openCoverExe = resolve-path $env:userprofile\.nuget\packages\OpenCover\*\tools\OpenCover.Console.exe -ErrorAction SilentlyContinue
if ($openCoverExe -eq $null) {
throw "Failed to find OpenCover.Console.exe"
}
Write-Output "Opencover executable: $openCoverExe"
}
Task Requires.OutDir {
if (!(test-path $outDir)) {
mkdir $outDir -ErrorAction SilentlyContinue | Out-Null
}
if (!(test-path $outDir)) {
throw "Output folder does not exist"
}
Write-Host "Output folder is $outDir"
}
Task Requires.Platform {
if ($targetPlatform -eq $null) {
@ -195,6 +232,19 @@ Task Requires.Platform {
Write-Host "Target platform is $targetPlatform"
}
Task Requires.ReportGenerator {
$script:reportGeneratorExe = resolve-path $env:userprofile\.nuget\packages\reportgenerator\*\tools\ReportGenerator.exe -ErrorAction SilentlyContinue |
Sort-Object -Property "Name" |
select-object -last 1
if ($reportGeneratorExe -eq $null) {
throw "Failed to find ReportGenerator.exe"
}
Write-Output "Report Generator executable: $reportGeneratorExe"
}
## --------------------------------------------------------------------------------
## Support Functions
## --------------------------------------------------------------------------------

Просмотреть файл

@ -1,37 +1,5 @@
#
# Run unit tests and generate a coverage report
#
. $PSScriptRoot\scripts\includes.ps1
Write-Divider
$dotnetExe = (get-command dotnet).Path
Write-Output "Dotnet executable: $dotnetExe"
$openCoverExe = resolve-path $env:userprofile\.nuget\packages\OpenCover\*\tools\OpenCover.Console.exe
Write-Output "Opencover executable: $openCoverExe"
$reportGeneratorExe = resolve-path $env:userprofile\.nuget\packages\reportgenerator\*\tools\ReportGenerator.exe
Write-Output "Report Generator executable: $reportGeneratorExe"
Write-Divider
$commonTests = resolve-path .\tests\Microsoft.Azure.Batch.SoftwareEntitlement.Common.Tests\*.csproj
$sesTests = resolve-path .\tests\Microsoft.Azure.Batch.SoftwareEntitlement.Tests\*.csproj
$logLevel = "info"
$filter = "+[*]* -[xunit.*]* -[Fluent*]* -[*.Tests]*"
Write-Header "Running tests for: $commonTests"
& $openCoverExe -oldStyle "-target:$dotnetExe" "-targetargs:test $commonTests" -register:user "-filter:$filter" -log:$loglevel -output:.\out\Common.cover.xml
Write-Header "Running tests for $sesTests"
& $openCoverExe -oldStyle "-target:$dotnetExe" "-targetargs:test $sesTests" -register:user "-filter:$filter" -log:$loglevel -output:.\out\Ses.cover.xml
Write-Header "Generating Report"
& $reportGeneratorExe "-reports:.\out\Common.cover.xml;.\out\Ses.cover.xml" "-targetdir:.\out\cover\"
$reportIndex = resolve-path .\out\cover\index.htm
Write-Divider
Write-Output "Test coverage report file: $reportIndex"
& $reportIndex
. .\scripts\bootstrap.ps1
invoke-psake -buildFile .\scripts\psake-build.ps1 -taskList Cover.Tests