Skip to content

Commit c25c6e4

Browse files
committed
Merge pull request #1106 from libgit2/ntk/coverage
Analyze code coverage
2 parents 9d3fe4d + 9ab3805 commit c25c6e4

File tree

2 files changed

+68
-2
lines changed

2 files changed

+68
-2
lines changed

LibGit2Sharp.Tests/MetaFixture.cs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using LibGit2Sharp.Tests.TestHelpers;
1010
using Xunit;
1111
using Xunit.Extensions;
12+
using Moq;
1213

1314
namespace LibGit2Sharp.Tests
1415
{
@@ -107,6 +108,28 @@ public void TypesInLibGit2SharpMustBeExtensibleInATestingContext()
107108
{
108109
nonTestableTypes.Add(type, new List<string>());
109110
}
111+
112+
if (type.IsAbstract)
113+
{
114+
continue;
115+
}
116+
117+
try
118+
{
119+
if (type.ContainsGenericParameters)
120+
{
121+
var constructType = type.MakeGenericType(Enumerable.Repeat(typeof(object), type.GetGenericArguments().Length).ToArray());
122+
Activator.CreateInstance(constructType, true);
123+
}
124+
else
125+
{
126+
Activator.CreateInstance(type, true);
127+
}
128+
}
129+
catch (Exception ex)
130+
{
131+
nonTestableTypes.Add(type, new List<string>());
132+
}
110133
}
111134

112135
if (nonTestableTypes.Any())
@@ -246,7 +269,7 @@ public void GetEnumeratorMethodsInLibGit2SharpMustBeVirtualForTestability()
246269
var nonVirtualGetEnumeratorMethods = Assembly.GetAssembly(typeof(IRepository))
247270
.GetExportedTypes()
248271
.Where(t =>
249-
t.Namespace == typeof (IRepository).Namespace &&
272+
t.Namespace == typeof(IRepository).Namespace &&
250273
!t.IsSealed &&
251274
!t.IsAbstract &&
252275
t.GetInterfaces().Any(i => i.IsAssignableFrom(typeof(IEnumerable<>))))

appveyor.yml

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ skip_tags: true
1010
clone_folder: C:\projects\libgit2sharp
1111

1212
environment:
13+
coveralls_token:
14+
secure: ixIsBslo9NheDb5lJknF58EYdgvZ0r3/L0ecRiXjfXmjHBLvoSU6/ZRwaMM+BAlG
1315
coverity_token:
1416
secure: nuzUT+HecXGIi3KaPd/1hgFEZJan/j6+oNbPV75JKjk=
1517
coverity_email:
@@ -60,6 +62,11 @@ install:
6062
Write-Host "Should package Nuget artifact = " -NoNewLine
6163
Write-Host $Env:SHOULD_PACKAGE_NUGET_ARTIFACT -ForegroundColor "Green"
6264
65+
$Env:SHOULD_RUN_COVERALLS = $($Env:APPVEYOR_PULL_REQUEST_NUMBER -eq $null `
66+
-and $Env:APPVEYOR_SCHEDULED_BUILD -eq $False)
67+
Write-Host "Should run Coveralls = " -NoNewLine
68+
Write-Host $Env:SHOULD_RUN_COVERALLS -ForegroundColor "Green"
69+
6370
Write-Host "Should publish on success = " -NoNewLine
6471
Write-Host $Env:publish_on_success -ForegroundColor "Green"
6572
@@ -68,6 +75,12 @@ install:
6875
cinst sourcelink -y
6976
}
7077
78+
If ($Env:SHOULD_RUN_COVERALLS -eq $True)
79+
{
80+
nuget install OpenCover -Version 4.5.3723 -ExcludeVersion -OutputDirectory .\packages
81+
nuget install coveralls.net -Version 0.5.0 -ExcludeVersion -OutputDirectory .\packages
82+
}
83+
7184
If ($Env:SHOULD_RUN_COVERITY_ANALYSIS -eq $True)
7285
{
7386
cinst curl -y
@@ -98,7 +111,20 @@ test_script:
98111
- ps: |
99112
If ($Env:SHOULD_RUN_COVERITY_ANALYSIS -eq $False)
100113
{
101-
& "$Env:xunit_runner" "$Env:APPVEYOR_BUILD_FOLDER\LibGit2Sharp.Tests\bin\Release\LibGit2Sharp.Tests.dll" /appveyor
114+
If ($Env:SHOULD_RUN_COVERALLS -eq $True -and $Env:publish_on_success -eq $True)
115+
{
116+
.\packages\OpenCover\OpenCover.Console.exe `
117+
-register:user `
118+
-target:$Env:xunit_runner `
119+
"-targetargs:""$Env:APPVEYOR_BUILD_FOLDER\LibGit2Sharp.Tests\bin\Release\LibGit2Sharp.Tests.dll"" /noshadow /appveyor" `
120+
"-filter:+[LibGit2Sharp]* -[LibGit2Sharp.Tests]*" `
121+
-hideskipped:All `
122+
-output:opencoverCoverage.xml
123+
}
124+
Else
125+
{
126+
& "$Env:xunit_runner" "$Env:APPVEYOR_BUILD_FOLDER\LibGit2Sharp.Tests\bin\Release\LibGit2Sharp.Tests.dll" /appveyor
127+
}
102128
}
103129
104130
after_test:
@@ -122,6 +148,23 @@ after_test:
122148
Get-ChildItem "$Env:APPVEYOR_BUILD_FOLDER\LibGit2sharp\*.nupkg" | % { Push-AppveyorArtifact $_.FullName -FileName $_.Name }
123149
}
124150
151+
If ($Env:SHOULD_RUN_COVERALLS -eq $True -and $Env:publish_on_success -eq $True)
152+
{
153+
Write-Host "Uploading code coverage result..." -ForegroundColor "Green"
154+
155+
.\packages\coveralls.net\csmacnz.Coveralls.exe `
156+
--opencover -i opencoverCoverage.xml `
157+
--repoToken $Env:coveralls_token `
158+
--commitId $Env:APPVEYOR_REPO_COMMIT `
159+
--commitBranch $Env:APPVEYOR_REPO_BRANCH `
160+
--commitAuthor $Env:APPVEYOR_REPO_COMMIT_AUTHOR `
161+
--commitEmail $Env:APPVEYOR_REPO_COMMIT_AUTHOR_EMAIL `
162+
--commitMessage $Env:APPVEYOR_REPO_COMMIT_MESSAGE `
163+
--useRelativePaths `
164+
--basePath "$Env:APPVEYOR_BUILD_FOLDER\"`
165+
--jobId $Env:APPVEYOR_JOB_ID
166+
}
167+
125168
If ($Env:SHOULD_RUN_COVERITY_ANALYSIS -eq $True -and $Env:publish_on_success -eq $True)
126169
{
127170
7z a "$Env:APPVEYOR_BUILD_FOLDER\$Env:APPVEYOR_PROJECT_NAME.zip" "$Env:APPVEYOR_BUILD_FOLDER\cov-int\"

0 commit comments

Comments
 (0)