|
1 |
| -using System.Text.RegularExpressions; |
| 1 | +using System; |
| 2 | +using System.Text.RegularExpressions; |
2 | 3 | using LibGit2Sharp.Tests.TestHelpers;
|
3 | 4 | using Xunit;
|
4 | 5 |
|
@@ -26,26 +27,31 @@ public void CanRetrieveValidVersionString()
|
26 | 27 | string versionInfo = GlobalSettings.Version.ToString();
|
27 | 28 |
|
28 | 29 | // The GlobalSettings.Version returned string should contain :
|
29 |
| - // version:'0.17.0' LibGit2Sharp version number. |
| 30 | + // version: '0.17.0[.198[-pre]]' LibGit2Sharp version number. |
30 | 31 | // git2SharpHash:'unknown' ( when compiled from source ) else LibGit2Sharp library hash.
|
31 | 32 | // git2hash: '06d772d' LibGit2 library hash.
|
32 | 33 | // arch: 'x86' or 'amd64' LibGit2 target.
|
33 | 34 | // git2Features: 'Threads, Ssh' LibGit2 features compiled with.
|
34 |
| - string regex = @"^(?<version>\d{1,}\.\d{1,2}\.\d{1,3})-(?<git2SharpHash>\w+)-(?<git2Hash>\w+) \((?<arch>\w+) - (?<git2Features>(?:\w*(?:, )*\w+)*)\)$"; |
| 35 | + string regex = @"^(?<version>\d{1,}\.\d{1,2}\.\d{1,3}(\.\d{1,5}(-pre)?)?)-(?<git2SharpHash>\w+)-(?<git2Hash>\w+) \((?<arch>\w+) - (?<git2Features>(?:\w*(?:, )*\w+)*)\)$"; |
35 | 36 |
|
36 | 37 | Assert.NotNull(versionInfo);
|
37 | 38 |
|
38 | 39 | Match regexResult = Regex.Match(versionInfo, regex);
|
39 | 40 |
|
40 | 41 | Assert.True(regexResult.Success, "The following version string format is enforced:" +
|
41 |
| - "Major.Minor.Patch-LibGit2Sharp_abbrev_hash-libgit2_abbrev_hash (x86|amd64 - features)"); |
| 42 | + "Major.Minor.Patch[.Build['-pre']]-LibGit2Sharp_abbrev_hash-libgit2_abbrev_hash (x86|amd64 - features)"); |
42 | 43 |
|
43 | 44 | GroupCollection matchGroups = regexResult.Groups;
|
44 | 45 |
|
45 | 46 | // Check that all groups are valid
|
46 |
| - foreach (Group group in matchGroups) |
| 47 | + for (int i = 0; i < matchGroups.Count; i++) |
47 | 48 | {
|
48 |
| - Assert.True(group.Success); |
| 49 | + if (i == 1 || i == 2) // Build number and '-pre' are optional |
| 50 | + { |
| 51 | + continue; |
| 52 | + } |
| 53 | + |
| 54 | + Assert.True(matchGroups[i].Success); |
49 | 55 | }
|
50 | 56 | }
|
51 | 57 | }
|
|
0 commit comments