|
4 | 4 | using System.Linq;
|
5 | 5 | using LibGit2Sharp.Tests.TestHelpers;
|
6 | 6 | using Xunit;
|
| 7 | +using System.Text.RegularExpressions; |
7 | 8 |
|
8 | 9 | namespace LibGit2Sharp.Tests
|
9 | 10 | {
|
@@ -88,9 +89,35 @@ public void CanCreateStandardRepo()
|
88 | 89 | [Fact]
|
89 | 90 | public void CanRetrieveValidVersionString()
|
90 | 91 | {
|
| 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 | + |
91 | 97 | string versionInfo = Repository.Version;
|
92 | 98 |
|
| 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 | + |
93 | 107 | 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 | + } |
94 | 121 | }
|
95 | 122 |
|
96 | 123 | [Fact]
|
|
0 commit comments