forked from libgit2/libgit2sharp
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/vNext' into error-handling-refactor
Conflicts: LibGit2Sharp/LibGit2SharpException.cs
- Loading branch information
Showing
68 changed files
with
6,900 additions
and
243 deletions.
There are no files selected for viewing
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,39 @@ | |||
using System.Linq; | |||
using LibGit2Sharp.Tests.TestHelpers; | |||
using Xunit; | |||
|
|||
namespace LibGit2Sharp.Tests | |||
{ | |||
public class DiffWorkdirToIndexFixture : BaseFixture | |||
{ | |||
/* | |||
* $ git diff | |||
* diff --git a/deleted_unstaged_file.txt b/deleted_unstaged_file.txt | |||
* deleted file mode 100644 | |||
* index f2e4113..0000000 | |||
* --- a/deleted_unstaged_file.txt | |||
* +++ /dev/null | |||
* @@ -1 +0,0 @@ | |||
* -stuff | |||
* diff --git a/modified_unstaged_file.txt b/modified_unstaged_file.txt | |||
* index 9217230..da6fd65 100644 | |||
* --- a/modified_unstaged_file.txt | |||
* +++ b/modified_unstaged_file.txt | |||
* @@ -1 +1,2 @@ | |||
* +some more text | |||
* more files! more files! | |||
*/ | |||
[Fact] | |||
public void CanCompareTheWorkDirAgainstTheIndex() | |||
{ | |||
using (var repo = new Repository(StandardTestRepoPath)) | |||
{ | |||
TreeChanges changes = repo.Diff.Compare(); | |||
|
|||
Assert.Equal(2, changes.Count()); | |||
Assert.Equal("deleted_unstaged_file.txt", changes.Deleted.Single().Path); | |||
Assert.Equal("modified_unstaged_file.txt", changes.Modified.Single().Path); | |||
} | |||
} | |||
} | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,89 @@ | |||
using System.Text; | |||
using Xunit; | |||
using System.Reflection; | |||
using System; | |||
using System.Linq; | |||
using System.Collections.Generic; | |||
|
|||
namespace LibGit2Sharp.Tests | |||
{ | |||
public class MetaFixture | |||
{ | |||
private static readonly Type[] excludedTypes = new[] { typeof(Repository) }; | |||
|
|||
// Related to https://github.com/libgit2/libgit2sharp/pull/185 | |||
[Fact] | |||
public void TypesInLibGit2SharpMustBeExtensibleInATestingContext() | |||
{ | |||
var nonTestableTypes = new Dictionary<Type, IEnumerable<string>>(); | |||
|
|||
IEnumerable<Type> libGit2SharpTypes = Assembly.GetAssembly(typeof(Repository)).GetExportedTypes().Where(t => !excludedTypes.Contains(t) && t.Namespace == typeof(Repository).Namespace); | |||
|
|||
foreach (Type type in libGit2SharpTypes) | |||
{ | |||
if (type.IsInterface || type.IsEnum || IsStatic(type)) | |||
continue; | |||
|
|||
ConstructorInfo[] publicConstructor = type.GetConstructors(BindingFlags.Public | BindingFlags.Instance); | |||
if (publicConstructor.Any()) | |||
{ | |||
continue; | |||
} | |||
|
|||
var nonVirtualMethodNamesForType = GetNonVirtualPublicMethodsNames(type).ToList(); | |||
if (nonVirtualMethodNamesForType.Any()) | |||
{ | |||
nonTestableTypes.Add(type, nonVirtualMethodNamesForType); | |||
continue; | |||
} | |||
|
|||
if (!HasEmptyProtectedConstructor(type)) | |||
{ | |||
nonTestableTypes.Add(type, new List<string>()); | |||
} | |||
} | |||
|
|||
if (nonTestableTypes.Any()) | |||
{ | |||
Assert.True(false, Environment.NewLine + BuildNonTestableTypesMessage(nonTestableTypes)); | |||
} | |||
} | |||
|
|||
private static string BuildNonTestableTypesMessage(Dictionary<Type, IEnumerable<string>> nonTestableTypes) | |||
{ | |||
var sb = new StringBuilder(); | |||
|
|||
foreach (var kvp in nonTestableTypes) | |||
{ | |||
sb.AppendFormat("'{0}' cannot be easily abstracted in a testing context. Please make sure it either has a public constructor, or an empty protected constructor.{1}", | |||
kvp.Key, Environment.NewLine); | |||
|
|||
foreach (string methodName in kvp.Value) | |||
{ | |||
sb.AppendFormat(" - Method '{0}' must be virtual{1}", methodName, Environment.NewLine); | |||
} | |||
} | |||
|
|||
return sb.ToString(); | |||
} | |||
|
|||
private static IEnumerable<string> GetNonVirtualPublicMethodsNames(Type type) | |||
{ | |||
var publicMethods = type.GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly); | |||
|
|||
return from mi in publicMethods where !mi.IsVirtual && !mi.IsStatic select mi.ToString(); | |||
} | |||
|
|||
private static bool HasEmptyProtectedConstructor(Type type) | |||
{ | |||
ConstructorInfo[] nonPublicConstructors = type.GetConstructors(BindingFlags.NonPublic | BindingFlags.Instance); | |||
|
|||
return nonPublicConstructors.Any(ci => !ci.IsPrivate && !ci.IsAssembly && !ci.IsFinal && !ci.GetParameters().Any()); | |||
} | |||
|
|||
private static bool IsStatic(Type type) | |||
{ | |||
return type.IsAbstract && type.IsSealed; | |||
} | |||
} | |||
} |
Oops, something went wrong.