Skip to content

Commit 7067eb5

Browse files
committed
Update test comments and remove unnecessary check
We have exactly two optional regex matching groups. Regex itself guarantees that the required groups were present, so the last half of this test that confirms that a hard-coded set of these groups were present is not testing libgit2sharp as much as it is testing regex itself, which is difficult to maintain and pointless, so I removed it rather than fixing it when I added the second optional group.
1 parent 5bdd563 commit 7067eb5

File tree

1 file changed

+4
-19
lines changed

1 file changed

+4
-19
lines changed

LibGit2Sharp.Tests/GlobalSettingsFixture.cs

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,41 +19,26 @@ public void CanGetMinimumCompiledInFeatures()
1919
public void CanRetrieveValidVersionString()
2020
{
2121
// Version string format is:
22-
// Major.Minor.Patch[-preDateTime]-LibGit2Sharp_abbrev_hash-libgit2_abbrev_hash (x86|x64 - features)
22+
// Major.Minor.Patch[-somePreleaseTag]-LibGit2Sharp_abbrev_hash-libgit2_abbrev_hash (x86|x64 - features)
2323
// Example output:
2424
// "0.17.0[-pre20170914123547]-deadcafe-06d772d (x86 - Threads, Https)"
2525

2626
string versionInfo = GlobalSettings.Version.ToString();
2727

2828
// The GlobalSettings.Version returned string should contain :
29-
// version: '0.17.0[-pre20170914123547]' LibGit2Sharp version number.
29+
// version: '0.17.0[-somePreleaseTag][+gSomeGitCommit]' LibGit2Sharp version number.
3030
// git2SharpHash:'unknown' ( when compiled from source ) else LibGit2Sharp library hash.
3131
// git2hash: '06d772d' LibGit2 library hash.
3232
// arch: 'x86' or 'x64' LibGit2 target.
3333
// git2Features: 'Threads, Ssh' LibGit2 features compiled with.
34-
string regex = @"^(?<version>\d{1,}\.\d{1,2}\.\d{1,3}(\+g[a-f0-9]{10})?)-(?<git2SharpHash>\w+)-(?<git2Hash>\w+) \((?<arch>\w+) - (?<git2Features>(?:\w*(?:, )*\w+)*)\)$";
34+
string regex = @"^(?<version>\d+\.\d+\.\d+(-\w+)?(\+g[a-f0-9]{10})?)-(?<git2SharpHash>\w+)-(?<git2Hash>\w+) \((?<arch>\w+) - (?<git2Features>(?:\w*(?:, )*\w+)*)\)$";
3535

3636
Assert.NotNull(versionInfo);
3737

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

4040
Assert.True(regexResult.Success, "The following version string format is enforced:" +
41-
"Major.Minor.Patch[-preDateTime]-LibGit2Sharp_abbrev_hash-libgit2_abbrev_hash (x86|x64 - features)");
42-
43-
GroupCollection matchGroups = regexResult.Groups;
44-
45-
Assert.Equal(7, matchGroups.Count);
46-
47-
// Check that all groups are valid
48-
for (int i = 0; i < matchGroups.Count; i++)
49-
{
50-
if (i == 1 || i == 2) // '-pre' segment is optional
51-
{
52-
continue;
53-
}
54-
55-
Assert.True(matchGroups[i].Success);
56-
}
41+
"Major.Minor.Patch[-somePreleaseTag][+gSomeGitCommit]-LibGit2Sharp_abbrev_hash-libgit2_abbrev_hash (x86|x64 - features)");
5742
}
5843

5944
[Fact]

0 commit comments

Comments
 (0)