From 1cba9e4759fa3beae2b5af6c8b1e7e63fada2338 Mon Sep 17 00:00:00 2001 From: nulltoken Date: Fri, 19 Jun 2015 11:39:57 +0200 Subject: [PATCH 1/2] Publish code coverage --- appveyor.yml | 45 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index c2ae0150e..063c758d2 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -10,6 +10,8 @@ skip_tags: true clone_folder: C:\projects\libgit2sharp environment: + coveralls_token: + secure: ixIsBslo9NheDb5lJknF58EYdgvZ0r3/L0ecRiXjfXmjHBLvoSU6/ZRwaMM+BAlG coverity_token: secure: nuzUT+HecXGIi3KaPd/1hgFEZJan/j6+oNbPV75JKjk= coverity_email: @@ -60,6 +62,11 @@ install: Write-Host "Should package Nuget artifact = " -NoNewLine Write-Host $Env:SHOULD_PACKAGE_NUGET_ARTIFACT -ForegroundColor "Green" + $Env:SHOULD_RUN_COVERALLS = $($Env:APPVEYOR_PULL_REQUEST_NUMBER -eq $null ` + -and $Env:APPVEYOR_SCHEDULED_BUILD -eq $False) + Write-Host "Should run Coveralls = " -NoNewLine + Write-Host $Env:SHOULD_RUN_COVERALLS -ForegroundColor "Green" + Write-Host "Should publish on success = " -NoNewLine Write-Host $Env:publish_on_success -ForegroundColor "Green" @@ -68,6 +75,12 @@ install: cinst sourcelink -y } + If ($Env:SHOULD_RUN_COVERALLS -eq $True) + { + nuget install OpenCover -Version 4.5.3723 -ExcludeVersion -OutputDirectory .\packages + nuget install coveralls.net -Version 0.5.0 -ExcludeVersion -OutputDirectory .\packages + } + If ($Env:SHOULD_RUN_COVERITY_ANALYSIS -eq $True) { cinst curl -y @@ -98,7 +111,20 @@ test_script: - ps: | If ($Env:SHOULD_RUN_COVERITY_ANALYSIS -eq $False) { - & "$Env:xunit_runner" "$Env:APPVEYOR_BUILD_FOLDER\LibGit2Sharp.Tests\bin\Release\LibGit2Sharp.Tests.dll" /appveyor + If ($Env:SHOULD_RUN_COVERALLS -eq $True -and $Env:publish_on_success -eq $True) + { + .\packages\OpenCover\OpenCover.Console.exe ` + -register:user ` + -target:$Env:xunit_runner ` + "-targetargs:""$Env:APPVEYOR_BUILD_FOLDER\LibGit2Sharp.Tests\bin\Release\LibGit2Sharp.Tests.dll"" /noshadow /appveyor" ` + "-filter:+[LibGit2Sharp]* -[LibGit2Sharp.Tests]*" ` + -hideskipped:All ` + -output:opencoverCoverage.xml + } + Else + { + & "$Env:xunit_runner" "$Env:APPVEYOR_BUILD_FOLDER\LibGit2Sharp.Tests\bin\Release\LibGit2Sharp.Tests.dll" /appveyor + } } after_test: @@ -122,6 +148,23 @@ after_test: Get-ChildItem "$Env:APPVEYOR_BUILD_FOLDER\LibGit2sharp\*.nupkg" | % { Push-AppveyorArtifact $_.FullName -FileName $_.Name } } + If ($Env:SHOULD_RUN_COVERALLS -eq $True -and $Env:publish_on_success -eq $True) + { + Write-Host "Uploading code coverage result..." -ForegroundColor "Green" + + .\packages\coveralls.net\csmacnz.Coveralls.exe ` + --opencover -i opencoverCoverage.xml ` + --repoToken $Env:coveralls_token ` + --commitId $Env:APPVEYOR_REPO_COMMIT ` + --commitBranch $Env:APPVEYOR_REPO_BRANCH ` + --commitAuthor $Env:APPVEYOR_REPO_COMMIT_AUTHOR ` + --commitEmail $Env:APPVEYOR_REPO_COMMIT_AUTHOR_EMAIL ` + --commitMessage $Env:APPVEYOR_REPO_COMMIT_MESSAGE ` + --useRelativePaths ` + --basePath "$Env:APPVEYOR_BUILD_FOLDER\"` + --jobId $Env:APPVEYOR_JOB_ID + } + If ($Env:SHOULD_RUN_COVERITY_ANALYSIS -eq $True -and $Env:publish_on_success -eq $True) { 7z a "$Env:APPVEYOR_BUILD_FOLDER\$Env:APPVEYOR_PROJECT_NAME.zip" "$Env:APPVEYOR_BUILD_FOLDER\cov-int\" From 9ab380596487686ff2b89e35e5f6520cece3c008 Mon Sep 17 00:00:00 2001 From: Keith Dahlby Date: Mon, 22 Jun 2015 09:13:41 -0500 Subject: [PATCH 2/2] Attempt to create mockable instances --- LibGit2Sharp.Tests/MetaFixture.cs | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/LibGit2Sharp.Tests/MetaFixture.cs b/LibGit2Sharp.Tests/MetaFixture.cs index 86ecdf3c4..3d0a4898b 100644 --- a/LibGit2Sharp.Tests/MetaFixture.cs +++ b/LibGit2Sharp.Tests/MetaFixture.cs @@ -9,6 +9,7 @@ using LibGit2Sharp.Tests.TestHelpers; using Xunit; using Xunit.Extensions; +using Moq; namespace LibGit2Sharp.Tests { @@ -107,6 +108,28 @@ public void TypesInLibGit2SharpMustBeExtensibleInATestingContext() { nonTestableTypes.Add(type, new List()); } + + if (type.IsAbstract) + { + continue; + } + + try + { + if (type.ContainsGenericParameters) + { + var constructType = type.MakeGenericType(Enumerable.Repeat(typeof(object), type.GetGenericArguments().Length).ToArray()); + Activator.CreateInstance(constructType, true); + } + else + { + Activator.CreateInstance(type, true); + } + } + catch (Exception ex) + { + nonTestableTypes.Add(type, new List()); + } } if (nonTestableTypes.Any()) @@ -246,7 +269,7 @@ public void GetEnumeratorMethodsInLibGit2SharpMustBeVirtualForTestability() var nonVirtualGetEnumeratorMethods = Assembly.GetAssembly(typeof(IRepository)) .GetExportedTypes() .Where(t => - t.Namespace == typeof (IRepository).Namespace && + t.Namespace == typeof(IRepository).Namespace && !t.IsSealed && !t.IsAbstract && t.GetInterfaces().Any(i => i.IsAssignableFrom(typeof(IEnumerable<>))))