Skip to content

Improve CanRetrieveValidVersionString() #697

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 28, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions LibGit2Sharp.Tests/RepositoryFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Linq;
using LibGit2Sharp.Tests.TestHelpers;
using Xunit;
using System.Text.RegularExpressions;

namespace LibGit2Sharp.Tests
{
Expand Down Expand Up @@ -88,9 +89,35 @@ public void CanCreateStandardRepo()
[Fact]
public void CanRetrieveValidVersionString()
{
// Version string format is:
// Major.Minor.Patch-LibGit2Sharp_abbrev_hash-libgit2_abbrev_hash (x86|amd64 - features)
// Example output:
// "0.17.0-unknown-06d772d (x86 - Threads, Https)"

string versionInfo = Repository.Version;

// The Repository.Version returned string should contain :
// version:'0.17.0' LibGit2Sharp version number.
// git2SharpHash:'unknown' ( when compiled from source ) else LibGit2Sharp library hash.
// git2hash: '06d772d' LibGit2 library hash.
// arch: 'x86' or 'amd64' LibGit2 target.
// git2Features: 'Threads, Ssh' LibGit2 features compiled with.
string regex = @"^(?<version>\d{1,}\.\d{1,2}\.\d{1,3})-(?<git2SharpHash>\w+)-(?<git2Hash>\w+) \((?<arch>\w+) - (?<git2Features>(?:\w*(?:, )*\w+)*)\)$";

Assert.NotNull(versionInfo);

Match regexResult = Regex.Match(versionInfo, regex);

Assert.True(regexResult.Success, "The following version string format is enforced:" +
"Major.Minor.Patch-LibGit2Sharp_abbrev_hash-libgit2_abbrev_hash (x86|amd64 - features)");

GroupCollection matchGroups = regexResult.Groups;

// Check that all groups are valid
foreach(Group group in matchGroups)
{
Assert.True(group.Success);
}
}

[Fact]
Expand Down
2 changes: 1 addition & 1 deletion LibGit2Sharp/Repository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1005,7 +1005,7 @@ internal T RegisterForCleanup<T>(T disposable) where T : IDisposable
/// Gets the current LibGit2Sharp version.
/// <para>
/// The format of the version number is as follows:
/// <para>Major.Minor.Patch-LibGit2Sharp_abbrev_hash-libgit2_abbrev_hash (x86|amd64 - capabilities)</para>
/// <para>Major.Minor.Patch-LibGit2Sharp_abbrev_hash-libgit2_abbrev_hash (x86|amd64 - features)</para>
/// </para>
/// </summary>
public static string Version
Expand Down