Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Feb 3, 2023. It is now read-only.

Commit d515546

Browse files
committed
Improve CanRetrieveValidVersionString()
in RepositoryFixture Updated Repository.Version documentation Updated Repository.Version test regex now checks each group. Fixes libgit2#696
1 parent a1b78fa commit d515546

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

LibGit2Sharp.Tests/RepositoryFixture.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Linq;
55
using LibGit2Sharp.Tests.TestHelpers;
66
using Xunit;
7+
using System.Text.RegularExpressions;
78

89
namespace LibGit2Sharp.Tests
910
{
@@ -88,9 +89,35 @@ public void CanCreateStandardRepo()
8889
[Fact]
8990
public void CanRetrieveValidVersionString()
9091
{
92+
// Version string format is:
93+
// Major.Minor.Patch-LibGit2Sharp_abbrev_hash-libgit2_abbrev_hash (x86|amd64 - features)
94+
// Example output:
95+
// "0.17.0-unknown-06d772d (x86 - Threads, Https)"
96+
9197
string versionInfo = Repository.Version;
9298

99+
// The Repository.Version returned string should contain :
100+
// version:'0.17.0' LibGit2Sharp version number.
101+
// git2SharpHash:'unknown' ( when compiled from source ) else LibGit2Sharp library hash.
102+
// git2hash: '06d772d' LibGit2 library hash.
103+
// arch: 'x86' or 'amd64' LibGit2 target.
104+
// git2Features: 'Threads, Ssh' LibGit2 features compiled with.
105+
string regex = @"^(?<version>\d{1,}\.\d{1,2}\.\d{1,3})-(?<git2SharpHash>\w+)-(?<git2Hash>\w+) \((?<arch>\w+) - (?<git2Features>(?:\w*(?:, )*\w+)*)\)$";
106+
93107
Assert.NotNull(versionInfo);
108+
109+
Match regexResult = Regex.Match(versionInfo, regex);
110+
111+
Assert.True(regexResult.Success, "The following version string format is enforced:" +
112+
"Major.Minor.Patch-LibGit2Sharp_abbrev_hash-libgit2_abbrev_hash (x86|amd64 - features)");
113+
114+
GroupCollection matchGroups = regexResult.Groups;
115+
116+
// Check that all groups are valid
117+
foreach(Group group in matchGroups)
118+
{
119+
Assert.True(group.Success);
120+
}
94121
}
95122

96123
[Fact]

LibGit2Sharp/Repository.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1005,7 +1005,7 @@ internal T RegisterForCleanup<T>(T disposable) where T : IDisposable
10051005
/// Gets the current LibGit2Sharp version.
10061006
/// <para>
10071007
/// The format of the version number is as follows:
1008-
/// <para>Major.Minor.Patch-LibGit2Sharp_abbrev_hash-libgit2_abbrev_hash (x86|amd64 - capabilities)</para>
1008+
/// <para>Major.Minor.Patch-LibGit2Sharp_abbrev_hash-libgit2_abbrev_hash (x86|amd64 - features)</para>
10091009
/// </para>
10101010
/// </summary>
10111011
public static string Version

0 commit comments

Comments
 (0)