Преглед изворни кода

Add support for code coverage

Oren Novotny пре 9 година
родитељ
комит
fbd6e3112b
3 измењених фајлова са 61 додато и 2 уклоњено
  1. 28 1
      Ix.NET/Source/build-new.ps1
  2. 29 1
      Rx.NET/Source/build-new.ps1
  3. 4 0
      appveyor.yml

+ 28 - 1
Ix.NET/Source/build-new.ps1

@@ -4,6 +4,14 @@ $configuration = "Release"
 
 $nuspecDir = Join-Path $scriptPath "NuSpecs"
 $isAppVeyor = Test-Path -Path env:\APPVEYOR
+$outputLocation = Join-Path $scriptPath "testResults"
+
+#remove any old coverage file
+md -Force $outputLocation | Out-Null
+$outputPath = (Resolve-Path $outputLocation).Path
+$outputFile = Join-Path $outputPath -childpath 'coverage.xml'
+Remove-Item $outputPath -Force -Recurse
+md -Force $outputLocation | Out-Null
 
 if (!(Test-Path .\nuget.exe)) {
     wget "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe" -outfile .\nuget.exe
@@ -16,6 +24,10 @@ $msbuildExe = Join-Path $msbuild.MSBuildToolsPath "msbuild.exe"
 
 # get tools
 .\nuget.exe install -excludeversion gitversion.commandline -outputdirectory packages
+.\nuget.exe install -excludeversion OpenCover -outputdirectory packages
+.\nuget.exe install -excludeversion ReportGenerator -outputdirectory packages
+.\nuget.exe install -excludeversion coveralls.io -outputdirectory packages
+
 
 #update version
 .\packages\gitversion.commandline\tools\gitversion.exe /l console /output buildserver /updateassemblyinfo
@@ -67,7 +79,10 @@ foreach ($nuspec in $nuspecs) {
 
 Write-Host "Running tests" -Foreground Green
 $testDirectory = Join-Path $scriptPath "Tests"  
-dotnet test $testDirectory -c $configuration
+
+# Execute OpenCover with a target of "dotnet test"
+.\packages\OpenCover\tools\OpenCover.Console.exe  -register:user -oldStyle -mergeoutput -target:dotnet.exe -threshold:1 -targetdir:"$testDirectory" -targetargs:"test $testDirectory -c $configuration" -output:"$outputFile" -skipautoprops -returntargetcode "-excludebyattribute:System.Diagnostics.DebuggerNonUserCodeAttribute" -nodefaultfilters  -hideskipped:All -filter:"+[*]* -[*.Tests]* -[Tests]* -[xunit.*]*" 
+
 if ($LastExitCode -ne 0) { 
     Write-Host "Error with tests" -Foreground Red
     if($isAppVeyor) {
@@ -75,6 +90,18 @@ if ($LastExitCode -ne 0) {
     }  
 }
 
+
+# Either display or publish the results
+if ($env:CI -eq 'True')
+{
+  .\packages\coveralls.io\tools\coveralls.net.exe  --opencover "$outputFile" --full-sources
+}
+else
+{
+	.\packages\ReportGenerator\tools\ReportGenerator.exe -reports:"$outputFile" -targetdir:"$outputPath"
+	 &$outPutPath/index.htm
+}
+
 Write-Host "Reverting AssemblyInfo's" -Foreground Green
 gci $scriptPath -re -in AssemblyInfo.cs | %{ git checkout $_ } 
 

+ 29 - 1
Rx.NET/Source/build-new.ps1

@@ -4,6 +4,14 @@ $configuration = "Release"
 
 $nuspecDir = Join-Path $scriptPath "NuSpecs"
 $isAppVeyor = Test-Path -Path env:\APPVEYOR
+$outputLocation = Join-Path $scriptPath "testResults"
+
+#remove any old coverage file
+md -Force $outputLocation | Out-Null
+$outputPath = (Resolve-Path $outputLocation).Path
+$outputFile = Join-Path $outputPath -childpath 'coverage.xml'
+Remove-Item $outputPath -Force -Recurse
+md -Force $outputLocation | Out-Null
 
 if (!(Test-Path .\nuget.exe)) {
     wget "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe" -outfile .\nuget.exe
@@ -15,6 +23,12 @@ $msbuildExe = Join-Path $msbuild.MSBuildToolsPath "msbuild.exe"
 
 # get version
 .\nuget.exe install -excludeversion gitversion.commandline -outputdirectory packages
+.\nuget.exe install -excludeversion OpenCover -outputdirectory packages
+.\nuget.exe install -excludeversion ReportGenerator -outputdirectory packages
+.\nuget.exe install -excludeversion coveralls.io -outputdirectory packages
+
+
+#update version
 .\packages\gitversion.commandline\tools\gitversion.exe /l console /output buildserver /updateassemblyinfo
 
 $versionObj = .\packages\gitversion.commandline\tools\gitversion.exe | ConvertFrom-Json 
@@ -80,7 +94,10 @@ foreach ($nuspec in $nuspecs)
 
 Write-Host "Running tests" -Foreground Green
 $testDirectory = Join-Path $scriptPath "Tests.System.Reactive"
-dotnet test $testDirectory -c "$configuration"
+
+# Execute OpenCover with a target of "dotnet test"
+.\packages\OpenCover\tools\OpenCover.Console.exe  -register:user -oldStyle -mergeoutput -target:dotnet.exe -threshold:1 -targetdir:"$testDirectory" -targetargs:"test $testDirectory -c $configuration" -output:"$outputFile" -skipautoprops -returntargetcode "-excludebyattribute:System.Diagnostics.DebuggerNonUserCodeAttribute" -nodefaultfilters  -hideskipped:All -filter:"+[*]* -[*.Tests]* -[Tests.*]* -[xunit.*]* -[*]Xunit.*" 
+
 if ($LastExitCode -ne 0) { 
     Write-Host "Error with tests" -Foreground Red
     if($isAppVeyor) {
@@ -88,5 +105,16 @@ if ($LastExitCode -ne 0) {
     }  
 }
 
+# Either display or publish the results
+if ($env:CI -eq 'True')
+{
+  .\packages\coveralls.io\tools\coveralls.net.exe  --opencover "$outputFile" --full-sources
+}
+else
+{
+	.\packages\ReportGenerator\tools\ReportGenerator.exe -reports:"$outputFile" -targetdir:"$outputPath"
+	 &$outPutPath/index.htm
+}
+
 Write-Host "Reverting AssemblyInfo's" -Foreground Green
 gci $scriptPath -re -in AssemblyInfo.cs | %{ git checkout $_ } 

+ 4 - 0
appveyor.yml

@@ -2,6 +2,10 @@ image: Visual Studio 2015
 init:
   - cmd: set
 
+environment:
+  COVERALLS_REPO_TOKEN:
+    secure: UHHvZf0xOadSg6wc6ITa3XqtDf3AIv31D2Bs0opREd4/Ni+1KsqcHitWDAahZhTG
+
 branches:
   only:
     - master